mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-11 10:26:34 +08:00
完成mvvm模式下,画布、节点编辑的基本重构
This commit is contained in:
68
Workbench/Api/IFlowCanvas.cs
Normal file
68
Workbench/Api/IFlowCanvas.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using Serein.Library;
|
||||
using Serein.Workbench.Node.View;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Workbench.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// 流程画布
|
||||
/// </summary>
|
||||
public interface IFlowCanvas
|
||||
{
|
||||
/// <summary>
|
||||
/// 画布标识
|
||||
/// </summary>
|
||||
string Guid { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 画布名称
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 移除节点
|
||||
/// </summary>
|
||||
void Remove(NodeControlBase nodeControl);
|
||||
|
||||
/// <summary>
|
||||
/// 添加节点
|
||||
/// </summary>
|
||||
void Add(NodeControlBase nodeControl);
|
||||
|
||||
/// <summary>
|
||||
/// 创建节点之间方法调用关系
|
||||
/// </summary>
|
||||
/// <param name="fromNodeControl">调用顺序中的起始节点</param>
|
||||
/// <param name="toNodeControl">下一节点</param>
|
||||
/// <param name="type">调用类型</param>
|
||||
void CreateInvokeConnection(NodeControlBase fromNodeControl, NodeControlBase toNodeControl, ConnectionInvokeType type);
|
||||
|
||||
/// <summary>
|
||||
/// 移除节点之间的调用关系
|
||||
/// </summary>
|
||||
/// <param name="fromNodeControl">调用顺序中的起始节点</param>
|
||||
/// <param name="toNodeControl">下一节点</param>
|
||||
void RemoveInvokeConnection(NodeControlBase fromNodeControl, NodeControlBase toNodeControl);
|
||||
|
||||
/// <summary>
|
||||
/// 创建节点之间的参数传递关系
|
||||
/// </summary>
|
||||
/// <param name="fromNodeControl">参数来源节点</param>
|
||||
/// <param name="toNodeControl">获取参数的节点</param>
|
||||
/// <param name="type">指示参数是如何获取的</param>
|
||||
/// <param name="index">作用在节点的第几个入参</param>
|
||||
void CreateArgConnection(NodeControlBase fromNodeControl, NodeControlBase toNodeControl, ConnectionArgSourceType type, int index);
|
||||
|
||||
/// <summary>
|
||||
/// 移除节点之间的参数传递关系
|
||||
/// </summary>
|
||||
/// <param name="fromNodeControl">参数来源节点</param>
|
||||
/// <param name="toNodeControl">获取参数的节点</param>
|
||||
/// <param name="index">移除节点第几个入参</param>
|
||||
void RemoveArgConnection(NodeControlBase fromNodeControl, NodeControlBase toNodeControl, int index);
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ namespace Serein.Workbench
|
||||
collection.AddSingleton<FlowLibrarysViewModel>();
|
||||
collection.AddSingleton<FlowEditViewModel>();
|
||||
|
||||
collection.AddTransient<FlowCanvasViewModel>(); // 依赖信息
|
||||
collection.AddTransient<FlowCanvasViewModel>(); // 画布
|
||||
}
|
||||
|
||||
public static void AddWorkbenchServices(this IServiceCollection collection)
|
||||
@@ -40,8 +40,8 @@ namespace Serein.Workbench
|
||||
collection.AddSingleton<IFlowEEForwardingService, FlowEEForwardingService>(); // 流程事件管理
|
||||
collection.AddSingleton<IWorkbenchEventService, WorkbenchEventService>(); // 流程事件管理
|
||||
collection.AddSingleton<FlowNodeService>(); // 节点操作管理
|
||||
// collection.AddSingleton<IKeyEventService, KeyEventService>(); // 按键事件管理
|
||||
//collection.AddSingleton<FlowNodeControlService>(); // 流程节点控件管理
|
||||
// collection.AddSingleton<IKeyEventService, KeyEventService>(); // 按键事件管理
|
||||
//collection.AddSingleton<FlowNodeControlService>(); // 流程节点控件管理
|
||||
}
|
||||
|
||||
|
||||
@@ -97,21 +97,17 @@ namespace Serein.Workbench
|
||||
collection.AddViewModelServices();
|
||||
var services = collection.BuildServiceProvider(); // 绑定并返回获取实例的服务接口
|
||||
App.ServiceProvider = services;
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(500);
|
||||
await this.LoadLocalProjectAsync();
|
||||
App.GetService<IFlowEnvironment>().LoadProject(new FlowEnvInfo { Project = App.FlowProjectData }, App.FileDataPath);
|
||||
|
||||
});
|
||||
#if DEBUG
|
||||
_ = this.LoadLocalProjectAsync();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
private async Task LoadLocalProjectAsync()
|
||||
{
|
||||
|
||||
await Task.Delay(500);
|
||||
#if DEBUG
|
||||
if (1 == 1)
|
||||
if (1 == 10)
|
||||
{
|
||||
// 这里是测试代码,可以删除
|
||||
string filePath;
|
||||
@@ -124,7 +120,7 @@ namespace Serein.Workbench
|
||||
App.FlowProjectData = JsonConvert.DeserializeObject<SereinProjectData>(content);
|
||||
App.FileDataPath = System.IO.Path.GetDirectoryName(filePath)!; // filePath;//
|
||||
var dir = Path.GetDirectoryName(filePath);
|
||||
|
||||
App.GetService<IFlowEnvironment>().LoadProject(new FlowEnvInfo { Project = App.FlowProjectData }, App.FileDataPath);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using Serein.Library.Utils;
|
||||
using Serein.NodeFlow;
|
||||
using Serein.NodeFlow.Env;
|
||||
using Serein.NodeFlow.Tool;
|
||||
using Serein.Workbench.Api;
|
||||
using Serein.Workbench.Extension;
|
||||
using Serein.Workbench.Node;
|
||||
using Serein.Workbench.Node.View;
|
||||
@@ -292,14 +293,14 @@ namespace Serein.Workbench
|
||||
{
|
||||
return;
|
||||
}
|
||||
InitializeCanvas(project.Basic.Canvas.Width, project.Basic.Canvas.Height);// 设置画布大小
|
||||
//InitializeCanvas(project.Basic.Canvas.Width, project.Basic.Canvas.Height);// 设置画布大小
|
||||
//foreach (var connection in Connections)
|
||||
//{
|
||||
// connection.RefreshLine(); // 窗体完成加载后试图刷新所有连接线
|
||||
//}
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"运行环境当前工作目录:{System.IO.Directory.GetCurrentDirectory()}");
|
||||
|
||||
var canvasData = project.Basic.Canvas;
|
||||
/*var canvasData = project.Basic.Canvas;
|
||||
if (canvasData is not null)
|
||||
{
|
||||
scaleTransform.ScaleX = 1;
|
||||
@@ -312,7 +313,7 @@ namespace Serein.Workbench
|
||||
translateTransform.Y += canvasData.ViewY;
|
||||
// 应用变换组
|
||||
FlowChartCanvas.RenderTransform = canvasTransformGroup;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
@@ -356,15 +357,15 @@ namespace Serein.Workbench
|
||||
|
||||
projectData.Basic = new Basic
|
||||
{
|
||||
Canvas = new FlowCanvasInfo
|
||||
{
|
||||
Height = FlowChartCanvas.Height,
|
||||
Width = FlowChartCanvas.Width,
|
||||
ViewX = translateTransform.X,
|
||||
ViewY = translateTransform.Y,
|
||||
ScaleX = scaleTransform.ScaleX,
|
||||
ScaleY = scaleTransform.ScaleY,
|
||||
},
|
||||
//Canvas = new FlowCanvasInfo
|
||||
//{
|
||||
// Height = FlowChartCanvas.Height,
|
||||
// Width = FlowChartCanvas.Width,
|
||||
// ViewX = translateTransform.X,
|
||||
// ViewY = translateTransform.Y,
|
||||
// ScaleX = scaleTransform.ScaleX,
|
||||
// ScaleY = scaleTransform.ScaleY,
|
||||
//},
|
||||
Versions = "1",
|
||||
};
|
||||
|
||||
@@ -527,7 +528,7 @@ namespace Serein.Workbench
|
||||
/// 节点连接关系变更
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
private void FlowEnvironment_NodeConnectChangeEvemt(NodeConnectChangeEventArgs eventArgs)
|
||||
private void FlowEnvironment_NodeConnectChangeEvemt(NodeConnectChangeEventArgs eventArgs)
|
||||
{
|
||||
string fromNodeGuid = eventArgs.FromNodeGuid;
|
||||
string toNodeGuid = eventArgs.ToNodeGuid;
|
||||
@@ -2444,7 +2445,7 @@ namespace Serein.Workbench
|
||||
var controlObj = Activator.CreateInstance(controlType, [viewModel]);
|
||||
if (controlObj is NodeControlBase nodeControl)
|
||||
{
|
||||
nodeControl.NodeCanvas = nodeCanvas;
|
||||
nodeControl.FlowCanvas = (Api.IFlowCanvas)nodeCanvas;
|
||||
return nodeControl;
|
||||
}
|
||||
else
|
||||
@@ -2731,6 +2732,7 @@ public class FlowLibrary
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 顶部菜单栏 - 远程管理
|
||||
private async void ButtonStartRemoteServer_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -13,35 +14,50 @@ using System.Xml.Linq;
|
||||
|
||||
namespace Serein.Workbench.Models
|
||||
{
|
||||
public partial class FlowCanvasModel : ObservableObject
|
||||
public partial class FlowEditorTabModel : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// tab 名称
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
var vm = (FlowCanvasViewModel)content.DataContext;
|
||||
return vm.Name;
|
||||
var vm = (FlowCanvasViewModel)Content.DataContext;
|
||||
return vm.Model.Name ?? "null";
|
||||
}
|
||||
set
|
||||
{
|
||||
var vm = (FlowCanvasViewModel)content.DataContext;
|
||||
vm.Name = value;
|
||||
var vm = (FlowCanvasViewModel)Content.DataContext;
|
||||
vm.Model.Name = value;
|
||||
OnPropertyChanged(nameof(Name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 正在选中
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _isSelected;
|
||||
|
||||
/// <summary>
|
||||
/// 正在编辑标题
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _isEditing;
|
||||
|
||||
/// <summary>
|
||||
/// tab对应的控件
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private FlowCanvasView content;
|
||||
|
||||
|
||||
public FlowCanvasModel()
|
||||
public FlowEditorTabModel(FlowCanvasView content)
|
||||
{
|
||||
|
||||
this.Content = content;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Workbench.Api;
|
||||
using Serein.Workbench.Node.ViewModel;
|
||||
using Serein.Workbench.Views;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
@@ -18,13 +20,14 @@ namespace Serein.Workbench.Node.View
|
||||
/// <summary>
|
||||
/// 节点所在的画布(以后需要将画布封装出来,实现多画布的功能)
|
||||
/// </summary>
|
||||
public Canvas NodeCanvas { get; set; }
|
||||
|
||||
private INodeContainerControl nodeContainerControl;
|
||||
public IFlowCanvas FlowCanvas { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 如果该节点放置在了某个容器节点,就会记录这个容器节点
|
||||
/// </summary>
|
||||
private INodeContainerControl NodeContainerControl { get; }
|
||||
|
||||
private INodeContainerControl nodeContainerControl;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 记录与该节点控件有关的所有连接
|
||||
@@ -53,11 +56,11 @@ namespace Serein.Workbench.Node.View
|
||||
public void PlaceToContainer(INodeContainerControl nodeContainerControl)
|
||||
{
|
||||
this.nodeContainerControl = nodeContainerControl;
|
||||
NodeCanvas.Children.Remove(this); // 临时从画布上移除
|
||||
FlowCanvas.Remove(this); // 临时从画布上移除
|
||||
var result = nodeContainerControl.PlaceNode(this);
|
||||
if (!result) // 检查是否放置成功,如果不成功,需要重新添加回来
|
||||
{
|
||||
NodeCanvas.Children.Add(this); // 从画布上移除
|
||||
FlowCanvas.Add(this); // 从画布上移除
|
||||
|
||||
}
|
||||
}
|
||||
@@ -70,7 +73,7 @@ namespace Serein.Workbench.Node.View
|
||||
var result = nodeContainerControl.TakeOutNode(this); // 从控件取出
|
||||
if (result) // 移除成功时才添加到画布上
|
||||
{
|
||||
NodeCanvas.Children.Add(this); // 重新添加到画布上
|
||||
FlowCanvas.Add(this); // 重新添加到画布上
|
||||
if (nodeContainerControl is NodeControlBase containerControl)
|
||||
{
|
||||
this.ViewModel.NodeModel.Position.X = containerControl.ViewModel.NodeModel.Position.X + containerControl.Width + 10;
|
||||
@@ -128,20 +131,12 @@ namespace Serein.Workbench.Node.View
|
||||
/// </summary>
|
||||
public void SetBinding()
|
||||
{
|
||||
// 绑定 Canvas.Left
|
||||
Binding leftBinding = new Binding("X")
|
||||
{
|
||||
Source = ViewModel.NodeModel.Position, // 如果 X 属性在当前 DataContext 中
|
||||
Mode = BindingMode.TwoWay
|
||||
};
|
||||
var p = ViewModel.NodeModel.Position;
|
||||
|
||||
Binding leftBinding = new(nameof(p.X)) { Source = p, Mode = BindingMode.TwoWay };
|
||||
BindingOperations.SetBinding(this, Canvas.LeftProperty, leftBinding);
|
||||
|
||||
// 绑定 Canvas.Top
|
||||
Binding topBinding = new Binding("Y")
|
||||
{
|
||||
Source = ViewModel.NodeModel.Position, // 如果 Y 属性在当前 DataContext 中
|
||||
Mode = BindingMode.TwoWay
|
||||
};
|
||||
Binding topBinding = new(nameof(p.Y)) { Source = p, Mode = BindingMode.TwoWay };
|
||||
BindingOperations.SetBinding(this, Canvas.TopProperty, topBinding);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Serein.NodeFlow.Model;
|
||||
using Serein.Workbench.Api;
|
||||
using Serein.Workbench.Node.ViewModel;
|
||||
|
||||
namespace Serein.Workbench.Node.View
|
||||
|
||||
@@ -25,9 +25,11 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Node\FlipflopRegionControl.xaml.cs" />
|
||||
<Compile Remove="Node\INodeContainerControl.cs" />
|
||||
<Compile Remove="Node\Junction\NodeJunctionViewBase.cs" />
|
||||
<Compile Remove="Node\NodeBase.cs" />
|
||||
<Compile Remove="Node\View\ActionRegionControl.xaml.cs" />
|
||||
<Compile Remove="Services\NodeControlService.cs" />
|
||||
<Compile Remove="Themes\ConditionControl.xaml.cs" />
|
||||
<Compile Remove="Themes\ConditionControlModel.cs" />
|
||||
<Compile Remove="Themes\ConnectionControl.xaml.cs" />
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Serein.Workbench.Services
|
||||
/// 转发流程运行环境各个事件的实现类
|
||||
/// </summary>
|
||||
/// <param name="flowEnvironment"></param>
|
||||
/// <param name="flowNodeControlService"></param>
|
||||
/// <param name="flowEnvironmentEvent"></param>
|
||||
public FlowEEForwardingService(IFlowEnvironment flowEnvironment,
|
||||
IFlowEnvironmentEvent flowEnvironmentEvent)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Workbench.Api;
|
||||
using Serein.Workbench.Node;
|
||||
using Serein.Workbench.Node.View;
|
||||
using Serein.Workbench.Node.ViewModel;
|
||||
using Serein.Workbench.ViewModels;
|
||||
using Serein.Workbench.Views;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Serein.Workbench.Services
|
||||
{
|
||||
@@ -12,9 +15,23 @@ namespace Serein.Workbench.Services
|
||||
/// </summary>
|
||||
public class FlowNodeService
|
||||
{
|
||||
|
||||
|
||||
#region 流程节点操作的相关事件
|
||||
public Action<FlowCanvasView> OnCreateFlowCanvasView { get; set; }
|
||||
public Action<string> OnRemoveFlowCanvasView { get; set; }
|
||||
/// <summary>
|
||||
/// 添加了画布
|
||||
/// </summary>
|
||||
public Action<FlowCanvasView> OnCreateFlowCanvasView { get; set; }
|
||||
/// <summary>
|
||||
/// 移除了画布
|
||||
/// </summary>
|
||||
public Action<FlowCanvasView> OnRemoveFlowCanvasView { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 添加了节点
|
||||
/// </summary>
|
||||
public Action<NodeControlBase> OnCreateNode { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -32,7 +49,7 @@ namespace Serein.Workbench.Services
|
||||
/// <summary>
|
||||
/// 当前需要创建的节点类型
|
||||
/// </summary>
|
||||
public NodeControlType? CurrentNodeControlType { get; set; }
|
||||
public NodeControlType CurrentNodeControlType { get; set; } = NodeControlType.None;
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -55,23 +72,27 @@ namespace Serein.Workbench.Services
|
||||
/// </summary>
|
||||
public NodeControlBase? ConnectionEndNode { get; set; }
|
||||
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// 记录流程画布
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, FlowCanvasView> FlowCanvasViews = [];
|
||||
private readonly Dictionary<string, FlowCanvasView> Canvass = [];
|
||||
|
||||
/// <summary>
|
||||
/// 记录加载的节点
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, NodeControlViewModelBase> NodeControls = [];
|
||||
private readonly Dictionary<string, NodeControlBase> NodeControls = [];
|
||||
|
||||
/// <summary>
|
||||
/// 运行环境接口
|
||||
/// </summary>
|
||||
private readonly IFlowEnvironment flowEnvironment;
|
||||
|
||||
/// <summary>
|
||||
/// 运行环境事件转发器
|
||||
/// </summary>
|
||||
private readonly IFlowEEForwardingService flowEEForwardingService;
|
||||
|
||||
|
||||
#region 初始化
|
||||
public FlowNodeService(IFlowEnvironment flowEnvironment,
|
||||
IFlowEEForwardingService flowEEForwardingService)
|
||||
@@ -79,44 +100,292 @@ namespace Serein.Workbench.Services
|
||||
this.flowEnvironment = flowEnvironment;
|
||||
this.flowEEForwardingService = flowEEForwardingService;
|
||||
InitFlowEvent();
|
||||
InitNodeType();
|
||||
}
|
||||
|
||||
public void InitFlowEvent()
|
||||
|
||||
/// <summary>
|
||||
/// 注册节点类型
|
||||
/// </summary>
|
||||
private void InitNodeType()
|
||||
{
|
||||
flowEEForwardingService.OnCanvasCreate += FlowEEForwardingService_OnCanvasCreate;
|
||||
flowEEForwardingService.OnCanvasRemove += FlowEEForwardingService_OnCanvasRemove;
|
||||
flowEEForwardingService.OnNodeCreate += FlowEEForwardingService_OnNodeCreate;
|
||||
flowEEForwardingService.OnNodeRemove += FlowEEForwardingService_OnNodeRemove;
|
||||
flowEnvironment.NodeMVVMManagement.RegisterUI(NodeControlType.UI, typeof(UINodeControl), typeof(UINodeControlViewModel));
|
||||
flowEnvironment.NodeMVVMManagement.RegisterUI(NodeControlType.Action, typeof(ActionNodeControl), typeof(ActionNodeControlViewModel));
|
||||
flowEnvironment.NodeMVVMManagement.RegisterUI(NodeControlType.Flipflop, typeof(FlipflopNodeControl), typeof(FlipflopNodeControlViewModel));
|
||||
flowEnvironment.NodeMVVMManagement.RegisterUI(NodeControlType.ExpOp, typeof(ExpOpNodeControl), typeof(ExpOpNodeControlViewModel));
|
||||
flowEnvironment.NodeMVVMManagement.RegisterUI(NodeControlType.ExpCondition, typeof(ConditionNodeControl), typeof(ConditionNodeControlViewModel));
|
||||
flowEnvironment.NodeMVVMManagement.RegisterUI(NodeControlType.ConditionRegion, typeof(ConditionRegionControl), typeof(ConditionRegionNodeControlViewModel));
|
||||
flowEnvironment.NodeMVVMManagement.RegisterUI(NodeControlType.GlobalData, typeof(GlobalDataControl), typeof(GlobalDataNodeControlViewModel));
|
||||
flowEnvironment.NodeMVVMManagement.RegisterUI(NodeControlType.Script, typeof(ScriptNodeControl), typeof(ScriptNodeControlViewModel));
|
||||
flowEnvironment.NodeMVVMManagement.RegisterUI(NodeControlType.NetScript, typeof(NetScriptNodeControl), typeof(NetScriptNodeControlViewModel));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册节点事件
|
||||
/// </summary>
|
||||
private void InitFlowEvent()
|
||||
{
|
||||
flowEEForwardingService.OnCanvasCreate += FlowEEForwardingService_OnCanvasCreate; // 创建了画布
|
||||
flowEEForwardingService.OnCanvasRemove += FlowEEForwardingService_OnCanvasRemove; // 移除了画布
|
||||
flowEEForwardingService.OnNodeCreate += FlowEEForwardingService_OnNodeCreate; // 创建了节点
|
||||
flowEEForwardingService.OnNodeRemove += FlowEEForwardingService_OnNodeRemove; // 移除了节点
|
||||
|
||||
flowEEForwardingService.OnNodePlace += FlowEEForwardingService_OnNodePlace; // 节点放置在容器中
|
||||
flowEEForwardingService.OnNodeTakeOut += FlowEEForwardingService_OnNodeTakeOut; ; // 节点从容器中取出
|
||||
|
||||
flowEEForwardingService.OnNodeConnectChange += FlowEEForwardingService_OnNodeConnectChange; // 节点连接状态改变事件
|
||||
|
||||
}
|
||||
|
||||
private void FlowEEForwardingService_OnNodeConnectChange(NodeConnectChangeEventArgs e)
|
||||
{
|
||||
var canvasGuid = e.CanvasGuid;
|
||||
string fromNodeGuid = e.FromNodeGuid;
|
||||
string toNodeGuid = e.ToNodeGuid;
|
||||
if (!TryGetCanvas(canvasGuid, out var flowCanvas)
|
||||
|| flowCanvas is not IFlowCanvas flow
|
||||
|| !TryGetControl(fromNodeGuid, out var fromNode)
|
||||
|| !TryGetControl(toNodeGuid, out var toNode))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Action? action = (e.JunctionOfConnectionType, e.ChangeType) switch
|
||||
{
|
||||
(JunctionOfConnectionType.Invoke, NodeConnectChangeEventArgs.ConnectChangeType.Create) => () => flow.CreateInvokeConnection(fromNode, toNode, e.ConnectionInvokeType), // 创建节点之间的调用关系
|
||||
(JunctionOfConnectionType.Invoke, NodeConnectChangeEventArgs.ConnectChangeType.Remove) => () => flow.RemoveInvokeConnection(fromNode, toNode), // 移除节点之间的调用关系
|
||||
(JunctionOfConnectionType.Arg, NodeConnectChangeEventArgs.ConnectChangeType.Create) => () => flow.CreateArgConnection(fromNode, toNode, e.ConnectionArgSourceType, e.ArgIndex), // 创建节点之间的参数传递关系
|
||||
(JunctionOfConnectionType.Arg, NodeConnectChangeEventArgs.ConnectChangeType.Remove) => () => flow.RemoveArgConnection(fromNode, toNode, e.ArgIndex), // 移除节点之间的参数传递关系
|
||||
_ => null
|
||||
};
|
||||
action?.Invoke();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
private void FlowEEForwardingService_OnNodeTakeOut(NodeTakeOutEventArgs eventArgs)
|
||||
{
|
||||
string nodeGuid = eventArgs.NodeGuid;
|
||||
if (!TryGetControl(nodeGuid, out var nodeControl))
|
||||
{
|
||||
return;
|
||||
}
|
||||
nodeControl.TakeOutContainer(); // 从容器节点中取出
|
||||
}
|
||||
|
||||
private void FlowEEForwardingService_OnNodePlace(NodePlaceEventArgs eventArgs)
|
||||
{
|
||||
string nodeGuid = eventArgs.NodeGuid;
|
||||
string containerNodeGuid = eventArgs.ContainerNodeGuid;
|
||||
if (!TryGetControl(nodeGuid, out var nodeControl)
|
||||
|| !TryGetControl(containerNodeGuid, out var containerNodeControl))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (containerNodeControl is not INodeContainerControl containerControl)
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.WARN,
|
||||
$"节点[{nodeGuid}]无法放置于节点[{containerNodeGuid}]," +
|
||||
$"因为后者并不实现 INodeContainerControl 接口");
|
||||
return;
|
||||
}
|
||||
nodeControl.PlaceToContainer(containerControl); // 放置在容器节点中
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 节点、画布相关的事件
|
||||
|
||||
/// <summary>
|
||||
/// 节点移除
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
private void FlowEEForwardingService_OnNodeRemove(NodeRemoveEventArgs eventArgs)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (!TryGetCanvas(eventArgs.CanvasGuid, out var nodeCanvas) || nodeCanvas is not IFlowCanvas api)
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"无法移除节点,画布不存在。");
|
||||
return;
|
||||
}
|
||||
if (!TryGetControl(eventArgs.NodeGuid, out var nodeControl))
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"无法移除节点,节点不存在。");
|
||||
return;
|
||||
}
|
||||
api.Remove(nodeControl);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 节点创建
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
|
||||
private void FlowEEForwardingService_OnNodeCreate(NodeCreateEventArgs eventArgs)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
#region 校验事件传入值
|
||||
var position = eventArgs.Position;
|
||||
var cavnasGuid = eventArgs.CanvasGuid;
|
||||
var nodeModel = eventArgs.NodeModel;
|
||||
if (NodeControls.ContainsKey(nodeModel.Guid))
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.WARN, $"创建节点时发生意外:节点Guid重复 - {nodeModel.Guid}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!flowEnvironment.NodeMVVMManagement.TryGetType(nodeModel.ControlType, out var nodeMVVM))
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"无法创建{nodeModel.ControlType}节点,节点类型尚未注册。");
|
||||
return;
|
||||
}
|
||||
if (nodeMVVM.ControlType == null|| nodeMVVM.ViewModelType == null)
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"无法创建{nodeModel.ControlType}节点,UI类型尚未注册(请通过 NodeMVVMManagement.RegisterUI() 方法进行注册)。");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryGetCanvas(cavnasGuid, out var nodeCanvas))
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"无法创建{nodeModel.ControlType}节点,不存在画布【{cavnasGuid}】。");
|
||||
return;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 创建控件
|
||||
|
||||
NodeControlBase nodeControl;
|
||||
try
|
||||
{
|
||||
nodeControl = CreateNodeControl(nodeMVVM.ControlType, // 控件UI类型
|
||||
nodeMVVM.ViewModelType, // 控件VIewModel类型
|
||||
nodeModel, // 控件数据实体
|
||||
nodeCanvas); // 所在画布
|
||||
OnCreateNode.Invoke(nodeControl); // 创建节点
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SereinEnv.WriteLine(ex);
|
||||
return;
|
||||
}
|
||||
|
||||
NodeControls.TryAdd(nodeControl.ViewModel.NodeModel.Guid, nodeControl); // 记录创建了的节点控件
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 画布移除
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
private void FlowEEForwardingService_OnCanvasRemove(CanvasRemoveEventArgs eventArgs)
|
||||
{
|
||||
OnRemoveFlowCanvasView.Invoke(eventArgs.CanvasGuid);
|
||||
if (!TryGetCanvas(eventArgs.CanvasGuid, out var nodeCanvas))
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"无法移除画布,画布不存在。");
|
||||
return;
|
||||
}
|
||||
OnRemoveFlowCanvasView.Invoke(nodeCanvas);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 画布创建
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
private void FlowEEForwardingService_OnCanvasCreate(CanvasCreateEventArgs eventArgs)
|
||||
{
|
||||
var info = eventArgs.Model;
|
||||
var model = eventArgs.Model;
|
||||
FlowCanvasView canvasView = new FlowCanvasView();
|
||||
canvasView.ViewModel.CanvasGuid = info.Guid;
|
||||
canvasView.ViewModel.Model = model;
|
||||
FlowCanvasViews.Add(info.Guid, canvasView);
|
||||
var guid = model.Guid;
|
||||
if (Canvass.ContainsKey(guid))
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.WARN, $"创建画布时发生意外:节点Guid重复 - {guid}");
|
||||
return;
|
||||
}
|
||||
|
||||
FlowCanvasView canvasView = new FlowCanvasView(model);
|
||||
//canvasView.ViewModel.Model = model;
|
||||
//canvasView.ViewModel.CanvasGuid = model.Guid;
|
||||
//canvasView.ViewModel.Name = model.Name;
|
||||
//canvasView.SetBinding(model);
|
||||
Canvass.Add(model.Guid, canvasView);
|
||||
OnCreateFlowCanvasView.Invoke(canvasView); // 传递给订阅者
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 创建节点控件
|
||||
/// </summary>
|
||||
/// <param name="controlType">节点控件视图控件类型</param>
|
||||
/// <param name="viewModelType">节点控件ViewModel类型</param>
|
||||
/// <param name="model">节点Model实例</param>
|
||||
/// <param name="nodeCanvas">节点所在画布</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception">无法创建节点控件</exception>
|
||||
private static NodeControlBase CreateNodeControl(Type controlType, Type viewModelType, NodeModelBase model, IFlowCanvas nodeCanvas)
|
||||
{
|
||||
if ((controlType is null)
|
||||
|| viewModelType is null
|
||||
|| model is null)
|
||||
{
|
||||
throw new Exception("无法创建节点控件");
|
||||
}
|
||||
if (typeof(NodeControlBase).IsSubclassOf(controlType) || typeof(NodeControlViewModelBase).IsSubclassOf(viewModelType))
|
||||
{
|
||||
throw new Exception("无法创建节点控件");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.Guid))
|
||||
{
|
||||
model.Guid = Guid.NewGuid().ToString();
|
||||
}
|
||||
|
||||
var viewModel = Activator.CreateInstance(viewModelType, [model]);
|
||||
var controlObj = Activator.CreateInstance(controlType, [viewModel]);
|
||||
if (controlObj is NodeControlBase nodeControl)
|
||||
{
|
||||
nodeControl.FlowCanvas = nodeCanvas;
|
||||
return nodeControl;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("无法创建节点控件");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从Guid获取节点控件
|
||||
/// </summary>
|
||||
/// <param name="nodeGuid"></param>
|
||||
/// <param name="nodeControl"></param>
|
||||
/// <returns></returns>
|
||||
private bool TryGetControl(string nodeGuid, out NodeControlBase nodeControl)
|
||||
{
|
||||
nodeControl = null;
|
||||
if (string.IsNullOrEmpty(nodeGuid))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return NodeControls.TryGetValue(nodeGuid, out nodeControl);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 从Guid获取画布视图
|
||||
/// </summary>
|
||||
/// <param name="nodeGuid"></param>
|
||||
/// <param name="nodeControl"></param>
|
||||
/// <returns></returns>
|
||||
private bool TryGetCanvas(string nodeGuid, out FlowCanvasView flowCanvas)
|
||||
{
|
||||
flowCanvas = null;
|
||||
if (string.IsNullOrEmpty(nodeGuid))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Canvass.TryGetValue(nodeGuid, out flowCanvas);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -128,8 +397,8 @@ namespace Serein.Workbench.Services
|
||||
/// <returns></returns>
|
||||
public void CreateFlowCanvas()
|
||||
{
|
||||
int height = 1000;
|
||||
int width = 600;
|
||||
int width = 1200;
|
||||
int height = 780;
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
var result = await flowEnvironment.CreateCanvasAsync("", width, height);
|
||||
@@ -146,7 +415,8 @@ namespace Serein.Workbench.Services
|
||||
{
|
||||
return;
|
||||
}
|
||||
_ = flowEnvironment.RemoveCanvasAsync(CurrentSelectCanvas.ViewModel.CanvasGuid);
|
||||
var model = ((FlowCanvasViewModel)CurrentSelectCanvas.DataContext).Model;
|
||||
_ = flowEnvironment.RemoveCanvasAsync(model.Guid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -154,32 +424,31 @@ namespace Serein.Workbench.Services
|
||||
/// </summary>
|
||||
public void CreateNode()
|
||||
{
|
||||
string canvasGuid = CurrentSelectCanvas.ViewModel.CanvasGuid;
|
||||
NodeControlType? nodeType = CurrentNodeControlType;
|
||||
var model = ((FlowCanvasViewModel)CurrentSelectCanvas.DataContext).Model;
|
||||
|
||||
string canvasGuid = model.Guid;
|
||||
NodeControlType nodeType = CurrentNodeControlType;
|
||||
PositionOfUI? position = CurrentMouseLocation;
|
||||
MethodDetailsInfo? methodDetailsInfo = CurrentDragMdInfo;
|
||||
if (nodeType is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (position is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_ = flowEnvironment.CreateNodeAsync(canvasGuid, (NodeControlType)nodeType, position, methodDetailsInfo);
|
||||
_ = flowEnvironment.CreateNodeAsync(canvasGuid, nodeType, position, methodDetailsInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向运行环境发出请求:移除节点
|
||||
/// </summary>
|
||||
public void RemoteNode()
|
||||
public void RemoteNode(NodeControlBase nodeControl)
|
||||
{
|
||||
NodeControlBase? node = CurrentSelectNodeControl;
|
||||
if (node is null)
|
||||
//NodeControlBase? node = CurrentSelectNodeControl;
|
||||
if (nodeControl is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var model = node.ViewModel.NodeModel;
|
||||
var model = nodeControl.ViewModel.NodeModel;
|
||||
if (model is null)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/*
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Serein.Workbench.Services
|
||||
{
|
||||
@@ -38,7 +39,6 @@ namespace Serein.Workbench.Services
|
||||
/// </summary>
|
||||
internal class KeyEventService : IKeyEventService
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 按键按下
|
||||
/// </summary>
|
||||
@@ -77,4 +77,3 @@ namespace Serein.Workbench.Services
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -18,14 +18,6 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace Serein.Workbench.Api
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
namespace Serein.Workbench.Services
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
using Serein.Library;
|
||||
using Microsoft.Win32;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Workbench.Api;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
@@ -50,25 +54,32 @@ namespace Serein.Workbench.Services
|
||||
{
|
||||
|
||||
private readonly IFlowEnvironment flowEnvironment;
|
||||
private readonly IFlowEEForwardingService flowEEForwardingService;
|
||||
|
||||
/// <summary>
|
||||
/// 管理工作台的事件
|
||||
/// </summary>
|
||||
/// <param name="flowEnvironment"></param>
|
||||
public WorkbenchEventService(IFlowEnvironment flowEnvironment)
|
||||
/// <param name="flowEEForwardingService"></param>
|
||||
public WorkbenchEventService(IFlowEnvironment flowEnvironment, IFlowEEForwardingService flowEEForwardingService)
|
||||
{
|
||||
this.flowEnvironment = flowEnvironment;
|
||||
|
||||
this.flowEEForwardingService = flowEEForwardingService;
|
||||
InitEvents();
|
||||
}
|
||||
|
||||
private void SubscribeEvents()
|
||||
private void InitEvents()
|
||||
{
|
||||
|
||||
flowEEForwardingService.OnProjectSaving += SaveProjectToLocalFile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 预览了某个方法信息(待创建)
|
||||
/// </summary>
|
||||
public event PreviewlMethodInfoHandler? OnPreviewlMethodInfo;
|
||||
|
||||
/// <summary>
|
||||
/// 预览依赖方法信息
|
||||
/// </summary>
|
||||
@@ -84,6 +95,96 @@ namespace Serein.Workbench.Services
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存项目数据到本地文件
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
private void SaveProjectToLocalFile(ProjectSavingEventArgs e)
|
||||
{
|
||||
var project = e.ProjectData;
|
||||
// 创建一个新的保存文件对话框
|
||||
SaveFileDialog saveFileDialog = new()
|
||||
{
|
||||
Filter = "DynamicNodeFlow Files (*.dnf)|*.dnf",
|
||||
DefaultExt = "dnf",
|
||||
FileName = "project.dnf"
|
||||
// FileName = System.IO.Path.GetFileName(App.FileDataPath)
|
||||
};
|
||||
|
||||
// 显示保存文件对话框
|
||||
bool? result = saveFileDialog.ShowDialog();
|
||||
// 如果用户选择了文件并点击了保存按钮
|
||||
if (result == false)
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.ERROR, "取消保存文件");
|
||||
return;
|
||||
}
|
||||
|
||||
var savePath = saveFileDialog.FileName;
|
||||
string? librarySavePath = System.IO.Path.GetDirectoryName(savePath);
|
||||
if (string.IsNullOrEmpty(librarySavePath))
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.ERROR, "保存项目DLL时返回了意外的文件保存路径");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Uri saveProjectFileUri = new Uri(savePath);
|
||||
SereinEnv.WriteLine(InfoType.INFO, "项目文件保存路径:" + savePath);
|
||||
for (int index = 0; index < project.Librarys.Length; index++)
|
||||
{
|
||||
NodeLibraryInfo? library = project.Librarys[index];
|
||||
string sourceFilePath = new Uri(library.FilePath).LocalPath; // 源文件夹
|
||||
string targetDir = System.IO.Path.Combine(librarySavePath, library.AssemblyName); // 目标文件夹
|
||||
if (!Path.Exists(targetDir))
|
||||
{
|
||||
Directory.CreateDirectory(targetDir);
|
||||
}
|
||||
string targetFilePath = System.IO.Path.Combine(targetDir, library.FileName); // 目标文件夹
|
||||
|
||||
try
|
||||
{
|
||||
if (File.Exists(sourceFilePath))
|
||||
{
|
||||
if (!File.Exists(targetFilePath))
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"源文件路径 : {sourceFilePath}");
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"目标路径 : {targetFilePath}");
|
||||
File.Copy(sourceFilePath, targetFilePath, true);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.WARN, $"目标路径已有类库文件: {targetFilePath}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SereinEnv.WriteLine(InfoType.WARN, $"源文件不存在 : {targetFilePath}");
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
|
||||
SereinEnv.WriteLine(InfoType.ERROR, ex.Message);
|
||||
}
|
||||
var dirName = System.IO.Path.GetDirectoryName(targetFilePath);
|
||||
if (!string.IsNullOrEmpty(dirName))
|
||||
{
|
||||
var tmpUri2 = new Uri(targetFilePath);
|
||||
var relativePath = saveProjectFileUri.MakeRelativeUri(tmpUri2).ToString(); // 转为类库的相对文件路径
|
||||
|
||||
//string relativePath = System.IO.Path.GetRelativePath(savePath, targetPath);
|
||||
project.Librarys[index].FilePath = relativePath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
JObject projectJsonData = JObject.FromObject(project);
|
||||
File.WriteAllText(savePath, projectJsonData.ToString());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Workbench.Api;
|
||||
using Serein.Workbench.Node.View;
|
||||
using Serein.Workbench.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Serein.Workbench.ViewModels
|
||||
{
|
||||
public partial class FlowCanvasViewModel : ObservableObject
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 画布当前选中的节点
|
||||
/// </summary>
|
||||
public NodeControlBase CurrentSelectNodeControl { get; set; }
|
||||
|
||||
public NodeControlBase CurrentSelectNode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 正在创建节点方法调用关系
|
||||
@@ -29,29 +35,13 @@ namespace Serein.Workbench.ViewModels
|
||||
[ObservableProperty]
|
||||
private bool _isConnectionArgSourceNode;
|
||||
|
||||
/// <summary>
|
||||
/// 画布显示名称
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _name;
|
||||
|
||||
/// <summary>
|
||||
/// 画布ID
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _canvasGuid;
|
||||
|
||||
/// <summary>
|
||||
/// 画布数据实体
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private FlowCanvasModel _model;
|
||||
private FlowCanvasDetails _model;
|
||||
|
||||
|
||||
|
||||
public FlowCanvasViewModel()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Serein.Workbench.Api;
|
||||
using Serein.Workbench.Models;
|
||||
using Serein.Workbench.Node.View;
|
||||
using Serein.Workbench.Services;
|
||||
using Serein.Workbench.Views;
|
||||
using System;
|
||||
@@ -20,13 +22,17 @@ namespace Serein.Workbench.ViewModels
|
||||
/// </summary>
|
||||
public partial class FlowEditViewModel : ObservableObject
|
||||
{
|
||||
public ObservableCollection<FlowCanvasModel> Tabs { get; set; } = [];
|
||||
public ObservableCollection<FlowEditorTabModel> CanvasTabs { get; set; } = [];
|
||||
public ICommand AddTabCommand { get; set; }
|
||||
public ICommand RemoveTabCommand { get; set; }
|
||||
public ICommand RenameTabCommand { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前选择的画布
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private FlowCanvasModel _selectedTab;
|
||||
private FlowEditorTabModel _selectedTab;
|
||||
|
||||
private readonly FlowNodeService flowNodeService;
|
||||
|
||||
@@ -34,39 +40,42 @@ namespace Serein.Workbench.ViewModels
|
||||
{
|
||||
this.flowNodeService = flowNodeService;
|
||||
AddTabCommand = new RelayCommand(AddTab);
|
||||
RemoveTabCommand = new RelayCommand(RemoveTab, CanRemoveTab);
|
||||
RemoveTabCommand = new RelayCommand(RemoveTab);
|
||||
|
||||
flowNodeService.OnCreateFlowCanvasView += OnCreateFlowCanvasView; // 运行环境创建了画布
|
||||
flowNodeService.OnRemoveFlowCanvasView += OnRemoveFlowCanvasView; // 运行环境移除了画布
|
||||
flowNodeService.OnCreateFlowCanvasView += OnCreateFlowCanvasView; // 创建了画布
|
||||
flowNodeService.OnRemoveFlowCanvasView += OnRemoveFlowCanvasView; // 移除了画布
|
||||
this.PropertyChanged += OnPropertyChanged;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void OnPropertyChanged(object? value, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (nameof(SelectedTab).Equals(e.PropertyName) && value is FlowCanvasModel model)
|
||||
{
|
||||
flowNodeService.CurrentSelectCanvas = model.Content; // 选中的视图发生改变
|
||||
}
|
||||
if (this.SelectedTab is null) return;
|
||||
flowNodeService.CurrentSelectCanvas = this.SelectedTab.Content;
|
||||
}
|
||||
|
||||
#region 响应环境事件
|
||||
private void OnCreateFlowCanvasView(FlowCanvasView FlowCanvasView)
|
||||
private void OnCreateFlowCanvasView(FlowCanvasView canvas)
|
||||
{
|
||||
var model = new FlowCanvasModel { Content = FlowCanvasView, Name = FlowCanvasView.ViewModel.Name };
|
||||
Tabs.Add(model);
|
||||
var model = new FlowEditorTabModel(canvas);
|
||||
CanvasTabs.Add(model);
|
||||
SelectedTab = model;
|
||||
}
|
||||
private void OnRemoveFlowCanvasView(string canvasGuid)
|
||||
private void OnRemoveFlowCanvasView(FlowCanvasView canvas)
|
||||
{
|
||||
var tab = Tabs.FirstOrDefault(t => t.Content.ViewModel.Model.Guid.Equals(canvasGuid, StringComparison.OrdinalIgnoreCase));
|
||||
var tab = CanvasTabs.FirstOrDefault(c => c.Content.Guid.Equals(canvas.Guid));
|
||||
if (tab is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Tabs.Remove(tab);
|
||||
Tabs.Remove(SelectedTab);
|
||||
if(Tabs.Count > 0 && Tabs[^1] is FlowCanvasModel view )
|
||||
CanvasTabs.Remove(tab);
|
||||
|
||||
if (CanvasTabs.Count > 0 && CanvasTabs[^1] is FlowEditorTabModel c)
|
||||
{
|
||||
SelectedTab = view;
|
||||
SelectedTab = c;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@@ -75,10 +84,9 @@ namespace Serein.Workbench.ViewModels
|
||||
private void AddTab() => flowNodeService.CreateFlowCanvas();
|
||||
private void RemoveTab()
|
||||
{
|
||||
if (Tabs.Count > 0 && SelectedTab != null) flowNodeService.RemoveFlowCanvas();
|
||||
if (CanvasTabs.Count > 0 && SelectedTab != null) flowNodeService.RemoveFlowCanvas();
|
||||
}
|
||||
|
||||
private bool CanRemoveTab() => SelectedTab != null;
|
||||
|
||||
|
||||
|
||||
@@ -86,12 +94,12 @@ namespace Serein.Workbench.ViewModels
|
||||
/// 进入编辑模式
|
||||
/// </summary>
|
||||
/// <param name="tab"></param>
|
||||
public void StartEditingTab(FlowCanvasModel tab)
|
||||
public void StartEditingTab(FlowEditorTabModel tab)
|
||||
{
|
||||
if (tab != null)
|
||||
{
|
||||
tab.IsEditing = true;
|
||||
OnPropertyChanged(nameof(Tabs)); // 刷新Tabs集合,以便更新UI
|
||||
OnPropertyChanged(nameof(CanvasTabs)); // 刷新Tabs集合,以便更新UI
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,13 +108,13 @@ namespace Serein.Workbench.ViewModels
|
||||
/// </summary>
|
||||
/// <param name="tab"></param>
|
||||
/// <param name="newName"></param>
|
||||
public void EndEditingTab(FlowCanvasModel tab, string newName)
|
||||
public void EndEditingTab(FlowEditorTabModel tab, string? newName = null)
|
||||
{
|
||||
if (tab != null)
|
||||
{
|
||||
tab.IsEditing = false;
|
||||
tab.Name = newName; // 设置新名称
|
||||
OnPropertyChanged(nameof(Tabs)); // 刷新Tabs集合
|
||||
if(tab.Name != newName && !string.IsNullOrWhiteSpace(newName)) tab.Name = newName; // 名称合法时设置新名称
|
||||
OnPropertyChanged(nameof(CanvasTabs)); // 刷新Tabs集合
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Serein.Workbench.Api;
|
||||
using Serein.Workbench.Models;
|
||||
using Serein.Workbench.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -13,10 +14,12 @@ namespace Serein.Workbench.ViewModels
|
||||
internal partial class FlowWorkbenchViewModel : ObservableObject
|
||||
{
|
||||
private readonly IFlowEEForwardingService flowEEForwardingService;
|
||||
private readonly IWorkbenchEventService workbenchEventService;
|
||||
|
||||
public FlowWorkbenchViewModel(IFlowEEForwardingService flowEEForwardingService)
|
||||
public FlowWorkbenchViewModel(IFlowEEForwardingService flowEEForwardingService, IWorkbenchEventService workbenchEventService)
|
||||
{
|
||||
this.flowEEForwardingService = flowEEForwardingService;
|
||||
this.workbenchEventService = workbenchEventService;
|
||||
//flowEEForwardingService.OnDllLoad += FlowEEForwardingService_OnDllLoad;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,23 +21,33 @@ namespace Serein.Workbench.ViewModels
|
||||
/// 加载远程项目
|
||||
/// </summary>
|
||||
public ICommand LoadRemoteProjectCommand { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 增加流程图
|
||||
/// </summary>
|
||||
public ICommand CreateFlowCanvasCommand { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 增加流程图
|
||||
/// 移除流程图
|
||||
/// </summary>
|
||||
public ICommand RemoteFlowCanvasCommand { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 运行当前画布流程
|
||||
/// </summary>
|
||||
public ICommand StartCurrentCanvasFlowCommand { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 停止当前画布流程
|
||||
/// </summary>
|
||||
public ICommand StopCurrentCanvasFlowCommand { get; private set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 打开环境输出窗口
|
||||
/// </summary>
|
||||
public ICommand OpenEnvOutWindowCommand { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 打开动态编译窗口
|
||||
/// </summary>
|
||||
@@ -49,13 +59,33 @@ namespace Serein.Workbench.ViewModels
|
||||
{
|
||||
this.environment = environment;
|
||||
|
||||
SaveProjectCommand = new RelayCommand(SaveProject);
|
||||
SaveProjectCommand = new RelayCommand(SaveProject); // 保存项目
|
||||
LoadLocalProjectCommand = new RelayCommand(LoadLocalProject); // 加载本地项目
|
||||
LoadRemoteProjectCommand = new RelayCommand(LoadRemoteProject); // 加载远程项目
|
||||
|
||||
CreateFlowCanvasCommand = new RelayCommand(CreateFlowCanvas); // 增加画布
|
||||
RemoteFlowCanvasCommand = new RelayCommand(RemoteFlowCanvas); // 移除画布
|
||||
|
||||
StartCurrentCanvasFlowCommand = new RelayCommand(StartCurrentCanvasFlow); // 运行当前流程
|
||||
StopCurrentCanvasFlowCommand = new RelayCommand(StopCurrentCanvasFlow); // 停止当前流程
|
||||
|
||||
OpenEnvOutWindowCommand = new RelayCommand(OpenEnvOutWindow); // 打开运行输出窗口
|
||||
OpenDynamicCompilerCommand = new RelayCommand(OpenDynamicCompiler); // 打开动态编译仓库窗口
|
||||
}
|
||||
|
||||
public void SaveProject()
|
||||
{
|
||||
|
||||
private void SaveProject() {
|
||||
environment.SaveProject(); // 保存项目
|
||||
}
|
||||
private void LoadLocalProject() {
|
||||
//environment.LoadProject(); // 加载项目
|
||||
}
|
||||
private void LoadRemoteProject() { }
|
||||
private void CreateFlowCanvas() { }
|
||||
private void RemoteFlowCanvas() { }
|
||||
private void StartCurrentCanvasFlow() { }
|
||||
private void StopCurrentCanvasFlow() { }
|
||||
private void OpenDynamicCompiler() { }
|
||||
private void OpenEnvOutWindow() { }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,11 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Serein.Workbench.Views"
|
||||
xmlns:tool="clr-namespace:Serein.Workbench.Tool.Converters"
|
||||
xmlns:vm="clr-namespace:Serein.Workbench.ViewModels"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance vm:FlowCanvasViewModel}">
|
||||
|
||||
<UserControl.Resources>
|
||||
<tool:RightThumbPositionConverter x:Key="RightThumbPositionConverter" />
|
||||
@@ -16,22 +19,23 @@
|
||||
</UserControl.Resources>
|
||||
|
||||
<DockPanel x:Name="FlowChartStackPanel"
|
||||
ClipToBounds="True">
|
||||
ClipToBounds="True">
|
||||
|
||||
<Canvas ClipToBounds="True"
|
||||
x:Name="FlowChartCanvas"
|
||||
Background="#E1FBEA"
|
||||
AllowDrop="True"
|
||||
Width="1000"
|
||||
Height="600"
|
||||
MouseLeftButtonDown ="FlowChartCanvas_MouseLeftButtonDown"
|
||||
MouseLeftButtonUp="FlowChartCanvas_MouseLeftButtonUp"
|
||||
MouseDown="FlowChartCanvas_MouseDown"
|
||||
MouseUp="FlowChartCanvas_MouseUp"
|
||||
MouseMove="FlowChartCanvas_MouseMove"
|
||||
MouseWheel="FlowChartCanvas_MouseWheel"
|
||||
Drop="FlowChartCanvas_Drop"
|
||||
DragOver="FlowChartCanvas_DragOver"
|
||||
>
|
||||
x:Name="FlowChartCanvas"
|
||||
Background="#E1FBEA"
|
||||
AllowDrop="True"
|
||||
Width="{Binding Model.Width, Mode=TwoWay}"
|
||||
Height="{Binding Model.Height, Mode=TwoWay}"
|
||||
MouseLeftButtonDown ="FlowChartCanvas_MouseLeftButtonDown"
|
||||
MouseLeftButtonUp="FlowChartCanvas_MouseLeftButtonUp"
|
||||
MouseDown="FlowChartCanvas_MouseDown"
|
||||
MouseUp="FlowChartCanvas_MouseUp"
|
||||
MouseMove="FlowChartCanvas_MouseMove"
|
||||
MouseWheel="FlowChartCanvas_MouseWheel"
|
||||
Drop="FlowChartCanvas_Drop"
|
||||
DragOver="FlowChartCanvas_DragOver"
|
||||
>
|
||||
|
||||
<Rectangle x:Name="SelectionRectangle"
|
||||
Stroke="Blue"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,29 +19,30 @@
|
||||
<!--DragOver="TabControl_DragOver"
|
||||
Drop="TabControl_Drop"
|
||||
AllowDrop="True"-->
|
||||
<TabControl SelectedItem="{Binding SelectedTab}" >
|
||||
<TabControl SelectedItem="{Binding SelectedTab}"
|
||||
SelectionChanged="TabControl_SelectionChanged"
|
||||
x:Name="CanvasTab">
|
||||
<TabControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel>
|
||||
<StackPanel >
|
||||
<!-- 双击选项卡名称来进入编辑模式 -->
|
||||
<TextBlock Text="{Binding Name}"
|
||||
FontSize="18"
|
||||
Visibility="{Binding IsEditing, Converter={StaticResource InvertableBooleanToVisibilityConverter},ConverterParameter=Inverted}"
|
||||
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"/>
|
||||
KeyDown="TextBox_KeyDown" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</TabControl.ItemTemplate>
|
||||
|
||||
<!-- Tabs Collection -->
|
||||
<TabControl.ItemsSource>
|
||||
<Binding Path="Tabs" />
|
||||
<Binding Path="CanvasTabs" />
|
||||
</TabControl.ItemsSource>
|
||||
|
||||
<!-- Content of the Tab (e.g., FlowCanvasView) -->
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Serein.Workbench.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -30,16 +31,18 @@ namespace Serein.Workbench.Views
|
||||
/// </summary>
|
||||
public partial class FlowEditView : UserControl
|
||||
{
|
||||
|
||||
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;
|
||||
var tab = textBlock?.DataContext as FlowCanvasViewModel;
|
||||
if (tab != null)
|
||||
{
|
||||
DragDrop.DoDragDrop(textBlock, tab, DragDropEffects.Move);
|
||||
@@ -47,7 +50,7 @@ namespace Serein.Workbench.Views
|
||||
}
|
||||
private void TabControl_DragOver(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(FlowCanvasModel)))
|
||||
if (e.Data.GetDataPresent(typeof(FlowCanvasViewModel)))
|
||||
{
|
||||
e.Effects = DragDropEffects.Move;
|
||||
}
|
||||
@@ -59,73 +62,83 @@ namespace Serein.Workbench.Views
|
||||
|
||||
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 sourceTab = e.Data.GetData(typeof(FlowEditorTabModel)) as FlowEditorTabModel;
|
||||
var targetTab = (sender as TabControl)?.SelectedItem as FlowEditorTabModel;
|
||||
var viewModel = (FlowEditViewModel)this.DataContext;
|
||||
if (sourceTab != null && targetTab != null && sourceTab != targetTab)
|
||||
{
|
||||
var sourceIndex = viewModel.Tabs.IndexOf(sourceTab);
|
||||
var targetIndex = viewModel.Tabs.IndexOf(targetTab);
|
||||
var sourceIndex = viewModel.CanvasTabs.IndexOf(sourceTab);
|
||||
var targetIndex = viewModel.CanvasTabs.IndexOf(targetTab);
|
||||
|
||||
// 删除源项并插入到目标位置
|
||||
viewModel.Tabs.Remove(sourceTab);
|
||||
viewModel.Tabs.Insert(targetIndex, sourceTab);
|
||||
|
||||
viewModel.CanvasTabs.Remove(sourceTab);
|
||||
viewModel.CanvasTabs.Insert(targetIndex, sourceTab);
|
||||
|
||||
// 更新视图模型中的选中的Tab
|
||||
viewModel.SelectedTab = sourceTab;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 按下确认或回车
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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))
|
||||
if (sender is TextBox textBox
|
||||
&& textBox.DataContext is FlowEditorTabModel tab
|
||||
&& DataContext is FlowEditViewModel viewModel)
|
||||
{
|
||||
viewModel.EndEditingTab(tab, textBox.Text); // 确认新名称
|
||||
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); // 确认新名称
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 双击tab进入编辑状态
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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)
|
||||
if (sender is TextBlock textBlock
|
||||
&& textBlock.DataContext is FlowEditorTabModel tab
|
||||
&& DataContext is FlowEditViewModel viewModel)
|
||||
{
|
||||
var viewModel = (FlowEditViewModel)this.DataContext;
|
||||
viewModel.StartEditingTab(tab);
|
||||
viewModel.StartEditingTab(tab); // 确认新名称
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private FlowEditorTabModel lastTab;
|
||||
|
||||
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is TabControl tabControl
|
||||
&& tabControl.SelectedIndex > 0
|
||||
&& DataContext is FlowEditViewModel viewModel
|
||||
&& viewModel.CanvasTabs[tabControl.SelectedIndex] is FlowEditorTabModel tab)
|
||||
{
|
||||
|
||||
viewModel.EndEditingTab(lastTab); // 确认新名称
|
||||
lastTab = tab;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,15 @@
|
||||
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="70" d:DesignWidth="350">
|
||||
d:DesignHeight="70" d:DesignWidth="350"
|
||||
d:DataContext="{d:DesignInstance vm:MainMenuBarViewModel}"
|
||||
>
|
||||
<Grid >
|
||||
<Menu DockPanel.Dock="Top" Grid.Row="0" Grid.ColumnSpan="5" Height="20">
|
||||
<MenuItem Header="项目">
|
||||
<MenuItem Header="保存项目" ></MenuItem>
|
||||
<MenuItem Header="保存项目" Command="{Binding SaveProjectCommand}"></MenuItem>
|
||||
<MenuItem Header="加载本地项目" ></MenuItem>
|
||||
<MenuItem Header="加载远程项目"></MenuItem>
|
||||
</MenuItem>
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Serein.Workbench.Views
|
||||
{
|
||||
public MainMenuBarView()
|
||||
{
|
||||
this.DataContext = App.GetService<Locator>().MainViewModel;
|
||||
this.DataContext = App.GetService<Locator>().MainMenuBarViewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user