mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-02 22:36:35 +08:00
运行环境新增了画布相关的属性
This commit is contained in:
@@ -15,17 +15,14 @@
|
||||
<tool:HorizontalCenterThumbPositionConverter x:Key="HorizontalCenterThumbPositionConverter" />
|
||||
</UserControl.Resources>
|
||||
|
||||
|
||||
|
||||
<StackPanel x:Name="FlowChartStackPanel"
|
||||
<DockPanel x:Name="FlowChartStackPanel"
|
||||
ClipToBounds="True">
|
||||
<!-- 虚拟化 VirtualizingStackPanel.IsVirtualizing="True" -->
|
||||
<Canvas
|
||||
<Canvas ClipToBounds="True"
|
||||
x:Name="FlowChartCanvas"
|
||||
Background="#E1FBEA"
|
||||
AllowDrop="True"
|
||||
Width="1920"
|
||||
Height="1080"
|
||||
Width="1000"
|
||||
Height="600"
|
||||
MouseLeftButtonDown ="FlowChartCanvas_MouseLeftButtonDown"
|
||||
MouseLeftButtonUp="FlowChartCanvas_MouseLeftButtonUp"
|
||||
MouseDown="FlowChartCanvas_MouseDown"
|
||||
@@ -116,6 +113,6 @@ Canvas.Top="{Binding ActualHeight, ElementName=FlowChartCanvas, Mode=OneWay, Con
|
||||
</Canvas>
|
||||
|
||||
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
|
||||
</UserControl>
|
||||
|
||||
@@ -71,19 +71,6 @@ namespace Serein.Workbench.Views
|
||||
private Point startSelectControolPoint;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 记录开始连接的文本块
|
||||
/// </summary>
|
||||
//private NodeControlBase? startConnectNodeControl;
|
||||
/// <summary>
|
||||
/// 当前正在绘制的连接线
|
||||
/// </summary>
|
||||
//private Line? currentLine;
|
||||
/// <summary>
|
||||
/// 当前正在绘制的真假分支属性
|
||||
/// </summary>
|
||||
//private ConnectionInvokeType currentConnectionType;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 组合变换容器
|
||||
@@ -103,9 +90,8 @@ namespace Serein.Workbench.Views
|
||||
public FlowCanvasView()
|
||||
{
|
||||
ViewModel = App.GetService<Locator>().FlowCanvasViewModel;
|
||||
|
||||
this.DataContext = ViewModel;
|
||||
EnvDecorator = App.GetService<IFlowEnvironment>();
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
#region 缩放平移容器
|
||||
@@ -185,7 +171,6 @@ namespace Serein.Workbench.Views
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 放置操作,根据拖放数据创建相应的控件,并处理相关操作
|
||||
/// </summary>
|
||||
@@ -201,9 +186,10 @@ namespace Serein.Workbench.Views
|
||||
{
|
||||
if (e.Data.GetData(MouseNodeType.CreateDllNodeInCanvas) is MoveNodeData nodeData)
|
||||
{
|
||||
var canvasGuid = this.ViewModel.CanvasGuid;
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await EnvDecorator.CreateNodeAsync(nodeData.NodeControlType, position, nodeData.MethodDetailsInfo); // 创建DLL文件的节点对象
|
||||
await EnvDecorator.CreateNodeAsync(canvasGuid, nodeData.NodeControlType, position, nodeData.MethodDetailsInfo); // 创建DLL文件的节点对象
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -223,9 +209,10 @@ namespace Serein.Workbench.Views
|
||||
};
|
||||
if (nodeControlType != NodeControlType.None)
|
||||
{
|
||||
var canvasGuid = this.ViewModel.CanvasGuid;
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await EnvDecorator.CreateNodeAsync(nodeControlType, position); // 创建基础节点对象
|
||||
await EnvDecorator.CreateNodeAsync(canvasGuid, nodeControlType, position); // 创建基础节点对象
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -257,11 +244,6 @@ namespace Serein.Workbench.Views
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 在画布中尝试选取控件
|
||||
/// </summary>
|
||||
@@ -340,7 +322,12 @@ namespace Serein.Workbench.Views
|
||||
#region 方法调用关系创建
|
||||
if (myData.Type == JunctionOfConnectionType.Invoke)
|
||||
{
|
||||
await EnvDecorator.ConnectInvokeNodeAsync(myData.StartJunction.MyNode.Guid, myData.CurrentJunction.MyNode.Guid,
|
||||
var canvasGuid = this.ViewModel.CanvasGuid;
|
||||
|
||||
await EnvDecorator.ConnectInvokeNodeAsync(
|
||||
canvasGuid,
|
||||
myData.StartJunction.MyNode.Guid,
|
||||
myData.CurrentJunction.MyNode.Guid,
|
||||
myData.StartJunction.JunctionType,
|
||||
myData.CurrentJunction.JunctionType,
|
||||
myData.ConnectionInvokeType);
|
||||
@@ -359,8 +346,12 @@ namespace Serein.Workbench.Views
|
||||
{
|
||||
argIndex = argJunction2.ArgIndex;
|
||||
}
|
||||
var canvasGuid = this.ViewModel.CanvasGuid;
|
||||
|
||||
await EnvDecorator.ConnectArgSourceNodeAsync(myData.StartJunction.MyNode.Guid, myData.CurrentJunction.MyNode.Guid,
|
||||
await EnvDecorator.ConnectArgSourceNodeAsync(
|
||||
canvasGuid,
|
||||
myData.StartJunction.MyNode.Guid,
|
||||
myData.CurrentJunction.MyNode.Guid,
|
||||
myData.StartJunction.JunctionType,
|
||||
myData.CurrentJunction.JunctionType,
|
||||
myData.ConnectionArgSourceType,
|
||||
@@ -376,9 +367,6 @@ namespace Serein.Workbench.Views
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#region 拖动画布实现缩放平移效果
|
||||
private void FlowChartCanvas_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
@@ -568,7 +556,6 @@ namespace Serein.Workbench.Views
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
/// 完成选取操作
|
||||
/// </summary>
|
||||
private void CompleteSelection()
|
||||
@@ -607,7 +594,9 @@ namespace Serein.Workbench.Views
|
||||
SelectedNode();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 选择控件
|
||||
/// </summary>
|
||||
private void SelectedNode()
|
||||
{
|
||||
|
||||
@@ -657,7 +646,10 @@ namespace Serein.Workbench.Views
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 选择范围配置
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private ContextMenu ConfiguerSelectionRectangle()
|
||||
{
|
||||
var contextMenu = new ContextMenu();
|
||||
@@ -670,7 +662,8 @@ namespace Serein.Workbench.Views
|
||||
var guid = node?.ViewModel?.NodeModel?.Guid;
|
||||
if (!string.IsNullOrEmpty(guid))
|
||||
{
|
||||
EnvDecorator.RemoveNodeAsync(guid);
|
||||
var canvasGuid = this.ViewModel.CanvasGuid;
|
||||
EnvDecorator.RemoveNodeAsync(canvasGuid, guid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,62 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Serein.Workbench.Views"
|
||||
xmlns:vm="clr-namespace:Serein.Workbench.ViewModels"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
Background="#FFD3D3D3">
|
||||
d:DataContext="{d:DesignInstance vm:FlowEditViewModel}"
|
||||
xmlns:converters="clr-namespace:Serein.Workbench.Tool.Converters"
|
||||
Background="#E7F0F6">
|
||||
<UserControl.Resources>
|
||||
<converters:InvertableBooleanToVisibilityConverter x:Key="InvertableBooleanToVisibilityConverter"/>
|
||||
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<local:FlowCanvasView></local:FlowCanvasView>
|
||||
<!-- TabControl -->
|
||||
<!--DragOver="TabControl_DragOver"
|
||||
Drop="TabControl_Drop"
|
||||
AllowDrop="True"-->
|
||||
<TabControl SelectedItem="{Binding SelectedTab}" >
|
||||
<TabControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel>
|
||||
<!-- 双击选项卡名称来进入编辑模式 -->
|
||||
<TextBlock Text="{Binding Name}"
|
||||
FontSize="18"
|
||||
Visibility="{Binding IsEditing, Converter={StaticResource InvertableBooleanToVisibilityConverter},ConverterParameter=Inverted}"
|
||||
PreviewMouseLeftButtonDown="TextBlock_PreviewMouseLeftButtonDown"
|
||||
MouseLeftButtonDown="TextBlock_MouseLeftButtonDown"/>
|
||||
<!-- 编辑模式下显示TextBox -->
|
||||
<TextBox Text="{Binding Name, Mode=TwoWay}"
|
||||
FontSize="18"
|
||||
Visibility="{Binding IsEditing, Converter={StaticResource InvertableBooleanToVisibilityConverter},ConverterParameter=Normal}"
|
||||
KeyDown="TextBox_KeyDown"
|
||||
LostFocus="TextBox_LostFocus"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</TabControl.ItemTemplate>
|
||||
|
||||
<!-- Tabs Collection -->
|
||||
<TabControl.ItemsSource>
|
||||
<Binding Path="Tabs" />
|
||||
</TabControl.ItemsSource>
|
||||
|
||||
<!-- Content of the Tab (e.g., FlowCanvasView) -->
|
||||
<TabControl.ContentTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Background="#FFD3D3D3">
|
||||
<ContentControl Content="{Binding Content}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</TabControl.ContentTemplate>
|
||||
</TabControl>
|
||||
|
||||
<!-- Tab control buttons -->
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Right">
|
||||
<Button Content="添加" Command="{Binding AddTabCommand}" Margin="5" Width="80"/>
|
||||
<Button Content="移除" Command="{Binding RemoveTabCommand}" Margin="5" Width="80"/>
|
||||
<!--<Button Content="Rename Tab" Command="{Binding RenameTabCommand}" />-->
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Serein.Workbench.ViewModels;
|
||||
using Serein.Workbench.Models;
|
||||
using Serein.Workbench.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -8,11 +9,19 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
using DragDropEffects = System.Windows.DragDropEffects;
|
||||
using DragEventArgs = System.Windows.DragEventArgs;
|
||||
using TabControl = System.Windows.Controls.TabControl;
|
||||
using TextBox = System.Windows.Controls.TextBox;
|
||||
using UserControl = System.Windows.Controls.UserControl;
|
||||
|
||||
namespace Serein.Workbench.Views
|
||||
{
|
||||
@@ -24,8 +33,99 @@ namespace Serein.Workbench.Views
|
||||
public FlowEditView()
|
||||
{
|
||||
this.DataContext = App.GetService<Locator>().FlowEditViewModel;
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void TextBlock_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
var textBlock = sender as TextBlock;
|
||||
var tab = textBlock?.DataContext as FlowCanvasModel;
|
||||
if (tab != null)
|
||||
{
|
||||
DragDrop.DoDragDrop(textBlock, tab, DragDropEffects.Move);
|
||||
}
|
||||
}
|
||||
private void TabControl_DragOver(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(FlowCanvasModel)))
|
||||
{
|
||||
e.Effects = DragDropEffects.Move;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effects = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void TabControl_Drop(object sender, DragEventArgs e)
|
||||
{
|
||||
var sourceTab = e.Data.GetData(typeof(FlowCanvasModel)) as FlowCanvasModel;
|
||||
var targetTab = (sender as TabControl)?.SelectedItem as FlowCanvasModel;
|
||||
var viewModel = (FlowEditViewModel)this.DataContext;
|
||||
if (sourceTab != null && targetTab != null && sourceTab != targetTab)
|
||||
{
|
||||
var sourceIndex = viewModel.Tabs.IndexOf(sourceTab);
|
||||
var targetIndex = viewModel.Tabs.IndexOf(targetTab);
|
||||
|
||||
// 删除源项并插入到目标位置
|
||||
viewModel.Tabs.Remove(sourceTab);
|
||||
viewModel.Tabs.Insert(targetIndex, sourceTab);
|
||||
|
||||
// 更新视图模型中的选中的Tab
|
||||
viewModel.SelectedTab = sourceTab;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void TextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
|
||||
{
|
||||
|
||||
if (e.Key == Key.Enter || e.Key == Key.Escape)
|
||||
{
|
||||
var textBox = sender as TextBox;
|
||||
var newName = textBox?.Text;
|
||||
if (string.IsNullOrEmpty(newName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var tab = textBox?.DataContext as FlowCanvasModel;
|
||||
if (tab != null)
|
||||
{
|
||||
var viewModel = (FlowEditViewModel)this.DataContext;
|
||||
viewModel.EndEditingTab(tab, newName); // 确认新名称
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var textBox = sender as TextBox;
|
||||
var newName = textBox?.Text;
|
||||
if (string.IsNullOrEmpty(newName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var tab = textBox?.DataContext as FlowCanvasModel;
|
||||
if (tab != null && tab.IsEditing)
|
||||
{
|
||||
var viewModel = (FlowEditViewModel)this.DataContext;
|
||||
viewModel.EndEditingTab(tab, newName); // 确认新名称
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ClickCount == 2)
|
||||
{
|
||||
var textBlock = sender as TextBlock;
|
||||
var tab = textBlock?.DataContext as FlowCanvasModel;
|
||||
if (tab != null)
|
||||
{
|
||||
var viewModel = (FlowEditViewModel)this.DataContext;
|
||||
viewModel.StartEditingTab(tab);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace Serein.Workbench.Views
|
||||
this.DataContext = App.GetService<Locator>().FlowWorkbenchViewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.MaxHeight = SystemParameters.PrimaryScreenHeight;
|
||||
|
||||
Reference in New Issue
Block a user