Files
aistudio-wpf-diagram/Extensions/AIStudio.Wpf.Mind/ViewModels/MindDiagramViewModel.cs

1498 lines
50 KiB
C#
Raw Normal View History

2023-03-05 21:30:53 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
2023-04-02 21:47:55 +08:00
using System.Text.RegularExpressions;
2023-03-24 22:32:42 +08:00
using System.Windows.Input;
2023-03-11 22:27:23 +08:00
using System.Windows.Media;
2023-03-05 21:30:53 +08:00
using AIStudio.Wpf.DiagramDesigner;
2023-03-25 22:10:49 +08:00
using AIStudio.Wpf.DiagramDesigner.Geometrys;
2023-04-02 21:47:55 +08:00
using AIStudio.Wpf.Mind.Controls;
2023-03-11 22:27:23 +08:00
using AIStudio.Wpf.Mind.Helpers;
2023-04-02 12:01:46 +08:00
using AIStudio.Wpf.Mind.Models;
2023-03-05 21:30:53 +08:00
namespace AIStudio.Wpf.Mind.ViewModels
{
public class MindDiagramViewModel : DiagramViewModel, IMindDiagramViewModel
{
#region
2023-04-02 12:01:46 +08:00
private MindType _mindType = MindType.Mind;
2023-03-05 21:30:53 +08:00
public MindType MindType
{
get
{
return _mindType;
}
set
{
SetProperty(ref _mindType, value);
2023-03-05 21:30:53 +08:00
}
}
2023-03-05 23:22:34 +08:00
2023-04-02 12:01:46 +08:00
private MindTheme _mindTheme;
public MindTheme MindTheme
2023-03-11 22:27:23 +08:00
{
get
{
2023-04-02 12:01:46 +08:00
return _mindTheme;
2023-03-11 22:27:23 +08:00
}
set
{
SetProperty(ref _mindTheme, value);
2023-03-11 22:27:23 +08:00
}
}
2023-04-02 12:01:46 +08:00
2023-03-24 22:32:42 +08:00
public List<MindNode> RootItems
2023-03-05 23:22:34 +08:00
{
get
{
2023-03-24 22:32:42 +08:00
return Items.OfType<MindNode>().Where(p => p.NodeLevel == 0).ToList();
2023-03-05 23:22:34 +08:00
}
}
2023-03-19 23:26:14 +08:00
public MindNode MindSelectedItem
{
get
{
return SelectedItem as MindNode;
}
2023-03-24 22:32:42 +08:00
}
2023-03-26 23:23:34 +08:00
2023-04-02 12:01:46 +08:00
public List<MindNode> MindSelectedItems
{
get
{
return SelectedItems.OfType<MindNode>().ToList();
}
}
2023-03-26 23:23:34 +08:00
private LinkInfo _linkInfo = new LinkInfo();
public LinkInfo LinkInfo
{
get
{
return _linkInfo;
}
set
{
SetProperty(ref _linkInfo, value);
}
}
private ImageInfo _imageInfo = new ImageInfo();
public ImageInfo ImageInfo
{
get
{
return _imageInfo;
}
set
{
SetProperty(ref _imageInfo, value);
}
}
private string _remark;
public string Remark
{
get
{
return _remark;
}
set
{
SetProperty(ref _remark, value);
}
}
2023-03-05 21:30:53 +08:00
#endregion
2023-03-24 22:32:42 +08:00
#region
private ICommand _addRootCommand;
public ICommand AddRootCommand
{
get
{
return this._addRootCommand ?? (this._addRootCommand = new SimpleCommand(ExecuteEnable, this.ExecuteAddRootCommand));
}
}
private ICommand _addParentCommand;
public ICommand AddParentCommand
2023-03-05 21:30:53 +08:00
{
2023-03-06 11:54:41 +08:00
get
{
2023-03-24 22:32:42 +08:00
return this._addParentCommand ?? (this._addParentCommand = new SimpleCommand(MindLevelEnable, this.ExecuteAddParentCommand));
2023-03-06 11:54:41 +08:00
}
2023-03-05 21:30:53 +08:00
}
2023-03-24 22:32:42 +08:00
private ICommand _addChildCommand;
public ICommand AddChildCommand
2023-03-05 21:30:53 +08:00
{
2023-03-06 11:54:41 +08:00
get
{
return this._addChildCommand ?? (this._addChildCommand = new SimpleCommand(MindExecuteEnable, this.ExecuteAddChildCommand));
}
2023-03-05 21:30:53 +08:00
}
2023-03-24 22:32:42 +08:00
private ICommand _AddPearCommand;
public ICommand AddPearCommand
2023-03-05 21:30:53 +08:00
{
2023-03-06 11:54:41 +08:00
get
{
2023-03-11 22:27:23 +08:00
return this._AddPearCommand ?? (this._AddPearCommand = new SimpleCommand(MindLevelEnable, this.ExecuteAddPearCommand));
2023-03-06 11:54:41 +08:00
}
2023-03-05 21:30:53 +08:00
}
2023-03-24 22:32:42 +08:00
private ICommand _moveForwardCommand;
public ICommand MoveForwardCommand
2023-03-05 21:30:53 +08:00
{
2023-03-06 11:54:41 +08:00
get
{
return this._moveForwardCommand ?? (this._moveForwardCommand = new SimpleCommand(MindExecuteEnable, ExecuteMoveForwardCommand));
}
2023-03-05 21:30:53 +08:00
}
2023-03-24 22:32:42 +08:00
private ICommand _moveBackCommand;
public ICommand MoveBackCommand
2023-03-05 21:30:53 +08:00
{
2023-03-06 11:54:41 +08:00
get
{
return this._moveBackCommand ?? (this._moveBackCommand = new SimpleCommand(MindExecuteEnable, ExecuteMoveBackCommand));
}
2023-03-05 21:30:53 +08:00
}
2023-04-02 21:47:55 +08:00
private ICommand _exportCommand;
public ICommand ExportCommand
{
get
{
return this._exportCommand ?? (this._exportCommand = new SimpleCommand(MindExecuteEnable, ExecuteExportCommand));
}
}
private ICommand _importCommand;
public ICommand ImportCommand
{
get
{
return this._importCommand ?? (this._importCommand = new SimpleCommand(MindExecuteEnable, ExecuteImportCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _selectBrotherCommand;
public ICommand SelectBrotherCommand
2023-03-11 22:27:23 +08:00
{
get
{
return this._selectBrotherCommand ?? (this._selectBrotherCommand = new SimpleCommand(MindLevelEnable, ExecuteSelectBrotherCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _selectPearCommand;
public ICommand SelectPearCommand
2023-03-11 22:27:23 +08:00
{
get
{
return this._selectPearCommand ?? (this._selectPearCommand = new SimpleCommand(MindLevelEnable, ExecuteSelectPearCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _selectRouteCommand;
public ICommand SelectRouteCommand
2023-03-11 22:27:23 +08:00
{
get
{
return this._selectRouteCommand ?? (this._selectRouteCommand = new SimpleCommand(MindLevelEnable, ExecuteSelectRouteCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _selectChildCommand;
public ICommand SelectChildCommand
2023-03-11 22:27:23 +08:00
{
get
{
return this._selectChildCommand ?? (this._selectChildCommand = new SimpleCommand(MindLevelEnable, ExecuteSelectChildCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _addLinkCommand;
public ICommand AddLinkCommand
2023-03-11 12:40:44 +08:00
{
get
{
return this._addLinkCommand ?? (this._addLinkCommand = new SimpleCommand(MindExecuteEnable, ExecuteAddLinkCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _removeLinkCommand;
public ICommand RemoveLinkCommand
2023-03-11 12:40:44 +08:00
{
get
{
return this._removeLinkCommand ?? (this._removeLinkCommand = new SimpleCommand(MindExecuteEnable, ExecuteRemoveLinkCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _addImageCommand;
public ICommand AddImageCommand
2023-03-11 12:40:44 +08:00
{
get
{
return this._addImageCommand ?? (this._addImageCommand = new SimpleCommand(MindExecuteEnable, ExecuteAddImageCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _removeImageCommand;
public ICommand RemoveImageCommand
2023-03-11 12:40:44 +08:00
{
get
{
return this._removeImageCommand ?? (this._removeImageCommand = new SimpleCommand(MindExecuteEnable, ExecuteRemoveImageCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _addRemarkCommand;
public ICommand AddRemarkCommand
2023-03-11 12:40:44 +08:00
{
get
{
return this._addRemarkCommand ?? (this._addRemarkCommand = new SimpleCommand(MindExecuteEnable, ExecuteAddRemarkCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _removeRemarkCommand;
public ICommand RemoveRemarkCommand
2023-03-11 12:40:44 +08:00
{
get
{
return this._removeRemarkCommand ?? (this._removeRemarkCommand = new SimpleCommand(MindExecuteEnable, ExecuteRemoveRemarkCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _addPriorityCommand;
public ICommand AddPriorityCommand
2023-03-11 12:40:44 +08:00
{
get
{
return this._addPriorityCommand ?? (this._addPriorityCommand = new SimpleCommand(MindExecuteEnable, ExecuteAddPriorityCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _addRatioCommand;
public ICommand AddRatioCommand
2023-03-11 12:40:44 +08:00
{
get
{
return this._addRatioCommand ?? (this._addRatioCommand = new SimpleCommand(MindExecuteEnable, ExecuteAddRatioCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _addTagCommand;
public ICommand AddTagCommand
2023-03-11 12:40:44 +08:00
{
get
{
return this._addTagCommand ?? (this._addTagCommand = new SimpleCommand(MindExecuteEnable, ExecuteAddTagCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _removeTagCommand;
public ICommand RemoveTagCommand
2023-03-18 21:44:58 +08:00
{
get
{
return this._removeTagCommand ?? (this._removeTagCommand = new SimpleCommand(MindExecuteEnable, ExecuteRemoveTagCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _clearThemeCommand;
public ICommand ClearThemeCommand
2023-03-11 22:27:23 +08:00
{
get
{
return this._clearThemeCommand ?? (this._clearThemeCommand = new SimpleCommand(ExecuteEnable, this.ExecutedClearThemeCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _copyThemeCommand;
public ICommand CopyThemeCommand
2023-03-11 22:27:23 +08:00
{
get
{
return this._copyThemeCommand ?? (this._copyThemeCommand = new SimpleCommand(ExecuteEnable, this.ExecutedCopyThemeCommand));
}
}
2023-03-24 22:32:42 +08:00
private ICommand _pasteThemeCommand;
public ICommand PasteThemeCommand
2023-03-11 22:27:23 +08:00
{
get
{
return this._pasteThemeCommand ?? (this._pasteThemeCommand = new SimpleCommand(ExecuteEnable, this.ExecutedPasteThemeCommand));
2023-03-06 11:54:41 +08:00
}
2023-03-05 21:30:53 +08:00
}
2023-03-24 22:32:42 +08:00
private ICommand _expand2LevelCommand;
public ICommand Expand2LevelCommand
2023-03-05 21:30:53 +08:00
{
2023-03-06 11:54:41 +08:00
get
{
2023-03-19 12:38:08 +08:00
return this._expand2LevelCommand ?? (this._expand2LevelCommand = new SimpleCommand(ExecuteEnable, this.ExecutedExpand2LevelCommand));
2023-03-06 11:54:41 +08:00
}
2023-03-24 22:32:42 +08:00
}
2023-03-05 21:30:53 +08:00
#endregion
2023-03-24 22:32:42 +08:00
#region ctor和初始化
2023-03-05 21:30:53 +08:00
public MindDiagramViewModel()
2023-03-08 23:02:50 +08:00
{
}
public override void Init(bool initNew)
2023-03-08 23:02:50 +08:00
{
if (initNew)
2023-03-08 23:02:50 +08:00
{
if (Items.Count == 0)
{
AddRootItem();
}
2023-03-08 23:02:50 +08:00
}
2023-03-24 22:32:42 +08:00
ResetChildren(RootItems);
2023-04-02 21:47:55 +08:00
RootItems?.ForEach(p => p.UpdatedLayout());
base.Init(initNew);
2023-03-08 23:02:50 +08:00
}
2023-03-26 23:23:34 +08:00
private MindNode AddRootItem()
2023-03-05 21:30:53 +08:00
{
2023-03-26 23:23:34 +08:00
ClearSelectedItems();
2023-04-02 12:01:46 +08:00
MindNode level1node = new MindNode(this) { Root = this, Id = Guid.NewGuid(), Text = "思维导图", MindType = MindType, MindTheme = MindTheme };
2023-03-05 23:22:34 +08:00
level1node.InitLayout(true);
Items.Add(level1node);
level1node.IsSelected = true;
2023-03-12 15:26:58 +08:00
2023-03-26 23:23:34 +08:00
Move(level1node, null, null);
return level1node;
2023-03-05 21:30:53 +08:00
}
2023-03-24 22:32:42 +08:00
protected override void ExecutedResetLayoutCommand(object obj)
{
foreach (var item in Items.OfType<MindNode>())
{
item.Offset = new DiagramDesigner.Geometrys.PointBase();
}
2023-04-02 21:47:55 +08:00
RootItems?.ForEach(p => p.UpdatedLayout());
2023-03-24 22:32:42 +08:00
}
private void ResetChildren(IEnumerable<MindNode> parents)
{
if (parents == null)
return;
foreach (var parent in parents)
{
parent.Children = new System.Collections.ObjectModel.ObservableCollection<MindNode>(Items.OfType<MindNode>().Where(p => p.ParentId == parent.Id));
2023-03-25 11:59:31 +08:00
foreach (var item in Items.OfType<MindNode>().Where(p => p.ParentId == parent.Id).ToList())
2023-03-24 22:32:42 +08:00
{
item.Parent = parent;
item.InitLayout(false);
2023-04-02 21:47:55 +08:00
item.InitConnectionLayout();
2023-03-24 22:32:42 +08:00
}
ResetChildren(parent.Children);
}
}
#endregion
#region 使
2023-03-05 21:30:53 +08:00
public bool MindExecuteEnable(object para)
{
if (ExecuteEnable(para) == false) return false;
if (SelectedItem is MindNode) return true;
return false;
}
private bool MindLevelEnable(object obj)
{
if (MindExecuteEnable(obj) == false) return false;
2023-03-05 23:22:34 +08:00
return (SelectedItem as MindNode).NodeLevel != 0;
2023-03-05 21:30:53 +08:00
}
2023-03-24 22:32:42 +08:00
#endregion
#region
protected override void DiagramViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.DiagramViewModel_PropertyChanged(sender, e);
if (e.PropertyName == nameof(MindType))
{
if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs)
{
ChangeMindType((MindType)valuePropertyChangedEventArgs.OldValue, (MindType)valuePropertyChangedEventArgs.NewValue);
}
}
else if (e.PropertyName == nameof(MindTheme))
{
if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs)
{
ChangeMindTheme((MindTheme)valuePropertyChangedEventArgs.OldValue, (MindTheme)valuePropertyChangedEventArgs.NewValue);
}
}
}
2023-03-26 23:23:34 +08:00
protected override void Item_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.Item_PropertyChanged(sender, e);
if (e.PropertyName == "IsSelected")
{
if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs)
{
LinkInfo = new LinkInfo(MindSelectedItem?.LinkInfo);
ImageInfo = new ImageInfo(MindSelectedItem?.ImageInfo);
Remark = MindSelectedItem?.Remark;
_mindType = MindSelectedItem?.MindType ?? RootItems.FirstOrDefault()?.MindType ?? MindType.Mind;
_mindTheme = MindSelectedItem?.MindTheme ?? RootItems.FirstOrDefault()?.MindTheme ?? MindTheme.SkyBlue;
RaisePropertyChanged(nameof(MindType));
RaisePropertyChanged(nameof(MindTheme));
2023-03-26 23:23:34 +08:00
}
}
2023-03-26 23:23:34 +08:00
}
#endregion
2023-03-24 22:32:42 +08:00
#region ,
public void ExecuteAddRootCommand(object parameter)
{
2023-03-26 23:23:34 +08:00
MindNode rootitem = null;
DoCommandManager.DoNewCommand(this.ToString(),
() => {
rootitem = AddRootItem();
},
() => {
if (rootitem != null)
{
Delete(rootitem);
2023-03-26 23:23:34 +08:00
}
});
2023-03-24 22:32:42 +08:00
}
2023-03-05 21:30:53 +08:00
public void ExecuteAddChildCommand(object parameter)
{
List<MindNode> items = new List<MindNode>();
2023-03-26 23:23:34 +08:00
List<MindNode> newitems = new List<MindNode>();
if (parameter is MindNode node)
2023-03-05 21:30:53 +08:00
{
2023-03-26 23:23:34 +08:00
items.Add(node);
2023-03-05 21:30:53 +08:00
}
else if (parameter is IEnumerable<MindNode> para)
{
2023-03-26 23:23:34 +08:00
items.AddRange(para);
2023-03-05 21:30:53 +08:00
}
else
{
2023-03-26 23:23:34 +08:00
items.AddRange(SelectedItems.OfType<MindNode>());
2023-03-05 21:30:53 +08:00
}
DoCommandManager.DoNewCommand(this.ToString(),
() => {
2023-03-26 23:23:34 +08:00
2023-03-05 21:30:53 +08:00
foreach (var item in items)
{
2023-03-26 23:23:34 +08:00
var newitem = new MindNode(this) { Text = $"分支主题{item.Children.Count + 1}" };
newitem.AddTo(item);
newitems.Add(newitem);
2023-03-05 21:30:53 +08:00
}
2023-03-26 23:23:34 +08:00
2023-04-02 21:47:55 +08:00
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
2023-03-05 21:30:53 +08:00
},
() => {
2023-03-26 23:23:34 +08:00
foreach (var item in newitems)
2023-03-05 21:30:53 +08:00
{
2023-03-26 23:23:34 +08:00
item.RemoveFrom();
2023-03-05 21:30:53 +08:00
}
2023-03-26 23:23:34 +08:00
2023-04-02 21:47:55 +08:00
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
2023-03-05 21:30:53 +08:00
});
}
public void ExecuteAddParentCommand(object parameter)
{
List<MindNode> items = new List<MindNode>();
2023-03-26 23:23:34 +08:00
List<MindNode> newitems = new List<MindNode>();
2023-03-05 21:30:53 +08:00
if (parameter is MindNode node)
{
2023-03-26 23:23:34 +08:00
items.Add(node);
2023-03-05 21:30:53 +08:00
}
else if (parameter is IEnumerable<MindNode> para)
{
2023-03-26 23:23:34 +08:00
items.AddRange(para);
2023-03-05 21:30:53 +08:00
}
else
{
2023-03-26 23:23:34 +08:00
items.AddRange(SelectedItems.OfType<MindNode>());
2023-03-25 22:10:49 +08:00
}
2023-03-05 21:30:53 +08:00
2023-03-26 23:23:34 +08:00
DoCommandManager.DoNewCommand(this.ToString(),
() => {
foreach (var item in items)
{
if (item.ParentNode == null)
continue;
2023-03-25 11:59:31 +08:00
2023-03-26 23:23:34 +08:00
int index = item.ParentNode.Children.IndexOf(item);
2023-03-05 21:30:53 +08:00
2023-03-26 23:23:34 +08:00
var newitem = new MindNode(this) { Text = $"分支主题{index + 1}" };
newitem.AddTo(item.ParentNode, index);
item.RemoveFrom();
item.AddTo(newitem, -1, false);
newitems.Add(newitem);
}
2023-03-05 21:30:53 +08:00
2023-04-02 21:47:55 +08:00
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
2023-03-26 23:23:34 +08:00
},
() => {
foreach (var item in items)
{
if (item.ParentNode == null || item.ParentNode.ParentNode == null)
continue;
2023-03-05 21:30:53 +08:00
2023-03-26 23:23:34 +08:00
var parent = item.ParentNode;
int index = item.ParentNode.ParentNode.Children.IndexOf(item.ParentNode);
2023-03-05 21:30:53 +08:00
2023-03-26 23:23:34 +08:00
item.RemoveFrom();
parent.RemoveFrom();
item.AddTo(parent.ParentNode, index);
}
2023-03-05 21:30:53 +08:00
2023-04-02 21:47:55 +08:00
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
2023-03-26 23:23:34 +08:00
});
2023-03-05 21:30:53 +08:00
}
2023-03-11 22:27:23 +08:00
public void ExecuteAddPearCommand(object parameter)
2023-03-05 21:30:53 +08:00
{
List<MindNode> items = new List<MindNode>();
2023-03-26 23:23:34 +08:00
List<MindNode> newitems = new List<MindNode>();
if (parameter is MindNode node)
2023-03-05 21:30:53 +08:00
{
2023-03-26 23:23:34 +08:00
items.Add(node);
2023-03-05 21:30:53 +08:00
}
else if (parameter is IEnumerable<MindNode> para)
{
2023-03-26 23:23:34 +08:00
items.AddRange(para);
2023-03-05 21:30:53 +08:00
}
else
{
2023-03-26 23:23:34 +08:00
items.AddRange(SelectedItems.OfType<MindNode>());
2023-03-05 21:30:53 +08:00
}
2023-03-26 23:23:34 +08:00
DoCommandManager.DoNewCommand(this.ToString(),
() => {
foreach (var item in items)
{
if (item.ParentNode == null)
{
var newitem = new MindNode(this) { Text = $"分支主题{item.Children.Count + 1}" };
newitem.AddTo(item);
newitems.Add(newitem);
}
else
{
int index = item.ParentNode.Children.IndexOf(item);
var newitem = new MindNode(this) { Text = $"分支主题{item.ParentNode.Children.Count + 1}" };
item.IsSelected = false;
newitem.AddTo(item.ParentNode, index + 1);
newitems.Add(newitem);
}
2023-03-26 23:23:34 +08:00
}
2023-04-02 21:47:55 +08:00
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
2023-03-26 23:23:34 +08:00
},
() => {
foreach (var item in newitems)
{
item.RemoveFrom();
2023-04-02 21:47:55 +08:00
item.UpdatedLayout();
2023-03-26 23:23:34 +08:00
}
2023-04-02 21:47:55 +08:00
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
2023-03-26 23:23:34 +08:00
});
2023-03-05 21:30:53 +08:00
}
public override void ExecuteNextCommand(object parameter)
{
ExecuteAddPearCommand(parameter);
}
2023-03-05 21:30:53 +08:00
private void ExecuteMoveBackCommand(object parameter)
{
2023-03-26 23:23:34 +08:00
List<MindNode> items = new List<MindNode>();
2023-03-05 21:30:53 +08:00
if (parameter is MindNode node)
{
2023-03-26 23:23:34 +08:00
items.Add(node);
2023-03-05 21:30:53 +08:00
}
2023-03-26 23:23:34 +08:00
else if (parameter is IEnumerable<MindNode> para)
2023-03-05 21:30:53 +08:00
{
2023-03-26 23:23:34 +08:00
items.AddRange(para);
2023-03-05 21:30:53 +08:00
}
2023-03-26 23:23:34 +08:00
else
2023-03-05 21:30:53 +08:00
{
2023-03-26 23:23:34 +08:00
items.AddRange(SelectedItems.OfType<MindNode>());
2023-03-05 21:30:53 +08:00
}
2023-03-26 23:23:34 +08:00
DoCommandManager.DoNewCommand(this.ToString(),
() => {
MoveBack(items);
},
() => {
MoveForward(items);
});
2023-03-05 21:30:53 +08:00
}
private void ExecuteMoveForwardCommand(object parameter)
{
2023-03-26 23:23:34 +08:00
List<MindNode> items = new List<MindNode>();
List<MindNode> newitems = new List<MindNode>();
2023-03-05 21:30:53 +08:00
if (parameter is MindNode node)
{
2023-03-26 23:23:34 +08:00
items.Add(node);
}
else if (parameter is IEnumerable<MindNode> para)
{
items.AddRange(para);
2023-03-05 21:30:53 +08:00
}
else
{
2023-03-26 23:23:34 +08:00
items.AddRange(SelectedItems.OfType<MindNode>());
2023-03-05 21:30:53 +08:00
}
2023-03-26 23:23:34 +08:00
DoCommandManager.DoNewCommand(this.ToString(),
() => {
MoveForward(items);
},
() => {
MoveBack(items);
});
}
2023-04-02 21:47:55 +08:00
private void ExecuteExportCommand(object parameter)
{
if (parameter is MindNode node)
{
}
else
{
node = SelectedItem as MindNode;
}
if (node != null)
{
var output = node.GetChildrenText(true);
var window = new NodeDTSWindow("导出节点", output);
window.ShowDialog();
}
}
private void ExecuteImportCommand(object parameter)
{
if (parameter is MindNode node)
{
}
else
{
node = SelectedItem as MindNode;
}
if (node != null)
{
var window = new NodeDTSWindow("导入节点", "");
if (window.ShowDialog() == true)
{
List<MindNode> newitems = new List<MindNode>();
DoCommandManager.DoNewCommand(this.ToString(),
() => {
2023-04-02 21:47:55 +08:00
var content = window.ContentString;
var lines = content.Split(new string[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
MindNode lastnode = node;
foreach (var line in lines)
{
int level = Regex.Matches(line, "\t").Count + node.NodeLevel + 1;
string text = line.Replace("\t", "");
var newitem = new MindNode(this) { Text = text };
while (lastnode.NodeLevel != level - 1)
{
lastnode = lastnode.ParentNode;
}
if (lastnode == null)
{
continue;
}
newitem.AddTo(lastnode, isSelected: false);
lastnode = newitem;
newitems.Add(newitem);
}
node.UpdatedLayout();
},
() => {
foreach (var item in newitems)
{
item.RemoveFrom();
}
node.UpdatedLayout();
});
}
}
}
2023-03-26 23:23:34 +08:00
private void MoveBack(List<MindNode> items)
{
foreach (var item in items)
2023-03-05 21:30:53 +08:00
{
2023-03-26 23:23:34 +08:00
if (item.ParentNode == null)
continue;
var parent = item.ParentNode;
int index = parent.Children.IndexOf(item);
if (index < parent.Children.Count - 1)
{
item.RemoveFrom();
item.AddTo(parent, index + 1);
}
2023-03-05 21:30:53 +08:00
}
2023-04-02 21:47:55 +08:00
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
2023-03-26 23:23:34 +08:00
}
private void MoveForward(List<MindNode> items)
{
foreach (var item in items)
{
if (item.ParentNode == null)
continue;
var parent = item.ParentNode;
int index = parent.Children.IndexOf(item);
2023-03-05 21:30:53 +08:00
2023-03-26 23:23:34 +08:00
if (index > 0)
{
item.RemoveFrom();
item.AddTo(parent, index - 1);
}
}
2023-04-02 21:47:55 +08:00
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
2023-03-05 21:30:53 +08:00
}
protected override List<SelectableDesignerItemViewModelBase> Delete(object parameter, bool delete = true, bool direct = true)
2023-03-05 21:30:53 +08:00
{
2023-03-26 23:23:34 +08:00
List<MindNode> items = new List<MindNode>();
2023-03-25 22:10:49 +08:00
List<SelectableDesignerItemViewModelBase> others = new List<SelectableDesignerItemViewModelBase>();
2023-03-26 23:23:34 +08:00
if (parameter is MindNode node)
2023-03-05 21:30:53 +08:00
{
2023-03-26 23:23:34 +08:00
items.Add(node);
2023-03-10 12:09:13 +08:00
}
else if (parameter is IEnumerable<MindNode> para)
{
2023-03-26 23:23:34 +08:00
items.AddRange(para);
2023-03-05 21:30:53 +08:00
}
else
{
2023-03-26 23:23:34 +08:00
items.AddRange(SelectedItems.OfType<MindNode>());
2023-03-25 22:10:49 +08:00
2023-03-26 23:23:34 +08:00
others = SelectedItems.Where(p => !(p is MindNode)).ToList();
2023-03-05 21:30:53 +08:00
}
2023-03-26 23:23:34 +08:00
if (items.Any())
2023-03-05 21:30:53 +08:00
{
2023-03-26 23:23:34 +08:00
//把子节点都加上
foreach (var item in items.ToList())
{
var children = item.GetChildren();
items.AddRange(children);
}
//去重
items = items.Distinct().ToList();
if (delete)
{
Dictionary<MindNode, Tuple<int, MindNode>> indexs = items.ToDictionary(p => p, p => new Tuple<int, MindNode>(p.ParentNode != null ? p.ParentNode.Children.IndexOf(p) : 0, p.ParentNode));
DoCommandManager.DoNewCommand(this.ToString(),
() => {
foreach (var item in items.ToList())
2023-03-26 23:23:34 +08:00
{
item.RemoveFrom();
2023-03-26 23:23:34 +08:00
}
if (others.Any())
{
base.Delete(others);
}
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
},
() => {
if (others.Any())
{
base.Add(others);
}
foreach (var item in items)
{
item.AddTo(indexs[item].Item2, indexs[item].Item1, false);
if (item.ParentId == Guid.Empty)
{
item.Offset = new PointBase();
}
}
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
});
}
2023-04-05 23:40:22 +08:00
return items.OfType<SelectableDesignerItemViewModelBase>().ToList();
2023-03-05 21:30:53 +08:00
}
2023-03-08 23:02:50 +08:00
else
2023-04-05 23:40:22 +08:00
return null;
2023-03-11 12:40:44 +08:00
}
2023-03-19 23:26:14 +08:00
#endregion
2023-03-11 12:40:44 +08:00
2023-03-24 22:32:42 +08:00
#region ,
2023-03-25 11:59:31 +08:00
protected override void FixOtherInfo(List<SelectableDesignerItemViewModelBase> items)
2023-03-24 22:32:42 +08:00
{
List<MindNode> parents = new List<MindNode>();
foreach (var item in items.OfType<MindNode>())
{
var parent = Items.OfType<MindNode>().FirstOrDefault(p => p.Id == item.ParentId);
2023-03-25 11:59:31 +08:00
if (parent != null && !items.Contains(parent))
2023-03-24 22:32:42 +08:00
{
parents.Add(parent);
}
2023-03-25 11:59:31 +08:00
else if (item.ParentId == Guid.Empty)
2023-03-24 22:32:42 +08:00
{
2023-03-28 22:09:24 +08:00
//item.Offset = new PointBase(item.Offset.X - OffsetX, item.Offset.Y - OffsetY);
2023-03-24 22:32:42 +08:00
parents.Add(item);
2023-03-25 11:59:31 +08:00
item.InitLayout(false);
2023-03-24 22:32:42 +08:00
}
}
ResetChildren(parents);
2023-04-02 21:47:55 +08:00
parents.ForEach(p => p.UpdatedLayout());
2023-03-24 22:32:42 +08:00
}
#endregion
2023-03-19 23:26:14 +08:00
#region
2023-03-11 12:40:44 +08:00
private void ExecuteAddLinkCommand(object obj)
{
2023-03-18 22:50:00 +08:00
if (obj is object[] array && array.Length == 2)
{
2023-03-26 23:23:34 +08:00
if (string.IsNullOrEmpty(array[0]?.ToString()))
{
return;
}
Dictionary<MindNode, LinkInfo> infos = SelectedItems.OfType<MindNode>().ToDictionary(p => p, p => p.LinkInfo);
DoCommandManager.DoNewCommand(this.ToString(),
() => {
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
p.LinkInfo = new LinkInfo(array[0]?.ToString(), array[1]?.ToString());
});
},
() => {
foreach (var linkInfo in infos)
{
linkInfo.Key.LinkInfo = linkInfo.Value;
}
});
2023-03-18 22:50:00 +08:00
}
2023-03-11 12:40:44 +08:00
}
2023-03-08 23:02:50 +08:00
2023-03-11 12:40:44 +08:00
private void ExecuteRemoveLinkCommand(object obj)
{
2023-03-26 23:23:34 +08:00
Dictionary<MindNode, LinkInfo> infos = SelectedItems.OfType<MindNode>().ToDictionary(p => p, p => p.LinkInfo);
DoCommandManager.DoNewCommand(this.ToString(),
() => {
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
p.LinkInfo = null;
});
},
() => {
foreach (var info in infos)
{
info.Key.LinkInfo = info.Value;
}
});
2023-03-11 12:40:44 +08:00
}
2023-03-05 21:30:53 +08:00
2023-03-11 12:40:44 +08:00
private void ExecuteAddImageCommand(object obj)
{
2023-03-19 12:38:08 +08:00
if (obj is object[] array && array.Length == 2)
{
2023-03-26 23:23:34 +08:00
if (string.IsNullOrEmpty(array[0]?.ToString()))
{
return;
}
Dictionary<MindNode, ImageInfo> infos = SelectedItems.OfType<MindNode>().ToDictionary(p => p, p => p.ImageInfo);
DoCommandManager.DoNewCommand(this.ToString(),
() => {
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
p.ImageInfo = new ImageInfo(array[0]?.ToString(), array[1]?.ToString());
});
},
() => {
foreach (var info in infos)
{
info.Key.ImageInfo = info.Value;
}
});
2023-03-19 12:38:08 +08:00
}
2023-03-11 12:40:44 +08:00
}
private void ExecuteRemoveImageCommand(object obj)
{
2023-03-26 23:23:34 +08:00
Dictionary<MindNode, ImageInfo> infos = SelectedItems.OfType<MindNode>().ToDictionary(p => p, p => p.ImageInfo);
DoCommandManager.DoNewCommand(this.ToString(),
() => {
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
p.ImageInfo = null;
});
},
() => {
foreach (var info in infos)
{
info.Key.ImageInfo = info.Value;
}
});
2023-03-11 12:40:44 +08:00
}
private void ExecuteAddRemarkCommand(object obj)
{
2023-03-26 23:23:34 +08:00
if (string.IsNullOrEmpty(obj?.ToString()))
{
return;
}
Dictionary<MindNode, string> infos = SelectedItems.OfType<MindNode>().ToDictionary(p => p, p => p.Remark);
DoCommandManager.DoNewCommand(this.ToString(),
() => {
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
p.Remark = obj?.ToString();
});
},
() => {
foreach (var info in infos)
{
info.Key.Remark = info.Value;
}
});
2023-03-11 12:40:44 +08:00
}
private void ExecuteRemoveRemarkCommand(object obj)
{
2023-03-26 23:23:34 +08:00
Dictionary<MindNode, string> infos = SelectedItems.OfType<MindNode>().ToDictionary(p => p, p => p.Remark);
DoCommandManager.DoNewCommand(this.ToString(),
() => {
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
p.Remark = null;
});
},
() => {
foreach (var info in infos)
{
info.Key.Remark = info.Value;
}
});
2023-03-11 12:40:44 +08:00
}
private void ExecuteAddPriorityCommand(object obj)
{
2023-03-26 23:23:34 +08:00
Dictionary<MindNode, double?> infos = SelectedItems.OfType<MindNode>().ToDictionary(p => p, p => p.Priority);
DoCommandManager.DoNewCommand(this.ToString(),
() => {
if (double.TryParse(obj.ToString(), out var priority))
{
SelectedItems.OfType<MindNode>().ToList().ForEach(p => p.Priority = priority);
}
else
{
SelectedItems.OfType<MindNode>().ToList().ForEach(p => p.Priority = null);
}
},
() => {
foreach (var info in infos)
{
info.Key.Priority = info.Value;
}
});
2023-03-11 12:40:44 +08:00
}
private void ExecuteAddRatioCommand(object obj)
{
2023-03-26 23:23:34 +08:00
Dictionary<MindNode, double?> infos = SelectedItems.OfType<MindNode>().ToDictionary(p => p, p => p.Rate);
DoCommandManager.DoNewCommand(this.ToString(),
() => {
if (double.TryParse(obj.ToString(), out var rate))
{
SelectedItems.OfType<MindNode>().ToList().ForEach(p => p.Rate = rate);
}
else
{
SelectedItems.OfType<MindNode>().ToList().ForEach(p => p.Rate = null);
}
},
() => {
foreach (var info in infos)
{
info.Key.Rate = info.Value;
}
});
2023-03-11 12:40:44 +08:00
}
private void ExecuteAddTagCommand(object obj)
{
2023-03-26 23:23:34 +08:00
DoCommandManager.DoNewCommand(this.ToString(),
() => {
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
p.Tags.Add(obj?.ToString());
});
},
() => {
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
p.Tags.Remove(obj?.ToString());
});
});
2023-03-11 12:40:44 +08:00
}
private void ExecuteRemoveTagCommand(object obj)
{
2023-03-26 23:23:34 +08:00
DoCommandManager.DoNewCommand(this.ToString(),
() => {
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
p.Tags.Remove(obj?.ToString());
});
},
() => {
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
p.Tags.Add(obj?.ToString());
});
});
2023-03-05 21:30:53 +08:00
}
2023-03-19 23:26:14 +08:00
#endregion
2023-03-06 11:54:41 +08:00
2023-03-19 23:26:14 +08:00
#region
private void ChangeMindType(MindType oldMindType, MindType newMindType)
2023-03-06 11:54:41 +08:00
{
List<MindNode> roots;
if (RootItems.Count == 1)//只有一个的时候
2023-03-06 11:54:41 +08:00
{
roots = RootItems.ToList();
}
else
{
roots = MindSelectedItems.Select(p => p.RootNode).Distinct().ToList();
}
if (roots.Count > 0)
{
DoCommandManager.DoNewCommand(this.ToString(),
() => {
roots.ForEach(p => p.MindType = newMindType);
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.InitLayout(true); });
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.InitConnectionLayout(); });
roots.ForEach(p => p.UpdatedLayout());
},
() => {
roots.ForEach(p => p.MindType = oldMindType);
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.InitLayout(true); });
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.InitConnectionLayout(); });
roots.ForEach(p => p.UpdatedLayout());
});
2023-03-26 23:23:34 +08:00
}
}
private void ChangeMindTheme(MindTheme oldMindTheme, MindTheme newMindTheme)
2023-03-06 11:54:41 +08:00
{
List<MindNode> roots;
if (RootItems.Count == 1)//只有一个的时候
{
roots = RootItems.ToList();
}
else
{
roots = MindSelectedItems.Select(p => p.RootNode).Distinct().ToList();
}
if (roots.Count > 0)
2023-03-11 22:27:23 +08:00
{
DoCommandManager.DoNewCommand(this.ToString(),
() => {
var mindThemeModel = MindThemeHelper.GetTheme(newMindTheme);
if (mindThemeModel?.Dark == true)
{
DiagramOption.LayoutOption.PageBackground = Colors.Black;
}
else
{
DiagramOption.LayoutOption.PageBackground = Colors.White;
}
roots.ForEach(p => p.MindTheme = newMindTheme);
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.ThemeChange(); });
roots.ForEach(p => p.UpdatedLayout());
},
() => {
var mindThemeModel = MindThemeHelper.GetTheme(oldMindTheme);
if (mindThemeModel?.Dark == true)
{
DiagramOption.LayoutOption.PageBackground = Colors.Black;
}
else
{
DiagramOption.LayoutOption.PageBackground = Colors.White;
}
roots.ForEach(p => p.MindTheme = oldMindTheme);
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.ThemeChange(); });
roots.ForEach(p => p.UpdatedLayout());
});
2023-03-11 22:27:23 +08:00
}
}
private void ExecutedClearThemeCommand(object parameter)
{
2023-03-26 23:23:34 +08:00
List<MindNode> items = new List<MindNode>();
if (parameter is MindNode node)
2023-03-11 22:27:23 +08:00
{
2023-03-26 23:23:34 +08:00
items.Add(node);
2023-03-11 22:27:23 +08:00
}
else if (parameter is IEnumerable<MindNode> para)
{
2023-03-26 23:23:34 +08:00
items.AddRange(para);
2023-03-11 22:27:23 +08:00
}
else
{
2023-03-26 23:23:34 +08:00
items.AddRange(SelectedItems.OfType<MindNode>());
2023-03-11 22:27:23 +08:00
}
2023-03-06 11:54:41 +08:00
2023-03-26 23:23:34 +08:00
if (items.Any())
2023-03-11 22:27:23 +08:00
{
2023-04-02 12:01:46 +08:00
Dictionary<MindNode, MindThemeModel> infos = items.OfType<MindNode>().ToDictionary(p => p, p => MindThemeHelper.GetNodeTheme(p));
2023-03-11 22:27:23 +08:00
DoCommandManager.DoNewCommand(this.ToString(),
() => {
2023-03-26 23:23:34 +08:00
foreach (var item in items)
2023-03-11 22:27:23 +08:00
{
2023-03-26 23:23:34 +08:00
item.ThemeChange();
2023-03-11 22:27:23 +08:00
}
},
() => {
2023-03-26 23:23:34 +08:00
foreach (var info in infos)
{
MindThemeHelper.SetThemeModel(info.Key, info.Value);
}
2023-03-11 22:27:23 +08:00
});
}
2023-03-06 11:54:41 +08:00
}
2023-03-19 23:26:14 +08:00
private MindNode _formatNode;
2023-03-11 22:27:23 +08:00
private void ExecutedCopyThemeCommand(object parameter)
{
if (parameter is MindNode node)
{
2023-03-12 22:47:45 +08:00
2023-03-11 22:27:23 +08:00
}
else
{
node = SelectedItem as MindNode;
}
if (node != null)
{
2023-03-19 23:26:14 +08:00
_formatNode = node;
2023-03-11 22:27:23 +08:00
}
}
private void ExecutedPasteThemeCommand(object parameter)
{
2023-03-19 23:26:14 +08:00
if (_formatNode != null)
2023-03-19 12:38:08 +08:00
{
2023-03-26 23:23:34 +08:00
List<MindNode> items = new List<MindNode>();
if (parameter is MindNode node)
2023-03-19 12:38:08 +08:00
{
2023-03-26 23:23:34 +08:00
items.Add(node);
2023-03-19 12:38:08 +08:00
}
else if (parameter is IEnumerable<MindNode> para)
{
2023-03-26 23:23:34 +08:00
items.AddRange(para);
2023-03-19 12:38:08 +08:00
}
else
{
2023-03-26 23:23:34 +08:00
items.AddRange(SelectedItems.OfType<MindNode>());
2023-03-19 12:38:08 +08:00
}
2023-03-12 22:47:45 +08:00
2023-03-26 23:23:34 +08:00
if (items.Any())
2023-03-19 12:38:08 +08:00
{
2023-03-26 23:23:34 +08:00
Dictionary<MindNode, Tuple<IColorViewModel, IFontViewModel>> infos = items.OfType<MindNode>().ToDictionary(p => p, p => new Tuple<IColorViewModel, IFontViewModel>(MindThemeHelper.GetColorViewModel(p), MindThemeHelper.GetFontViewModel(p)));
2023-03-19 12:38:08 +08:00
DoCommandManager.DoNewCommand(this.ToString(),
() => {
2023-03-26 23:23:34 +08:00
foreach (var item in items)
2023-03-19 12:38:08 +08:00
{
2023-03-26 23:23:34 +08:00
CopyHelper.CopyPropertyValue(_formatNode.ColorViewModel, item.ColorViewModel);
CopyHelper.CopyPropertyValue(_formatNode.FontViewModel, item.FontViewModel);
2023-03-19 12:38:08 +08:00
}
},
() => {
2023-03-26 23:23:34 +08:00
foreach (var info in infos)
{
CopyHelper.CopyPropertyValue(info.Value.Item1, info.Key.ColorViewModel);
CopyHelper.CopyPropertyValue(info.Value.Item2, info.Key.FontViewModel);
}
2023-03-19 12:38:08 +08:00
});
}
}
2023-03-06 11:54:41 +08:00
}
2023-03-19 23:26:14 +08:00
#endregion
#region
protected override void ExecuteCenterMoveCommand(object parameter)
{
2023-03-24 22:32:42 +08:00
var rootitem = MindSelectedItem?.RootNode;
if (rootitem != null)
{
2023-03-26 23:23:34 +08:00
var left = rootitem.Left;
var top = rootitem.Top;
DoCommandManager.DoNewCommand(this.ToString(),
() => {
Move(rootitem, null, null);
},
() => {
Move(rootitem, left, top);
});
2023-03-24 22:32:42 +08:00
}
2023-03-19 23:26:14 +08:00
}
2023-03-06 11:54:41 +08:00
2023-03-26 23:23:34 +08:00
private void Move(MindNode rootitem, double? left, double? top)
{
2023-04-02 12:01:46 +08:00
2023-03-26 23:23:34 +08:00
if (left == null)
left = (DiagramOption.LayoutOption.PageSize.Width - rootitem.ItemWidth) / 2;
2023-03-26 23:23:34 +08:00
if (top == null)
top = (DiagramOption.LayoutOption.PageSize.Height - rootitem.ItemHeight) / 2;
2023-03-28 22:09:24 +08:00
var offset = rootitem.Offset;
2023-03-26 23:23:34 +08:00
rootitem.Left = left.Value;
rootitem.Top = top.Value;
2023-03-28 22:09:24 +08:00
rootitem.Offset = offset;
2023-04-02 21:47:55 +08:00
rootitem?.UpdatedLayout();
2023-03-26 23:23:34 +08:00
FitViewModel = new FitViewModel() { BoundingRect = rootitem.GetBounds() };
}
2023-03-19 12:38:08 +08:00
private void ExecutedExpand2LevelCommand(object obj)
2023-03-06 11:54:41 +08:00
{
2023-03-19 12:38:08 +08:00
int level = 0;
2023-03-26 23:23:34 +08:00
if (int.TryParse(obj?.ToString(), out level))
2023-03-19 12:38:08 +08:00
{
2023-03-26 23:23:34 +08:00
Dictionary<MindNode, bool> infos = Items.OfType<MindNode>().ToDictionary(p => p, p => p.IsExpanded);
DoCommandManager.DoNewCommand(this.ToString(),
() => {
foreach (var item in Items.OfType<MindNode>())
{
if (item.NodeLevel == 0)
{
continue;
}
else if (item.NodeLevel < level)
{
item.IsExpanded = true;
}
else
{
item.IsExpanded = false;
}
}
},
() => {
foreach (var info in infos)
{
info.Key.IsExpanded = info.Value;
}
});
2023-03-19 12:38:08 +08:00
}
2023-03-19 23:26:14 +08:00
}
protected void ExecuteSelectBrotherCommand(object parameter)
{
2023-03-26 23:23:34 +08:00
List<MindNode> items = new List<MindNode>();
2023-03-19 23:26:14 +08:00
if (parameter is MindNode node)
{
2023-03-26 23:23:34 +08:00
items.Add(node);
}
else if (parameter is IEnumerable<MindNode> para)
{
items.AddRange(para);
2023-03-19 23:26:14 +08:00
}
else
{
2023-03-26 23:23:34 +08:00
items.AddRange(SelectedItems.OfType<MindNode>());
2023-03-19 23:26:14 +08:00
}
2023-03-26 23:23:34 +08:00
if (items.Any())
2023-03-19 23:26:14 +08:00
{
2023-03-26 23:23:34 +08:00
List<MindNode> selecteditems = new List<MindNode>();
DoCommandManager.DoNewCommand(this.ToString(),
() => {
foreach (var item in items)
{
if (item != null && item.ParentNode != null)
{
foreach (var child in item.ParentNode.Children)
{
if (child.IsSelected != true)
{
child.IsSelected = true;
selecteditems.Add(child);
}
}
}
}
},
() => {
foreach (var item in selecteditems)
{
item.IsSelected = false;
}
});
2023-03-19 23:26:14 +08:00
}
}
protected void ExecuteSelectPearCommand(object parameter)
{
2023-03-26 23:23:34 +08:00
List<MindNode> items = new List<MindNode>();
2023-03-19 23:26:14 +08:00
if (parameter is MindNode node)
{
2023-03-26 23:23:34 +08:00
items.Add(node);
}
else if (parameter is IEnumerable<MindNode> para)
{
items.AddRange(para);
2023-03-19 23:26:14 +08:00
}
else
{
2023-03-26 23:23:34 +08:00
items.AddRange(SelectedItems.OfType<MindNode>());
2023-03-19 23:26:14 +08:00
}
2023-03-26 23:23:34 +08:00
if (items.Any())
2023-03-19 23:26:14 +08:00
{
2023-03-26 23:23:34 +08:00
List<MindNode> selecteditems = new List<MindNode>();
DoCommandManager.DoNewCommand(this.ToString(),
() => {
foreach (var item in items)
{
foreach (var pear in Items.OfType<MindNode>().Where(p => p.RootNode == item.RootNode && p.NodeLevel == item.NodeLevel))
{
if (pear.IsSelected != true)
{
pear.IsSelected = true;
selecteditems.Add(pear);
}
}
}
},
() => {
foreach (var item in selecteditems)
{
item.IsSelected = false;
}
});
2023-03-19 23:26:14 +08:00
}
}
protected void ExecuteSelectRouteCommand(object parameter)
{
2023-03-26 23:23:34 +08:00
List<MindNode> items = new List<MindNode>();
2023-03-19 23:26:14 +08:00
if (parameter is MindNode node)
{
2023-03-26 23:23:34 +08:00
items.Add(node);
}
else if (parameter is IEnumerable<MindNode> para)
{
items.AddRange(para);
2023-03-19 23:26:14 +08:00
}
else
{
2023-03-26 23:23:34 +08:00
items.AddRange(SelectedItems.OfType<MindNode>());
2023-03-19 23:26:14 +08:00
}
2023-03-26 23:23:34 +08:00
if (items.Any())
2023-03-19 23:26:14 +08:00
{
2023-03-26 23:23:34 +08:00
List<MindNode> selecteditems = new List<MindNode>();
DoCommandManager.DoNewCommand(this.ToString(),
() => {
foreach (var item in items)
{
var parents = item.GetParent();
foreach (var parent in parents)
{
if (parent.IsSelected != true)
{
parent.IsSelected = true;
selecteditems.Add(parent);
}
}
}
}, () => {
foreach (var item in selecteditems)
{
item.IsSelected = false;
}
});
2023-03-19 23:26:14 +08:00
}
}
protected void ExecuteSelectChildCommand(object parameter)
{
2023-03-26 23:23:34 +08:00
List<MindNode> items = new List<MindNode>();
2023-03-19 23:26:14 +08:00
if (parameter is MindNode node)
{
2023-03-26 23:23:34 +08:00
items.Add(node);
2023-03-19 23:26:14 +08:00
}
2023-03-26 23:23:34 +08:00
else if (parameter is IEnumerable<MindNode> para)
2023-03-19 23:26:14 +08:00
{
2023-03-26 23:23:34 +08:00
items.AddRange(para);
2023-03-19 23:26:14 +08:00
}
2023-03-26 23:23:34 +08:00
else
2023-03-19 23:26:14 +08:00
{
2023-03-26 23:23:34 +08:00
items.AddRange(SelectedItems.OfType<MindNode>());
2023-03-19 23:26:14 +08:00
}
2023-03-26 23:23:34 +08:00
if (items.Any())
{
List<MindNode> selecteditems = new List<MindNode>();
DoCommandManager.DoNewCommand(this.ToString(),
() => {
foreach (var item in items)
{
var children = item.GetChildren();
foreach (var child in children)
{
if (child.IsSelected != true)
{
child.IsSelected = true;
selecteditems.Add(child);
}
}
}
}, () => {
foreach (var item in selecteditems)
{
item.IsSelected = false;
}
});
2023-03-28 22:09:24 +08:00
}
2023-03-19 23:26:14 +08:00
}
2023-03-05 21:30:53 +08:00
#endregion
2023-03-19 23:26:14 +08:00
2023-03-05 21:30:53 +08:00
}
}