diff --git a/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs b/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs index 345a35e..3de825d 100644 --- a/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs +++ b/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs @@ -100,7 +100,7 @@ namespace AIStudio.Wpf.Flowchart DiagramViewModel = DiagramViewModels.FirstOrDefault(); InitDiagramViewModel(); - var level1node = MindDiagramViewModel.RootItem; + var level1node = MindDiagramViewModel.RootItems.FirstOrDefault(); MindNode level2node1_1 = new MindNode(DiagramViewModel) { Text = "分支主题1" }; MindDiagramViewModel.AddChildCommand.Execute(new MindNode[] { level1node, level2node1_1 }); diff --git a/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs b/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs index eb5803b..327da44 100644 --- a/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs +++ b/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs @@ -144,13 +144,11 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels if (_diagramViewModel != null) { _diagramViewModel.PropertyChanged -= DiagramViewModel_PropertyChanged; - _diagramViewModel.OutAddVerify -= AddVerify; } SetProperty(ref _diagramViewModel, value); if (_diagramViewModel != null) { _diagramViewModel.PropertyChanged += DiagramViewModel_PropertyChanged; - _diagramViewModel.OutAddVerify += AddVerify; } } } diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/CinchMenuItem.cs b/AIStudio.Wpf.DiagramDesigner/Controls/CinchMenuItem.cs index 08f6515..e3633ec 100644 --- a/AIStudio.Wpf.DiagramDesigner/Controls/CinchMenuItem.cs +++ b/AIStudio.Wpf.DiagramDesigner/Controls/CinchMenuItem.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Windows.Input; namespace AIStudio.Wpf.DiagramDesigner { @@ -59,13 +60,13 @@ namespace AIStudio.Wpf.DiagramDesigner public class CinchMenuItem { #region Public Properties - public String Text { get; set; } - public String IconUrl { get; set; } + public string Text { get; set; } + public string IconUrl { get; set; } public bool IsChecked { get; set; } public bool IsCheckable { get; set; } public List Children { get; private set; } - public Object CommandParameter { get; set; } - public SimpleCommand Command { get; set; } + public object CommandParameter { get; set; } + public ICommand Command { get; set; } #endregion #region Ctor diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/ConnectionViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/ConnectionViewModel.cs index 26e955f..ff197d5 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/ConnectionViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/ConnectionViewModel.cs @@ -27,14 +27,14 @@ namespace AIStudio.Wpf.DiagramDesigner { PathMode = drawMode.ToString(); RouterMode = routerMode.ToString(); - Init(sourceConnectorInfo, sinkConnectorInfo); + Init(root, sourceConnectorInfo, sinkConnectorInfo); } public ConnectionViewModel(IDiagramViewModel root, FullyCreatedConnectorInfo sourceConnectorInfo, FullyCreatedConnectorInfo sinkConnectorInfo, ConnectionItem designer) : base(root, designer) { PathMode = designer.PathMode; RouterMode = designer.RouterMode; - Init(sourceConnectorInfo, sinkConnectorInfo); + Init(root, sourceConnectorInfo, sinkConnectorInfo); } public override SelectableItemBase GetSerializableObject() @@ -51,9 +51,9 @@ namespace AIStudio.Wpf.DiagramDesigner } } - protected virtual void Init(FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo) + protected virtual void Init(IDiagramViewModel root, FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo) { - this.Root = sourceConnectorInfo.DataItem.Root; + this.Root = root?? sourceConnectorInfo.Root; if (sinkConnectorInfo is FullyCreatedConnectorInfo sink && sink.DataItem.ShowArrow == false) { @@ -427,17 +427,17 @@ namespace AIStudio.Wpf.DiagramDesigner #endregion #region 方法 - public SimpleCommand DeleteConnectionCommand + public ICommand DeleteConnectionCommand { get; set; } - public SimpleCommand AddVertexCommand + public ICommand AddVertexCommand { get; set; } - public SimpleCommand AddLabelCommand + public ICommand AddLabelCommand { get; set; } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/ConnectorLabelModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/ConnectorLabelModel.cs index 8552004..182fe40 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/ConnectorLabelModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/ConnectorLabelModel.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Windows.Input; using AIStudio.Wpf.DiagramDesigner.Geometrys; using AIStudio.Wpf.DiagramDesigner.Models; using SvgPathProperties; @@ -82,12 +83,12 @@ namespace AIStudio.Wpf.DiagramDesigner get; set; } - public SimpleCommand DeleteLabelCommand + public ICommand DeleteLabelCommand { get; set; } - public SimpleCommand EditCommand + public ICommand EditCommand { get; private set; } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/ConnectorVertexModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/ConnectorVertexModel.cs index 4125151..1c75a91 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/ConnectorVertexModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/ConnectorVertexModel.cs @@ -1,4 +1,5 @@ using System; +using System.Windows.Input; using AIStudio.Wpf.DiagramDesigner.Geometrys; using AIStudio.Wpf.DiagramDesigner.Models; @@ -68,7 +69,7 @@ namespace AIStudio.Wpf.DiagramDesigner public override PointBase MiddlePosition => new PointBase(Connector.Area.Left + Left + ConnectorWidth / 2, Connector.Area.Top + Top + ConnectorHeight / 2); - public SimpleCommand DeleteVertexCommand + public ICommand DeleteVertexCommand { get; set; } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/FullyCreatedConnectorInfo.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/FullyCreatedConnectorInfo.cs index 9d14985..0ec46f5 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/FullyCreatedConnectorInfo.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/FullyCreatedConnectorInfo.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; +using System.Windows.Input; using AIStudio.Wpf.DiagramDesigner.Geometrys; using AIStudio.Wpf.DiagramDesigner.Models; @@ -185,11 +186,11 @@ namespace AIStudio.Wpf.DiagramDesigner #endregion #region 方法 - public SimpleCommand DeleteCommand + public ICommand DeleteCommand { get; private set; } - public SimpleCommand MenuItemCommand + public ICommand MenuItemCommand { get; private set; } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs index c5cc53d..dfd5432 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs @@ -630,13 +630,17 @@ namespace AIStudio.Wpf.DiagramDesigner get; set; } = true; + protected DoCommandManager DoCommandManager = new DoCommandManager(); + + public event DiagramEventHandler Event; + private double OffsetX = 10; private double OffsetY = 10; #endregion #region 命令 - private SimpleCommand _createNewDiagramCommand; - public SimpleCommand CreateNewDiagramCommand + private ICommand _createNewDiagramCommand; + public ICommand CreateNewDiagramCommand { get { @@ -644,8 +648,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _directAddItemCommand; - public SimpleCommand DirectAddItemCommand + private ICommand _directAddItemCommand; + public ICommand DirectAddItemCommand { get { @@ -653,8 +657,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _addItemCommand; - public SimpleCommand AddItemCommand + private ICommand _addItemCommand; + public ICommand AddItemCommand { get { @@ -662,8 +666,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _directRemoveItemCommand; - public SimpleCommand DirectRemoveItemCommand + private ICommand _directRemoveItemCommand; + public ICommand DirectRemoveItemCommand { get { @@ -671,8 +675,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _removeItemCommand; - public SimpleCommand RemoveItemCommand + private ICommand _removeItemCommand; + public ICommand RemoveItemCommand { get { @@ -680,8 +684,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _clearSelectedItemsCommand; - public SimpleCommand ClearSelectedItemsCommand + private ICommand _clearSelectedItemsCommand; + public ICommand ClearSelectedItemsCommand { get { @@ -689,8 +693,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _alignTopCommand; - public SimpleCommand AlignTopCommand + private ICommand _alignTopCommand; + public ICommand AlignTopCommand { get { @@ -698,8 +702,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _alignVerticalCentersCommand; - public SimpleCommand AlignVerticalCentersCommand + private ICommand _alignVerticalCentersCommand; + public ICommand AlignVerticalCentersCommand { get { @@ -707,8 +711,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _alignBottomCommand; - public SimpleCommand AlignBottomCommand + private ICommand _alignBottomCommand; + public ICommand AlignBottomCommand { get { @@ -716,8 +720,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _alignLeftCommand; - public SimpleCommand AlignLeftCommand + private ICommand _alignLeftCommand; + public ICommand AlignLeftCommand { get { @@ -725,8 +729,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _alignHorizontalCentersCommand; - public SimpleCommand AlignHorizontalCentersCommand + private ICommand _alignHorizontalCentersCommand; + public ICommand AlignHorizontalCentersCommand { get { @@ -734,8 +738,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _alignRightCommand; - public SimpleCommand AlignRightCommand + private ICommand _alignRightCommand; + public ICommand AlignRightCommand { get { @@ -743,8 +747,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _bringForwardCommand; - public SimpleCommand BringForwardCommand + private ICommand _bringForwardCommand; + public ICommand BringForwardCommand { get { @@ -752,8 +756,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _bringToFrontCommand; - public SimpleCommand BringToFrontCommand + private ICommand _bringToFrontCommand; + public ICommand BringToFrontCommand { get { @@ -761,8 +765,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _sendBackwardCommand; - public SimpleCommand SendBackwardCommand + private ICommand _sendBackwardCommand; + public ICommand SendBackwardCommand { get { @@ -770,8 +774,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _sendToBackCommand; - public SimpleCommand SendToBackCommand + private ICommand _sendToBackCommand; + public ICommand SendToBackCommand { get { @@ -779,8 +783,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _distributeHorizontalCommand; - public SimpleCommand DistributeHorizontalCommand + private ICommand _distributeHorizontalCommand; + public ICommand DistributeHorizontalCommand { get { @@ -788,8 +792,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _distributeVerticalCommand; - public SimpleCommand DistributeVerticalCommand + private ICommand _distributeVerticalCommand; + public ICommand DistributeVerticalCommand { get { @@ -797,8 +801,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _selectAllCommand; - public SimpleCommand SelectAllCommand + private ICommand _selectAllCommand; + public ICommand SelectAllCommand { get { @@ -806,8 +810,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _selectInverseCommand; - public SimpleCommand SelectInverseCommand + private ICommand _selectInverseCommand; + public ICommand SelectInverseCommand { get { @@ -815,8 +819,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _selectItemCommand; - public SimpleCommand SelectItemCommand + private ICommand _selectItemCommand; + public ICommand SelectItemCommand { get { @@ -824,8 +828,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _copyCommand; - public SimpleCommand CopyCommand + private ICommand _copyCommand; + public ICommand CopyCommand { get { @@ -833,8 +837,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _pasteCommand; - public SimpleCommand PasteCommand + private ICommand _pasteCommand; + public ICommand PasteCommand { get { @@ -842,8 +846,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _cutCommand; - public SimpleCommand CutCommand + private ICommand _cutCommand; + public ICommand CutCommand { get { @@ -851,8 +855,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _deleteCommand; - public virtual SimpleCommand DeleteCommand + private ICommand _deleteCommand; + public virtual ICommand DeleteCommand { get { @@ -860,8 +864,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _leftMoveCommand; - public SimpleCommand LeftMoveCommand + private ICommand _leftMoveCommand; + public ICommand LeftMoveCommand { get { @@ -869,8 +873,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _rightMoveCommand; - public SimpleCommand RightMoveCommand + private ICommand _rightMoveCommand; + public ICommand RightMoveCommand { get { @@ -878,8 +882,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _upMoveCommand; - public SimpleCommand UpMoveCommand + private ICommand _upMoveCommand; + public ICommand UpMoveCommand { get { @@ -887,8 +891,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _downMoveCommand; - public SimpleCommand DownMoveCommand + private ICommand _downMoveCommand; + public ICommand DownMoveCommand { get { @@ -896,8 +900,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _centerMoveCommand; - public SimpleCommand CenterMoveCommand + private ICommand _centerMoveCommand; + public ICommand CenterMoveCommand { get { @@ -905,8 +909,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _sameSizeCommand; - public SimpleCommand SameSizeCommand + private ICommand _sameSizeCommand; + public ICommand SameSizeCommand { get { @@ -914,8 +918,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _sameWidthCommand; - public SimpleCommand SameWidthCommand + private ICommand _sameWidthCommand; + public ICommand SameWidthCommand { get { @@ -923,8 +927,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _sameHeightCommand; - public SimpleCommand SameHeightCommand + private ICommand _sameHeightCommand; + public ICommand SameHeightCommand { get { @@ -932,8 +936,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _sameAngleCommand; - public SimpleCommand SameAngleCommand + private ICommand _sameAngleCommand; + public ICommand SameAngleCommand { get { @@ -941,8 +945,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _fitAutoCommand; - public SimpleCommand FitAutoCommand + private ICommand _fitAutoCommand; + public ICommand FitAutoCommand { get { @@ -950,8 +954,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _fitWidthCommand; - public SimpleCommand FitWidthCommand + private ICommand _fitWidthCommand; + public ICommand FitWidthCommand { get { @@ -959,8 +963,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _fitHeightCommand; - public SimpleCommand FitHeightCommand + private ICommand _fitHeightCommand; + public ICommand FitHeightCommand { get { @@ -968,8 +972,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _groupCommand; - public SimpleCommand GroupCommand + private ICommand _groupCommand; + public ICommand GroupCommand { get { @@ -977,8 +981,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _ungroupCommand; - public SimpleCommand UngroupCommand + private ICommand _ungroupCommand; + public ICommand UngroupCommand { get { @@ -986,8 +990,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _lockCommand; - public SimpleCommand LockCommand + private ICommand _lockCommand; + public ICommand LockCommand { get { @@ -995,8 +999,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _unlockCommand; - public SimpleCommand UnlockCommand + private ICommand _unlockCommand; + public ICommand UnlockCommand { get { @@ -1004,8 +1008,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _editCommand; - public SimpleCommand EditCommand + private ICommand _editCommand; + public ICommand EditCommand { get { @@ -1013,8 +1017,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _undoCommand; - public SimpleCommand UndoCommand + private ICommand _undoCommand; + public ICommand UndoCommand { get { @@ -1022,8 +1026,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _redoCommand; - public SimpleCommand RedoCommand + private ICommand _redoCommand; + public ICommand RedoCommand { get { @@ -1031,8 +1035,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _resetLayoutCommand; - public SimpleCommand ResetLayoutCommand + private ICommand _resetLayoutCommand; + public ICommand ResetLayoutCommand { get { @@ -1040,8 +1044,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _searchDownCommand; - public SimpleCommand SearchDownCommand + private ICommand _searchDownCommand; + public ICommand SearchDownCommand { get { @@ -1049,8 +1053,8 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private SimpleCommand _searchUpCommand; - public SimpleCommand SearchUpCommand + private ICommand _searchUpCommand; + public ICommand SearchUpCommand { get { @@ -1059,27 +1063,13 @@ namespace AIStudio.Wpf.DiagramDesigner } #endregion - protected DoCommandManager DoCommandManager = new DoCommandManager(); - - public event DiagramEventHandler Event; - - private IDisposable ZoomValueChangedSubscription; - + #region ctor和初始化 public DiagramViewModel() { Mediator.Instance.Register(this); - Items.CollectionChanged += Items_CollectionChanged; - - ZoomValueChangedSubscription = WhenPropertyChanged.Where(o => o.ToString() == nameof(ZoomValue)).Throttle(TimeSpan.FromMilliseconds(100)).Subscribe(OnZoomValueChanged);//Sample + var zoomValueChangedSubscription = WhenPropertyChanged.Where(o => o.ToString() == nameof(ZoomValue)).Throttle(TimeSpan.FromMilliseconds(100)).Subscribe(OnZoomValueChanged);//Sample } - - //提供给标尺计算,延迟100ms,等布局改变再计算。 - private void OnZoomValueChanged(string obj) - { - DelayZoomValue = ZoomValue; - } - public DiagramViewModel(DiagramItem diagramItem) : this() { DiagramType = diagramItem.DiagramType; @@ -1103,10 +1093,18 @@ namespace AIStudio.Wpf.DiagramDesigner DoCommandManager.Init(); } + protected virtual void ExecutedResetLayoutCommand(object obj) + { + + } + #endregion + + #region 命令使能 public virtual bool ExecuteEnable(object para) { return IsReadOnly == false; } + #endregion #region 菜单 private void BuildMenuOptions() @@ -1178,11 +1176,8 @@ namespace AIStudio.Wpf.DiagramDesigner } #endregion - protected virtual void ExecutedResetLayoutCommand(object obj) - { - - } + #region 属性改变 private void Items_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.OldItems != null) @@ -1234,6 +1229,13 @@ namespace AIStudio.Wpf.DiagramDesigner } } + //提供给标尺计算,延迟100ms,等布局改变再计算。 + private void OnZoomValueChanged(string obj) + { + DelayZoomValue = ZoomValue; + } + #endregion + [MediatorMessageSink("DoneDrawingMessage")] public void OnDoneDrawingMessage(bool dummy) { @@ -1243,26 +1245,12 @@ namespace AIStudio.Wpf.DiagramDesigner } } - public Func OutAddVerify - { - get; set; - } - public bool AddVerify(SelectableDesignerItemViewModelBase item) - { - if (item.InitData() == false) - return false; - - if (OutAddVerify != null && OutAddVerify(item) != true) - return false; - - return true; - } - #region 新增,删除 - private void ExecuteCreateNewDiagramCommand(object parameter) + protected virtual void ExecuteCreateNewDiagramCommand(object parameter) { this.Items.Clear(); } + private void ExecuteDirectAddItemCommand(object parameter) { if (parameter is SelectableDesignerItemViewModelBase ite) @@ -1283,29 +1271,7 @@ namespace AIStudio.Wpf.DiagramDesigner } } } - private void Add(SelectableDesignerItemViewModelBase item) - { - item.Root = this; - item.ZIndex = Items.Any() ? Items.Max(p => p.ZIndex) + 1 : 0; - if (item.Id == Guid.Empty) - { - item.Id = Guid.NewGuid(); - } - var logical = item as LogicalGateItemViewModelBase; - if (logical != null && logical.LogicalType > 0) - { - logical.OrderNumber = Items.OfType().Count(p => (int)p.LogicalType > 0) + 1; - } - - var designerItemViewModelBase = item as DesignerItemViewModelBase; - if (designerItemViewModelBase != null) - { - designerItemViewModelBase.SetCellAlignment(); - } - Items.Add(item); - item.IsSelected = true; - } private void ExecuteAddItemCommand(object parameter) { if (parameter is SelectableDesignerItemViewModelBase ite) @@ -1341,6 +1307,39 @@ namespace AIStudio.Wpf.DiagramDesigner }); } } + + public bool AddVerify(SelectableDesignerItemViewModelBase item) + { + if (item.InitData() == false) + return false; + + return true; + } + + private void Add(SelectableDesignerItemViewModelBase item) + { + item.Root = this; + item.ZIndex = Items.Any() ? Items.Max(p => p.ZIndex) + 1 : 0; + if (item.Id == Guid.Empty) + { + item.Id = Guid.NewGuid(); + } + + var logical = item as LogicalGateItemViewModelBase; + if (logical != null && logical.LogicalType > 0) + { + logical.OrderNumber = Items.OfType().Count(p => (int)p.LogicalType > 0) + 1; + } + + var designerItemViewModelBase = item as DesignerItemViewModelBase; + if (designerItemViewModelBase != null) + { + designerItemViewModelBase.SetCellAlignment(); + } + Items.Add(item); + item.IsSelected = true; + } + private void ExecuteDirectRemoveItemCommand(object parameter) { if (parameter is SelectableDesignerItemViewModelBase ite) @@ -1357,6 +1356,7 @@ namespace AIStudio.Wpf.DiagramDesigner } } } + private void ExecuteRemoveItemCommand(object parameter) { if (parameter is SelectableDesignerItemViewModelBase ite) @@ -1390,6 +1390,7 @@ namespace AIStudio.Wpf.DiagramDesigner }); } } + private void ExecuteClearSelectedItemsCommand(object parameter) { IEnumerable selectedItems; @@ -1415,6 +1416,7 @@ namespace AIStudio.Wpf.DiagramDesigner item.IsSelected = false; } } + private void ExecuteSelectAllCommand(object parameter) { foreach (var item in Items) @@ -1454,6 +1456,250 @@ namespace AIStudio.Wpf.DiagramDesigner } #endregion + #region 复制,粘贴 + private void ExecuteCopyCommand(object parameter) + { + Copy(parameter); + } + + private bool Copy(object parameter) + { + List selectedDesignerItems; + + List selectedConnections; + + if (parameter is IEnumerable para) + { + selectedDesignerItems = para.OfType().ToList(); + selectedConnections = para.OfType().ToList(); + } + else + { + if (SelectedItems.Count == 0) + { + return false; + } + var first = SelectedItems.OfType().FirstOrDefault(); + if (first != null && first.IsEditing == true) + { + return false; + } + selectedDesignerItems = SelectedItems.OfType().ToList(); + selectedConnections = SelectedItems.OfType().ToList(); + } + + + foreach (ConnectionViewModel connection in Items.OfType()) + { + if (!selectedConnections.Contains(connection)) + { + DesignerItemViewModelBase sourceItem = (from item in selectedDesignerItems + where item.Id == connection.SourceConnectorInfo.DataItem.Id + select item).FirstOrDefault(); + + DesignerItemViewModelBase sinkItem = (from item in selectedDesignerItems + where item.Id == connection.SinkConnectorInfoFully?.DataItem?.Id + select item).FirstOrDefault(); + + if (sourceItem != null && + sinkItem != null && + BelongToSameGroup(sourceItem, sinkItem)) + { + selectedConnections.Add(connection); + } + } + } + + string json = new SerializableObject + { + DesignerItems = selectedDesignerItems.Select(p => p.ToSerializableItem(".json")).Where(p => p != null).ToList(), + Connections = selectedConnections.Select(p => p.ToSerializableItem(".json")).Where(p => p != null).ToList(), + }.ToJson(); + + OffsetX = 10; + OffsetY = 10; + System.Windows.Clipboard.Clear(); + System.Windows.Clipboard.SetData(System.Windows.DataFormats.Serializable, json); + + return true; + } + + private void ExecutePasteCommand(object parameter) + { + Paste(parameter); + } + + protected virtual bool Paste(object parameter) + { + if (System.Windows.Clipboard.ContainsData(System.Windows.DataFormats.Serializable)) + { + string clipboardData = System.Windows.Clipboard.GetData(System.Windows.DataFormats.Serializable) as String; + + if (string.IsNullOrEmpty(clipboardData)) + return false; + try + { + List items = new List(); + SerializableObject copyitem = JsonConvert.DeserializeObject(clipboardData); + + Dictionary mappingOldToNewIDs = new Dictionary(); + + foreach (var diagramItemData in copyitem.DesignerItems) + { + DesignerItemViewModelBase newItem = null; + + Type type = TypeHelper.GetType(diagramItemData.ModelTypeName); + + DesignerItemViewModelBase itemBase = Activator.CreateInstance(type, this, diagramItemData, ".json") as DesignerItemViewModelBase; + Guid newID = Guid.NewGuid(); + mappingOldToNewIDs.Add(itemBase.Id, newID); + itemBase.Id = newID; + itemBase.Left += OffsetX; + itemBase.Top += OffsetY; + + newItem = itemBase; + + if (newItem != null) + { + items.Add(newItem); + } + } + + OffsetX += 10; + OffsetY += 10; + + List connectors = new List(); + foreach (var connection in copyitem.Connections) + { + var connectionItem = JsonConvert.DeserializeObject(connection.SerializableString); + Guid newID = Guid.NewGuid(); + mappingOldToNewIDs.Add(connectionItem.Id, newID); + + connectionItem.SourceId = mappingOldToNewIDs[connectionItem.SourceId]; + connectionItem.SinkId = mappingOldToNewIDs[connectionItem.SinkId]; + + connectionItem.SourceType = System.Type.GetType(connectionItem.SourceTypeName); + connectionItem.SinkType = System.Type.GetType(connectionItem.SinkTypeName); + DesignerItemViewModelBase sourceItem = DiagramViewModelHelper.GetConnectorDataItem(items, connectionItem.SourceId, connectionItem.SourceType); + ConnectorOrientation sourceConnectorOrientation = connectionItem.SourceOrientation; + FullyCreatedConnectorInfo sourceConnectorInfo = sourceItem.GetFullConnectorInfo(connectionItem.Id, sourceConnectorOrientation, connectionItem.SourceXRatio, connectionItem.SourceYRatio, connectionItem.SourceInnerPoint, connectionItem.SourceIsPortless); + + DesignerItemViewModelBase sinkItem = DiagramViewModelHelper.GetConnectorDataItem(items, connectionItem.SinkId, connectionItem.SinkType); + ConnectorOrientation sinkConnectorOrientation = connectionItem.SinkOrientation; + FullyCreatedConnectorInfo sinkConnectorInfo = sinkItem.GetFullConnectorInfo(connectionItem.Id, sinkConnectorOrientation, connectionItem.SinkXRatio, connectionItem.SinkYRatio, connectionItem.SinkInnerPoint, connectionItem.SinkIsPortless); + + ConnectionViewModel connectionVM = new ConnectionViewModel(this, sourceConnectorInfo, sinkConnectorInfo, connectionItem); + connectors.Add(connectionVM); + } + + //修复父级的引用 + foreach (var item in items) + { + if (item.ParentId != Guid.Empty) + { + if (mappingOldToNewIDs.ContainsKey(item.ParentId)) + item.ParentId = mappingOldToNewIDs[item.ParentId]; + } + } + items.AddRange(connectors); + FixConnection(items); + + DirectAddItemCommand.Execute(items); + } + catch (Exception e) + { + System.Windows.MessageBox.Show(e.StackTrace, e.Message, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); + } + return true; + } + else + { + return false; + } + } + + protected virtual void FixConnection(List items) + { + + } + + private bool ItemsToDeleteHasConnector(List itemsToRemove, ConnectorInfoBase connector) + { + if (connector is FullyCreatedConnectorInfo fully) + { + return itemsToRemove.Contains(fully.DataItem); + } + + return false; + } + + private void ExecuteCutCommand(object parameter) + { + Cut(parameter); + } + + private bool Cut(object parameter) + { + if (Paste(null) == false) + return false; + OffsetX = 0; + OffsetY = 0; + if (Delete(null) == false) + return false; + + return true; + } + + protected void ExecuteDeleteCommand(object parameter) + { + Delete(parameter); + } + + protected virtual bool Delete(object parameter) + { + List itemsToRemove; + + if (parameter is IEnumerable para) + { + itemsToRemove = para.OfType().ToList(); + } + else + { + if (SelectedItems.Count == 0) + { + return false; + } + var first = SelectedItems.OfType().FirstOrDefault(); + if (first != null && first.IsEditing == true) + { + return false; + } + itemsToRemove = SelectedItems.OfType().ToList(); + } + + List connectionsToAlsoRemove = new List(); + + foreach (var connector in Items.OfType()) + { + if (ItemsToDeleteHasConnector(itemsToRemove, connector.SourceConnectorInfo)) + { + connectionsToAlsoRemove.Add(connector); + } + + if (ItemsToDeleteHasConnector(itemsToRemove, connector.SinkConnectorInfo)) + { + connectionsToAlsoRemove.Add(connector); + } + + } + itemsToRemove.AddRange(connectionsToAlsoRemove); + + RemoveItemCommand.Execute(itemsToRemove); + + return true; + } + #endregion + #region 布局 private void ExecuteAlignTopCommand(object parameter) { @@ -2038,248 +2284,7 @@ namespace AIStudio.Wpf.DiagramDesigner }); } } - #endregion - - #region 复制,粘贴 - private void ExecuteCopyCommand(object parameter) - { - Copy(parameter); - } - - private bool Copy(object parameter) - { - List selectedDesignerItems; - - List selectedConnections; - - if (parameter is IEnumerable para) - { - selectedDesignerItems = para.OfType().ToList(); - selectedConnections = para.OfType().ToList(); - } - else - { - if (SelectedItems.Count == 0) - { - return false; - } - var first = SelectedItems.OfType().FirstOrDefault(); - if (first != null && first.IsEditing == true) - { - return false; - } - selectedDesignerItems = SelectedItems.OfType().ToList(); - selectedConnections = SelectedItems.OfType().ToList(); - } - - - foreach (ConnectionViewModel connection in Items.OfType()) - { - if (!selectedConnections.Contains(connection)) - { - DesignerItemViewModelBase sourceItem = (from item in selectedDesignerItems - where item.Id == connection.SourceConnectorInfo.DataItem.Id - select item).FirstOrDefault(); - - DesignerItemViewModelBase sinkItem = (from item in selectedDesignerItems - where item.Id == connection.SinkConnectorInfoFully?.DataItem?.Id - select item).FirstOrDefault(); - - if (sourceItem != null && - sinkItem != null && - BelongToSameGroup(sourceItem, sinkItem)) - { - selectedConnections.Add(connection); - } - } - } - - string json = new SerializableObject - { - DesignerItems = selectedDesignerItems.Select(p => p.ToSerializableItem(".json")).Where(p => p != null).ToList(), - Connections = selectedConnections.Select(p => p.ToSerializableItem(".json")).Where(p => p != null).ToList(), - }.ToJson(); - - OffsetX = 10; - OffsetY = 10; - System.Windows.Clipboard.Clear(); - System.Windows.Clipboard.SetData(System.Windows.DataFormats.Serializable, json); - - return true; - } - - private void ExecutePasteCommand(object parameter) - { - Paste(parameter); - } - - private bool Paste(object parameter) - { - if (System.Windows.Clipboard.ContainsData(System.Windows.DataFormats.Serializable)) - { - string clipboardData = System.Windows.Clipboard.GetData(System.Windows.DataFormats.Serializable) as String; - - if (string.IsNullOrEmpty(clipboardData)) - return false; - try - { - List items = new List(); - SerializableObject copyitem = JsonConvert.DeserializeObject(clipboardData); - - Dictionary mappingOldToNewIDs = new Dictionary(); - - foreach (var diagramItemData in copyitem.DesignerItems) - { - DesignerItemViewModelBase newItem = null; - - Type type = TypeHelper.GetType(diagramItemData.ModelTypeName); - - DesignerItemViewModelBase itemBase = Activator.CreateInstance(type, this, diagramItemData, ".json") as DesignerItemViewModelBase; - Guid newID = Guid.NewGuid(); - mappingOldToNewIDs.Add(itemBase.Id, newID); - itemBase.Id = newID; - itemBase.Left += OffsetX; - itemBase.Top += OffsetY; - - newItem = itemBase; - - if (newItem != null) - { - items.Add(newItem); - } - } - - - OffsetX += 10; - OffsetY += 10; - - List connectors = new List(); - foreach (var connection in copyitem.Connections) - { - var connectionItem = JsonConvert.DeserializeObject(connection.SerializableString); - Guid newID = Guid.NewGuid(); - mappingOldToNewIDs.Add(connectionItem.Id, newID); - - connectionItem.SourceId = mappingOldToNewIDs[connectionItem.SourceId]; - connectionItem.SinkId = mappingOldToNewIDs[connectionItem.SinkId]; - - connectionItem.SourceType = System.Type.GetType(connectionItem.SourceTypeName); - connectionItem.SinkType = System.Type.GetType(connectionItem.SinkTypeName); - DesignerItemViewModelBase sourceItem = DiagramViewModelHelper.GetConnectorDataItem(items, connectionItem.SourceId, connectionItem.SourceType); - ConnectorOrientation sourceConnectorOrientation = connectionItem.SourceOrientation; - FullyCreatedConnectorInfo sourceConnectorInfo = sourceItem.GetFullConnectorInfo(connectionItem.Id, sourceConnectorOrientation, connectionItem.SourceXRatio, connectionItem.SourceYRatio, connectionItem.SourceInnerPoint, connectionItem.SourceIsPortless); - - DesignerItemViewModelBase sinkItem = DiagramViewModelHelper.GetConnectorDataItem(items, connectionItem.SinkId, connectionItem.SinkType); - ConnectorOrientation sinkConnectorOrientation = connectionItem.SinkOrientation; - FullyCreatedConnectorInfo sinkConnectorInfo = sinkItem.GetFullConnectorInfo(connectionItem.Id, sinkConnectorOrientation, connectionItem.SinkXRatio, connectionItem.SinkYRatio, connectionItem.SinkInnerPoint, connectionItem.SinkIsPortless); - - ConnectionViewModel connectionVM = new ConnectionViewModel(this, sourceConnectorInfo, sinkConnectorInfo, connectionItem); - connectors.Add(connectionVM); - } - - //修复父级的引用 - foreach (var item in items) - { - if (item.ParentId != Guid.Empty) - { - if (mappingOldToNewIDs.ContainsKey(item.ParentId)) - item.ParentId = mappingOldToNewIDs[item.ParentId]; - } - } - - items.AddRange(connectors); - - DirectAddItemCommand.Execute(items); - } - catch (Exception e) - { - System.Windows.MessageBox.Show(e.StackTrace, e.Message, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); - } - - return true; - } - else - { - return false; - } - } - - private bool ItemsToDeleteHasConnector(List itemsToRemove, ConnectorInfoBase connector) - { - if (connector is FullyCreatedConnectorInfo fully) - { - return itemsToRemove.Contains(fully.DataItem); - } - - return false; - } - - private void ExecuteCutCommand(object parameter) - { - Cut(parameter); - } - - private bool Cut(object parameter) - { - if (Paste(null) == false) - return false; - OffsetX = 0; - OffsetY = 0; - if (Delete(null) == false) - return false; - - return true; - } - - protected void ExecuteDeleteCommand(object parameter) - { - Delete(parameter); - } - - protected virtual bool Delete(object parameter) - { - List itemsToRemove; - - if (parameter is IEnumerable para) - { - itemsToRemove = para.OfType().ToList(); - } - else - { - if (SelectedItems.Count == 0) - { - return false; - } - var first = SelectedItems.OfType().FirstOrDefault(); - if (first != null && first.IsEditing == true) - { - return false; - } - itemsToRemove = SelectedItems.OfType().ToList(); - } - - List connectionsToAlsoRemove = new List(); - - foreach (var connector in Items.OfType()) - { - if (ItemsToDeleteHasConnector(itemsToRemove, connector.SourceConnectorInfo)) - { - connectionsToAlsoRemove.Add(connector); - } - - if (ItemsToDeleteHasConnector(itemsToRemove, connector.SinkConnectorInfo)) - { - connectionsToAlsoRemove.Add(connector); - } - - } - itemsToRemove.AddRange(connectionsToAlsoRemove); - - RemoveItemCommand.Execute(itemsToRemove); - - return true; - } - #endregion + #endregion #region 移动 private void ExecuteLeftMoveCommand(object parameter) @@ -2387,7 +2392,6 @@ namespace AIStudio.Wpf.DiagramDesigner #endregion #region 大小 - private void ExecuteSameSizeCommand(object parameter) { if (parameter is DesignerItemViewModelBase designerItem) @@ -2600,6 +2604,7 @@ namespace AIStudio.Wpf.DiagramDesigner } #endregion + #region 锁定与解锁,待完善 private void ExecuteLockCommand(object parameter) { @@ -2609,7 +2614,9 @@ namespace AIStudio.Wpf.DiagramDesigner { } + #endregion + #region 搜索与编辑 protected virtual void ExecuteEditCommand(object parameter) { if (parameter is SelectableDesignerItemViewModelBase designerItem) @@ -2624,7 +2631,6 @@ namespace AIStudio.Wpf.DiagramDesigner } - private void ExecutedSearchUpCommand(object obj) { if (obj != null) @@ -2706,5 +2712,6 @@ namespace AIStudio.Wpf.DiagramDesigner SearchInfo = null; } } + #endregion } } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs index 8f79a83..9e6ecfc 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs @@ -13,7 +13,7 @@ namespace AIStudio.Wpf.DiagramDesigner public interface ISelectItems { - SimpleCommand SelectItemCommand + ICommand SelectItemCommand { get; } @@ -64,7 +64,7 @@ namespace AIStudio.Wpf.DiagramDesigner return true; } - public SimpleCommand SelectItemCommand + public ICommand SelectItemCommand { get; private set; } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/GifImageItemViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/GifImageItemViewModel.cs index c702b5f..8faad8d 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/GifImageItemViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/GifImageItemViewModel.cs @@ -84,12 +84,12 @@ namespace AIStudio.Wpf.DiagramDesigner } } - public SimpleCommand AddItemCommand + public ICommand AddItemCommand { get; private set; } - public SimpleCommand ImageSwitchCommand + public ICommand ImageSwitchCommand { get; private set; } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/ImageItemViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/ImageItemViewModel.cs index 0981de3..fe66fab 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/ImageItemViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/ImageItemViewModel.cs @@ -141,8 +141,8 @@ namespace AIStudio.Wpf.DiagramDesigner menuOptions.Add(menuItem); } - private SimpleCommand _menuItemCommand; - public SimpleCommand MenuItemCommand + private ICommand _menuItemCommand; + public ICommand MenuItemCommand { get { diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/LogicalGateItemViewModelBase.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/LogicalGateItemViewModelBase.cs index 612880a..64fb6a1 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/LogicalGateItemViewModelBase.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/LogicalGateItemViewModelBase.cs @@ -4,6 +4,7 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Input; using System.Windows.Media; using AIStudio.Wpf.DiagramDesigner.Models; @@ -11,8 +12,8 @@ namespace AIStudio.Wpf.DiagramDesigner { public abstract class LogicalGateItemViewModelBase : DesignerItemViewModelBase { - public SimpleCommand AddInputCommand { get; private set; } - public SimpleCommand AddOutputCommand { get; private set; } + public ICommand AddInputCommand { get; private set; } + public ICommand AddOutputCommand { get; private set; } public LogicalGateItemViewModelBase(LogicalType logicalType) : this(null, logicalType) diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/MediaItemViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/MediaItemViewModel.cs index 5d52776..9a163d1 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/MediaItemViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/MediaItemViewModel.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; +using System.Windows.Input; using AIStudio.Wpf.DiagramDesigner.Models; namespace AIStudio.Wpf.DiagramDesigner @@ -69,8 +70,8 @@ namespace AIStudio.Wpf.DiagramDesigner menuOptions.Add(menuItem); } - private SimpleCommand _menuItemCommand; - public SimpleCommand MenuItemCommand + private ICommand _menuItemCommand; + public ICommand MenuItemCommand { get { diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/ShapeDesignerItemViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/ShapeDesignerItemViewModel.cs index 0076f1e..4cdab77 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/ShapeDesignerItemViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/ShapeDesignerItemViewModel.cs @@ -4,6 +4,7 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Windows; +using System.Windows.Input; using System.Windows.Media; using System.Windows.Shapes; @@ -75,7 +76,7 @@ namespace AIStudio.Wpf.DiagramDesigner } } - public SimpleCommand MenuItemCommand + public ICommand MenuItemCommand { get; private set; } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs index a052444..5acaa18 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs @@ -31,190 +31,198 @@ namespace AIStudio.Wpf.DiagramDesigner get; } - SimpleCommand CreateNewDiagramCommand + ICommand CreateNewDiagramCommand { get; } - SimpleCommand DirectAddItemCommand + ICommand DirectAddItemCommand { get; } - SimpleCommand AddItemCommand + ICommand AddItemCommand { get; } - SimpleCommand RemoveItemCommand + ICommand RemoveItemCommand { get; } - SimpleCommand DirectRemoveItemCommand + ICommand DirectRemoveItemCommand { get; } - SimpleCommand ClearSelectedItemsCommand + ICommand ClearSelectedItemsCommand { get; } - SimpleCommand AlignTopCommand + ICommand AlignTopCommand { get; } - SimpleCommand AlignVerticalCentersCommand + ICommand AlignVerticalCentersCommand { get; } - SimpleCommand AlignBottomCommand + ICommand AlignBottomCommand { get; } - SimpleCommand AlignLeftCommand + ICommand AlignLeftCommand { get; } - SimpleCommand AlignHorizontalCentersCommand + ICommand AlignHorizontalCentersCommand { get; } - SimpleCommand AlignRightCommand + ICommand AlignRightCommand { get; } - SimpleCommand BringForwardCommand + ICommand BringForwardCommand { get; } - SimpleCommand BringToFrontCommand + ICommand BringToFrontCommand { get; } - SimpleCommand SendBackwardCommand + ICommand SendBackwardCommand { get; } - SimpleCommand SendToBackCommand + ICommand SendToBackCommand { get; } - SimpleCommand DistributeHorizontalCommand + ICommand DistributeHorizontalCommand { get; } - SimpleCommand DistributeVerticalCommand + ICommand DistributeVerticalCommand { get; } - SimpleCommand SelectAllCommand + ICommand SelectAllCommand { get; } - SimpleCommand SelectInverseCommand + ICommand SelectInverseCommand { get; } - SimpleCommand SelectItemCommand + ICommand SelectItemCommand { get; } - SimpleCommand CopyCommand + ICommand CopyCommand { get; } - SimpleCommand PasteCommand + ICommand PasteCommand { get; } - SimpleCommand CutCommand + ICommand CutCommand { get; } - SimpleCommand DeleteCommand + ICommand DeleteCommand { get; } - SimpleCommand LeftMoveCommand + ICommand LeftMoveCommand { get; } - SimpleCommand RightMoveCommand + ICommand RightMoveCommand { get; } - SimpleCommand UpMoveCommand + ICommand UpMoveCommand { get; } - SimpleCommand DownMoveCommand + ICommand DownMoveCommand { get; } - SimpleCommand CenterMoveCommand + ICommand CenterMoveCommand { get; } - SimpleCommand SameSizeCommand + ICommand SameSizeCommand { get; } - SimpleCommand SameWidthCommand + ICommand SameWidthCommand { get; } - SimpleCommand SameHeightCommand + ICommand SameHeightCommand { get; } - SimpleCommand SameAngleCommand + ICommand SameAngleCommand { get; } - SimpleCommand GroupCommand + ICommand FitAutoCommand { get; } - SimpleCommand UngroupCommand + ICommand FitWidthCommand { get; } - SimpleCommand LockCommand + ICommand FitHeightCommand { get; } - SimpleCommand UnlockCommand + ICommand GroupCommand { get; } - - SimpleCommand EditCommand + ICommand UngroupCommand { get; } - - SimpleCommand UndoCommand + ICommand LockCommand { get; } - SimpleCommand RedoCommand + ICommand UnlockCommand { get; } - - SimpleCommand ResetLayoutCommand + ICommand EditCommand + { + get; + } + ICommand UndoCommand + { + get; + } + ICommand RedoCommand + { + get; + } + ICommand ResetLayoutCommand + { + get; + } + ICommand SearchDownCommand + { + get; + } + ICommand SearchUpCommand { get; } event DiagramEventHandler Event; - Func OutAddVerify - { - get; set; - } - //void ClearSelectedItems(); - //bool BelongToSameGroup(IGroupable item1, IGroupable item2); - //Rectangle GetBoundingRectangle(IEnumerable items); - //void UpdateZIndex(); - bool IsReadOnly { get; set; diff --git a/AIStudio.Wpf.Mind/Controls/ToolBoxControl.xaml b/AIStudio.Wpf.Mind/Controls/ToolBoxControl.xaml index 3547bc8..549654b 100644 --- a/AIStudio.Wpf.Mind/Controls/ToolBoxControl.xaml +++ b/AIStudio.Wpf.Mind/Controls/ToolBoxControl.xaml @@ -79,7 +79,12 @@ 插入同级主题 - + @@ -611,7 +616,7 @@ - + diff --git a/AIStudio.Wpf.Mind/ViewModels/IMindDiagramViewModel.cs b/AIStudio.Wpf.Mind/ViewModels/IMindDiagramViewModel.cs index 413525d..beb979a 100644 --- a/AIStudio.Wpf.Mind/ViewModels/IMindDiagramViewModel.cs +++ b/AIStudio.Wpf.Mind/ViewModels/IMindDiagramViewModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Input; using AIStudio.Wpf.DiagramDesigner; using AIStudio.Wpf.Mind.Helpers; @@ -20,67 +21,111 @@ namespace AIStudio.Wpf.Mind.ViewModels get; set; } - MindNode RootItem + List RootItems { get; } - - SimpleCommand AddParentCommand + ICommand AddRootCommand { get; } - - SimpleCommand AddChildCommand + ICommand AddParentCommand { get; } - - SimpleCommand AddPearCommand + ICommand AddChildCommand { get; } - - SimpleCommand MoveForwardCommand + ICommand AddPearCommand { get; } - - SimpleCommand MoveBackCommand + ICommand MoveForwardCommand { get; } - - SimpleCommand ChangeMindTypeCommand + ICommand MoveBackCommand { get; } - - SimpleCommand ChangeMindThemeCommand + ICommand SelectBrotherCommand { get; } - - SimpleCommand SelectBrotherCommand + ICommand SelectPearCommand { get; } - - SimpleCommand SelectPearCommand + ICommand SelectRouteCommand { get; } - - SimpleCommand SelectRouteCommand + ICommand SelectChildCommand { get; } - - SimpleCommand SelectChildCommand + ICommand AddLinkCommand { get; } - - SimpleCommand Expand2LevelCommand + ICommand RemoveLinkCommand + { + get; + } + ICommand AddImageCommand + { + get; + } + ICommand RemoveImageCommand + { + get; + } + ICommand AddRemarkCommand + { + get; + } + ICommand RemoveRemarkCommand + { + get; + } + ICommand AddPriorityCommand + { + get; + } + ICommand AddRatioCommand + { + get; + } + ICommand AddTagCommand + { + get; + } + ICommand RemoveTagCommand + { + get; + } + ICommand ChangeMindTypeCommand + { + get; + } + ICommand ChangeMindThemeCommand + { + get; + } + ICommand ClearThemeCommand + { + get; + } + ICommand CopyThemeCommand + { + get; + } + ICommand PasteThemeCommand + { + get; + } + ICommand Expand2LevelCommand { get; } diff --git a/AIStudio.Wpf.Mind/ViewModels/MindDiagramViewModel.cs b/AIStudio.Wpf.Mind/ViewModels/MindDiagramViewModel.cs index fe21138..7d56415 100644 --- a/AIStudio.Wpf.Mind/ViewModels/MindDiagramViewModel.cs +++ b/AIStudio.Wpf.Mind/ViewModels/MindDiagramViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Windows.Input; using System.Windows.Media; using AIStudio.Wpf.DiagramDesigner; using AIStudio.Wpf.Mind.Helpers; @@ -38,11 +39,11 @@ namespace AIStudio.Wpf.Mind.ViewModels SetProperty(ref _mindThemeModel, value); } } - public MindNode RootItem + public List RootItems { get { - return Items.OfType().FirstOrDefault(); + return Items.OfType().Where(p => p.NodeLevel == 0).ToList(); } } @@ -52,21 +53,30 @@ namespace AIStudio.Wpf.Mind.ViewModels { return SelectedItem as MindNode; } - } + } #endregion - #region 命令 - private SimpleCommand _addParentCommand; - public SimpleCommand AddParentCommand + #region 命令 + private ICommand _addRootCommand; + public ICommand AddRootCommand { get { - return this._addParentCommand ?? (this._addParentCommand = new SimpleCommand(MindLevelEnable, ExecuteAddParentCommand)); + return this._addRootCommand ?? (this._addRootCommand = new SimpleCommand(ExecuteEnable, this.ExecuteAddRootCommand)); } } - private SimpleCommand _addChildCommand; - public SimpleCommand AddChildCommand + private ICommand _addParentCommand; + public ICommand AddParentCommand + { + get + { + return this._addParentCommand ?? (this._addParentCommand = new SimpleCommand(MindLevelEnable, this.ExecuteAddParentCommand)); + } + } + + private ICommand _addChildCommand; + public ICommand AddChildCommand { get { @@ -74,8 +84,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _AddPearCommand; - public SimpleCommand AddPearCommand + private ICommand _AddPearCommand; + public ICommand AddPearCommand { get { @@ -83,8 +93,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _moveForwardCommand; - public SimpleCommand MoveForwardCommand + private ICommand _moveForwardCommand; + public ICommand MoveForwardCommand { get { @@ -92,8 +102,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _moveBackCommand; - public SimpleCommand MoveBackCommand + private ICommand _moveBackCommand; + public ICommand MoveBackCommand { get { @@ -101,8 +111,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _deleteCommand; - public override SimpleCommand DeleteCommand + private ICommand _deleteCommand; + public override ICommand DeleteCommand { get { @@ -110,8 +120,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _selectBrotherCommand; - public SimpleCommand SelectBrotherCommand + private ICommand _selectBrotherCommand; + public ICommand SelectBrotherCommand { get { @@ -119,8 +129,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _selectPearCommand; - public SimpleCommand SelectPearCommand + private ICommand _selectPearCommand; + public ICommand SelectPearCommand { get { @@ -128,8 +138,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _selectRouteCommand; - public SimpleCommand SelectRouteCommand + private ICommand _selectRouteCommand; + public ICommand SelectRouteCommand { get { @@ -137,8 +147,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _selectChildCommand; - public SimpleCommand SelectChildCommand + private ICommand _selectChildCommand; + public ICommand SelectChildCommand { get { @@ -146,8 +156,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _addLinkCommand; - public SimpleCommand AddLinkCommand + private ICommand _addLinkCommand; + public ICommand AddLinkCommand { get { @@ -155,8 +165,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _removeLinkCommand; - public SimpleCommand RemoveLinkCommand + private ICommand _removeLinkCommand; + public ICommand RemoveLinkCommand { get { @@ -164,8 +174,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _addImageCommand; - public SimpleCommand AddImageCommand + private ICommand _addImageCommand; + public ICommand AddImageCommand { get { @@ -173,8 +183,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _removeImageCommand; - public SimpleCommand RemoveImageCommand + private ICommand _removeImageCommand; + public ICommand RemoveImageCommand { get { @@ -182,8 +192,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _addRemarkCommand; - public SimpleCommand AddRemarkCommand + private ICommand _addRemarkCommand; + public ICommand AddRemarkCommand { get { @@ -191,8 +201,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _removeRemarkCommand; - public SimpleCommand RemoveRemarkCommand + private ICommand _removeRemarkCommand; + public ICommand RemoveRemarkCommand { get { @@ -200,8 +210,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _addPriorityCommand; - public SimpleCommand AddPriorityCommand + private ICommand _addPriorityCommand; + public ICommand AddPriorityCommand { get { @@ -209,8 +219,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _addRatioCommand; - public SimpleCommand AddRatioCommand + private ICommand _addRatioCommand; + public ICommand AddRatioCommand { get { @@ -218,8 +228,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _addTagCommand; - public SimpleCommand AddTagCommand + private ICommand _addTagCommand; + public ICommand AddTagCommand { get { @@ -227,8 +237,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _removeTagCommand; - public SimpleCommand RemoveTagCommand + private ICommand _removeTagCommand; + public ICommand RemoveTagCommand { get { @@ -236,8 +246,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _changeMindTypeCommand; - public SimpleCommand ChangeMindTypeCommand + private ICommand _changeMindTypeCommand; + public ICommand ChangeMindTypeCommand { get { @@ -245,8 +255,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _changeMindThemeCommand; - public SimpleCommand ChangeMindThemeCommand + private ICommand _changeMindThemeCommand; + public ICommand ChangeMindThemeCommand { get { @@ -254,8 +264,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _clearThemeCommand; - public SimpleCommand ClearThemeCommand + private ICommand _clearThemeCommand; + public ICommand ClearThemeCommand { get { @@ -263,8 +273,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _copyThemeCommand; - public SimpleCommand CopyThemeCommand + private ICommand _copyThemeCommand; + public ICommand CopyThemeCommand { get { @@ -272,8 +282,8 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _pasteThemeCommand; - public SimpleCommand PasteThemeCommand + private ICommand _pasteThemeCommand; + public ICommand PasteThemeCommand { get { @@ -281,16 +291,17 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _expand2LevelCommand; - public SimpleCommand Expand2LevelCommand + private ICommand _expand2LevelCommand; + public ICommand Expand2LevelCommand { get { return this._expand2LevelCommand ?? (this._expand2LevelCommand = new SimpleCommand(ExecuteEnable, this.ExecutedExpand2LevelCommand)); } - } + } #endregion + #region ctor和初始化 public MindDiagramViewModel() { @@ -302,13 +313,14 @@ namespace AIStudio.Wpf.Mind.ViewModels { InitRootItem(); } - ResetChildren(RootItem); - RootItem?.LayoutUpdated(); + ResetChildren(RootItems); + RootItems?.ForEach(p => p.LayoutUpdated()); base.Init(); } public void InitRootItem() { + ClearSelectedItemsCommand.Execute(null); MindNode level1node = new MindNode(this) { Root = this, Id = Guid.NewGuid(), Text = "思维导图" }; level1node.InitLayout(true); Items.Add(level1node); @@ -317,6 +329,61 @@ namespace AIStudio.Wpf.Mind.ViewModels CenterMoveCommand.Execute(level1node); } + protected override void ExecutedResetLayoutCommand(object obj) + { + foreach (var item in Items.OfType()) + { + item.Offset = new DiagramDesigner.Geometrys.PointBase(); + } + + RootItems?.ForEach(p => p.LayoutUpdated()); + } + + private void ResetChildren(IEnumerable parents) + { + if (parents == null) + return; + + foreach (var parent in parents) + { + parent.Children = new System.Collections.ObjectModel.ObservableCollection(Items.OfType().Where(p => p.ParentId == parent.Id)); + foreach (var item in Items.OfType().Where(p => p.ParentId == parent.Id)) + { + item.Parent = parent; + item.InitLayout(false); + item.InitConnectLayout(); + } + ResetChildren(parent.Children); + } + } + + private List GetParent(MindNode node) + { + List mindnode = new List(); + while (node.ParentNode != null) + { + mindnode.Add(node.ParentNode); + node = node.ParentNode; + } + return mindnode; + } + + private List GetChildren(MindNode parent) + { + List mindnode = new List(); + if (parent.Children != null) + { + foreach (var child in parent.Children) + { + mindnode.Add(child); + mindnode.AddRange(GetChildren(child)); + } + } + return mindnode; + } + #endregion + + #region 命令使能 public bool MindExecuteEnable(object para) { if (ExecuteEnable(para) == false) return false; @@ -332,8 +399,14 @@ namespace AIStudio.Wpf.Mind.ViewModels return (SelectedItem as MindNode).NodeLevel != 0; } + #endregion + + #region 新增,删除 + public void ExecuteAddRootCommand(object parameter) + { + InitRootItem(); + } - #region 添加删除 public void ExecuteAddChildCommand(object parameter) { List items = new List(); @@ -561,25 +634,30 @@ namespace AIStudio.Wpf.Mind.ViewModels return false; } - nodes = nodes.Except(new List { RootItem }).ToList(); - if (nodes.Any()) { - Dictionary indexs = nodes.ToDictionary(p => p, p => p.ParentNode.Children.IndexOf(p)); + Dictionary indexs = nodes.ToDictionary(p => p, p => p.ParentNode != null ? p.ParentNode.Children.IndexOf(p) : 0); DoCommandManager.DoNewCommand(this.ToString(), () => { foreach (var node in nodes) { - node.ParentNode.RemoveChild(node, true); + if (node.NodeLevel == 0) + { + DirectRemoveItemCommand.Execute(node); + } + else + { + node.ParentNode?.RemoveChild(node, true); + } } - RootItem.LayoutUpdated(); + RootItems.ForEach(p => p.LayoutUpdated()); }, () => { foreach (var node in nodes) { node.ParentNode.AddChild(node, indexs[node]); } - RootItem.LayoutUpdated(); + RootItems.ForEach(p => p.LayoutUpdated()); }); return true; } @@ -588,20 +666,39 @@ namespace AIStudio.Wpf.Mind.ViewModels } #endregion + #region 复制,粘贴 + protected override void FixConnection(List items) + { + List parents = new List(); + foreach (var item in items.OfType()) + { + var parent = Items.OfType().FirstOrDefault(p => p.Id == item.ParentId); + if (parent != null) + { + parents.Add(parent); + } + else + { + parents.Add(item); + } + } + ResetChildren(parents); + } + #endregion + #region 附加信息 private void ExecuteAddLinkCommand(object obj) { if (obj is object[] array && array.Length == 2) { - SelectedItems.OfType().ToList().ForEach(p => - { + SelectedItems.OfType().ToList().ForEach(p => { if (p.LinkInfo == null) p.LinkInfo = new LinkInfo(); p.LinkInfo.Link = array[0]?.ToString(); p.LinkInfo.Text = array[1]?.ToString(); - - }); + + }); } } @@ -610,7 +707,7 @@ namespace AIStudio.Wpf.Mind.ViewModels SelectedItems.OfType().ToList().ForEach(p => { if (p.LinkInfo != null) { - p.LinkInfo.Link = null; + p.LinkInfo.Link = null; p.LinkInfo.Text = null; } }); @@ -698,7 +795,7 @@ namespace AIStudio.Wpf.Mind.ViewModels { Items.OfType().ToList().ForEach(item => { item.InitLayout(true); }); Items.OfType().ToList().ForEach(item => { item.InitConnectLayout(); }); - RootItem?.LayoutUpdated(); + RootItems?.ForEach(p => p.LayoutUpdated()); } } @@ -716,7 +813,6 @@ namespace AIStudio.Wpf.Mind.ViewModels PageBackground = Colors.White; } Items.OfType().ToList().ForEach(item => { item.ThemeChange(); }); - RootItem?.LayoutUpdated(); } } @@ -744,7 +840,6 @@ namespace AIStudio.Wpf.Mind.ViewModels { node.ThemeChange(); } - RootItem.LayoutUpdated(); }, () => { //ToDo @@ -797,13 +892,12 @@ namespace AIStudio.Wpf.Mind.ViewModels CopyHelper.CopyPropertyValue(_formatNode.ColorViewModel, node.ColorViewModel); CopyHelper.CopyPropertyValue(_formatNode.FontViewModel, node.FontViewModel); } - RootItem.LayoutUpdated(); }, () => { //ToDo }); } - + } } @@ -812,10 +906,14 @@ namespace AIStudio.Wpf.Mind.ViewModels #region 操作 protected override void ExecuteCenterMoveCommand(object parameter) { - RootItem.Left = (PageSize.Width - RootItem.ItemWidth) / 2; - RootItem.Top = (PageSize.Height - RootItem.ItemHeight) / 2; - RootItem?.LayoutUpdated(); - FitViewModel = new FitViewModel() { BoundingRect = RootItem.GetBounds() }; + var rootitem = MindSelectedItem?.RootNode; + if (rootitem != null) + { + rootitem.Left = (PageSize.Width - rootitem.ItemWidth) / 2; + rootitem.Top = (PageSize.Height - rootitem.ItemHeight) / 2; + rootitem?.LayoutUpdated(); + FitViewModel = new FitViewModel() { BoundingRect = rootitem.GetBounds() }; + } } private void ExecutedExpand2LevelCommand(object obj) @@ -914,55 +1012,6 @@ namespace AIStudio.Wpf.Mind.ViewModels } #endregion - #region 初始化 - protected override void ExecutedResetLayoutCommand(object obj) - { - foreach (var item in Items.OfType()) - { - item.Offset = new DiagramDesigner.Geometrys.PointBase(); - } - RootItem?.LayoutUpdated(); - } - private void ResetChildren(MindNode parent) - { - if (parent == null) - return; - - parent.Children = new System.Collections.ObjectModel.ObservableCollection(Items.OfType().Where(p => p.ParentId == parent.Id)); - foreach (var item in Items.OfType().Where(p => p.ParentId == parent.Id)) - { - item.Parent = parent; - item.InitLayout(false); - item.InitConnectLayout(); - ResetChildren(item); - } - } - - private List GetParent(MindNode node) - { - List mindnode = new List(); - while (node.ParentNode != null) - { - mindnode.Add(node.ParentNode); - node = node.ParentNode; - } - return mindnode; - } - - private List GetChildren(MindNode parent) - { - List mindnode = new List(); - if (parent.Children != null) - { - foreach (var child in parent.Children) - { - mindnode.Add(child); - mindnode.AddRange(GetChildren(child)); - } - } - return mindnode; - } - #endregion } } diff --git a/AIStudio.Wpf.Mind/ViewModels/MindNode.cs b/AIStudio.Wpf.Mind/ViewModels/MindNode.cs index 0bf44e9..95598c2 100644 --- a/AIStudio.Wpf.Mind/ViewModels/MindNode.cs +++ b/AIStudio.Wpf.Mind/ViewModels/MindNode.cs @@ -8,6 +8,7 @@ using System.Security.Policy; using System.Text; using System.Windows; using System.Windows.Controls; +using System.Windows.Input; using System.Windows.Media; using System.Xml.Linq; using AIStudio.Wpf.DiagramDesigner; @@ -75,7 +76,7 @@ namespace AIStudio.Wpf.Mind.ViewModels var layout = GlobalType.AllTypes.Where(p => typeof(IMindLayout).IsAssignableFrom(p)).FirstOrDefault(p => p.Name == MindType.ToString() + "Layout"); MindLayout = layout != null ? (System.Activator.CreateInstance(layout) as IMindLayout) : new MindLayout(); - IsInnerConnector = true; + IsInnerConnector = true; MindLayout.Appearance(this, MindThemeModel, initAppearance); this.PropertyChanged -= this.Item_PropertyChanged; @@ -139,7 +140,14 @@ namespace AIStudio.Wpf.Mind.ViewModels { return Parent as MindNode; } + } + public MindNode RootNode + { + get + { + return GetLevel1Node(); + } } public int NodeLevel @@ -346,7 +354,7 @@ namespace AIStudio.Wpf.Mind.ViewModels if (_tags != null) { _tags.CollectionChanged += _tags_CollectionChanged; - } + } } } @@ -373,32 +381,32 @@ namespace AIStudio.Wpf.Mind.ViewModels #endregion #region 命令 - public SimpleCommand AddParentCommand + public ICommand AddParentCommand { get; private set; } - public SimpleCommand AddChildCommand + public ICommand AddChildCommand { get; private set; } - public SimpleCommand AddPearCommand + public ICommand AddPearCommand { get; private set; } - public SimpleCommand DeleteCommand + public ICommand DeleteCommand { get; private set; } - public SimpleCommand MoveForwardCommand + public ICommand MoveForwardCommand { get; private set; } - public SimpleCommand MoveBackCommand + public ICommand MoveBackCommand { get; private set; } @@ -490,9 +498,10 @@ namespace AIStudio.Wpf.Mind.ViewModels public void InitConnectLayout() { var connector = Root?.Items.OfType().Where(p => p.IsFullConnection).FirstOrDefault(p => p.SinkConnectorInfoFully.DataItem == this); - if (connector != null) + var newconnecter = MindLayout?.GetOrSetConnectionViewModel(connector.SourceConnectorInfo.DataItem as MindNode, connector.SinkConnectorInfoFully.DataItem as MindNode, connector); + if (connector == null) { - MindLayout?.GetOrSetConnectionViewModel(connector.SourceConnectorInfo.DataItem as MindNode, connector.SinkConnectorInfoFully.DataItem as MindNode, connector); + Root?.DirectAddItemCommand.Execute(new SelectableDesignerItemViewModelBase[] { newconnecter }); } } #endregion @@ -541,7 +550,7 @@ namespace AIStudio.Wpf.Mind.ViewModels break; } case nameof(Rate): - case nameof(Priority): + case nameof(Priority): case nameof(Remark): case nameof(LinkInfo.Link): {