优化了Workbench上的操作。

This commit is contained in:
fengjiayi
2025-05-30 23:31:31 +08:00
parent f0eb11c914
commit a19733eff5
35 changed files with 807 additions and 225 deletions

View File

@@ -9,6 +9,7 @@ using Serein.Workbench.Node.ViewModel;
using Serein.Workbench.ViewModels;
using Serein.Workbench.Views;
using System;
using System.Reactive;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
@@ -20,7 +21,7 @@ namespace Serein.Workbench.Services
/// <summary>
/// 流程节点管理
/// </summary>
public class FlowNodeService
public class FlowNodeService
{
@@ -44,6 +45,16 @@ namespace Serein.Workbench.Services
/// </summary>
public Action<FlowCanvasView> OnViewCanvasChanged{ get; set; }
/// <summary>
/// 查看的节点发生变化
/// </summary>
public Action<NodeControlBase> OnViewNodeControlChanged{ get; set; }
/// <summary>
/// 查看方法发生变化
/// </summary>
public Action<MethodDetailsInfo> OnViewMethodDetailsInfoChanged { get; set; }
#endregion
#region
@@ -64,10 +75,39 @@ namespace Serein.Workbench.Services
}
}
private NodeControlBase? currentSelectNodeControl;
/// <summary>
/// 当前选中的节点
/// </summary>
public NodeControlBase? CurrentSelectNodeControl { get => currentSelectNodeControl; set
{
if (value == null || value.Equals(currentSelectNodeControl))
{
return;
}
currentSelectNodeControl = value;
OnViewNodeControlChanged?.Invoke(value);
}
}
private MethodDetailsInfo? currentMethodDetailsInfo;
/// <summary>
/// 当前拖动的方法信息
/// </summary>
public MethodDetailsInfo? CurrentDragMdInfo { get; set; }
public MethodDetailsInfo? CurrentMethodDetailsInfo { get => currentMethodDetailsInfo; set
{
if (value == null || value.Equals(currentMethodDetailsInfo))
{
return;
}
currentMethodDetailsInfo = value;
OnViewMethodDetailsInfoChanged?.Invoke(value);
}
}
/// <summary>
/// 当前需要创建的节点类型
@@ -79,10 +119,6 @@ namespace Serein.Workbench.Services
/// </summary>
public PositionOfUI? CurrentMouseLocation { get; set; }
/// <summary>
/// 当前选中的节点
/// </summary>
public NodeControlBase? CurrentSelectNodeControl { get; set; }
/// <summary>
/// 连接数据
@@ -651,7 +687,7 @@ namespace Serein.Workbench.Services
string canvasGuid = model.Guid;
NodeControlType nodeType = CurrentNodeControlType;
PositionOfUI? position = CurrentMouseLocation;
MethodDetailsInfo? methodDetailsInfo = CurrentDragMdInfo;
MethodDetailsInfo? methodDetailsInfo = CurrentMethodDetailsInfo;
if (position is null)
{

View File

@@ -0,0 +1,60 @@
using Newtonsoft.Json;
using Serein.Library;
using Serein.Library.Api;
using Serein.NodeFlow.Env;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serein.Workbench.Services
{
public class FlowProjectService
{
private readonly IFlowEnvironment flowEnvironment;
public SereinProjectData? FlowProjectData { get; set; }
public string FileDataPath { get; set; }
public FlowProjectService(IFlowEnvironment flowEnvironment)
{
this.flowEnvironment = flowEnvironment;
}
public void LoadLocalProject(string filePath)
{
if (File.Exists(filePath))
{
string content = System.IO.File.ReadAllText(filePath); // 读取整个文件内容
this.FlowProjectData = JsonConvert.DeserializeObject<SereinProjectData>(content);
this.FileDataPath = System.IO.Path.GetDirectoryName(filePath)!; // filePath;//
var dir = Path.GetDirectoryName(filePath);
var flowEnvInfo = new FlowEnvInfo
{
Project = FlowProjectData,
};
flowEnvironment.LoadProject(flowEnvInfo, FileDataPath);
}
}
public void SelectProjectFile()
{
System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
openFileDialog.Filter = "流程项目文件|*.dnf|所有文件|*.*";
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
openFileDialog.Title = "打开项目文件";
openFileDialog.Multiselect = false;
// 显示文件对话框
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// 获取用户选择的文件路径
var projectFile = openFileDialog.FileName;
LoadLocalProject(projectFile);
}
}
}
}