mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
1364 lines
45 KiB
C#
1364 lines
45 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Reflection;
|
||
using System.Windows.Input;
|
||
using System.Windows.Media;
|
||
using AIStudio.Wpf.DiagramDesigner;
|
||
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||
using AIStudio.Wpf.Mind.Helpers;
|
||
|
||
namespace AIStudio.Wpf.Mind.ViewModels
|
||
{
|
||
public class MindDiagramViewModel : DiagramViewModel, IMindDiagramViewModel
|
||
{
|
||
#region
|
||
private MindType _mindType = Mind.MindType.Mind;
|
||
public MindType MindType
|
||
{
|
||
get
|
||
{
|
||
return _mindType;
|
||
}
|
||
set
|
||
{
|
||
var oldvalue = _mindType;
|
||
if (SetProperty(ref _mindType, value))
|
||
{
|
||
ExecutedChangeMindType(oldvalue, value);
|
||
}
|
||
}
|
||
}
|
||
|
||
private MindThemeModel _mindThemeModel = MindThemeHelper.GetTheme("天空蓝");
|
||
public MindThemeModel MindThemeModel
|
||
{
|
||
get
|
||
{
|
||
return _mindThemeModel;
|
||
}
|
||
set
|
||
{
|
||
SetProperty(ref _mindThemeModel, value);
|
||
}
|
||
}
|
||
public List<MindNode> RootItems
|
||
{
|
||
get
|
||
{
|
||
return Items.OfType<MindNode>().Where(p => p.NodeLevel == 0).ToList();
|
||
}
|
||
}
|
||
|
||
public MindNode MindSelectedItem
|
||
{
|
||
get
|
||
{
|
||
return SelectedItem as MindNode;
|
||
}
|
||
}
|
||
|
||
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);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 命令
|
||
private ICommand _addRootCommand;
|
||
public ICommand AddRootCommand
|
||
{
|
||
get
|
||
{
|
||
return this._addRootCommand ?? (this._addRootCommand = new SimpleCommand(ExecuteEnable, this.ExecuteAddRootCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _addParentCommand;
|
||
public ICommand AddParentCommand
|
||
{
|
||
get
|
||
{
|
||
return this._addParentCommand ?? (this._addParentCommand = new SimpleCommand(MindLevelEnable, this.ExecuteAddParentCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _addChildCommand;
|
||
public ICommand AddChildCommand
|
||
{
|
||
get
|
||
{
|
||
return this._addChildCommand ?? (this._addChildCommand = new SimpleCommand(MindExecuteEnable, this.ExecuteAddChildCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _AddPearCommand;
|
||
public ICommand AddPearCommand
|
||
{
|
||
get
|
||
{
|
||
return this._AddPearCommand ?? (this._AddPearCommand = new SimpleCommand(MindLevelEnable, this.ExecuteAddPearCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _moveForwardCommand;
|
||
public ICommand MoveForwardCommand
|
||
{
|
||
get
|
||
{
|
||
return this._moveForwardCommand ?? (this._moveForwardCommand = new SimpleCommand(MindExecuteEnable, ExecuteMoveForwardCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _moveBackCommand;
|
||
public ICommand MoveBackCommand
|
||
{
|
||
get
|
||
{
|
||
return this._moveBackCommand ?? (this._moveBackCommand = new SimpleCommand(MindExecuteEnable, ExecuteMoveBackCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _selectBrotherCommand;
|
||
public ICommand SelectBrotherCommand
|
||
{
|
||
get
|
||
{
|
||
return this._selectBrotherCommand ?? (this._selectBrotherCommand = new SimpleCommand(MindLevelEnable, ExecuteSelectBrotherCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _selectPearCommand;
|
||
public ICommand SelectPearCommand
|
||
{
|
||
get
|
||
{
|
||
return this._selectPearCommand ?? (this._selectPearCommand = new SimpleCommand(MindLevelEnable, ExecuteSelectPearCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _selectRouteCommand;
|
||
public ICommand SelectRouteCommand
|
||
{
|
||
get
|
||
{
|
||
return this._selectRouteCommand ?? (this._selectRouteCommand = new SimpleCommand(MindLevelEnable, ExecuteSelectRouteCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _selectChildCommand;
|
||
public ICommand SelectChildCommand
|
||
{
|
||
get
|
||
{
|
||
return this._selectChildCommand ?? (this._selectChildCommand = new SimpleCommand(MindLevelEnable, ExecuteSelectChildCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _addLinkCommand;
|
||
public ICommand AddLinkCommand
|
||
{
|
||
get
|
||
{
|
||
return this._addLinkCommand ?? (this._addLinkCommand = new SimpleCommand(MindExecuteEnable, ExecuteAddLinkCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _removeLinkCommand;
|
||
public ICommand RemoveLinkCommand
|
||
{
|
||
get
|
||
{
|
||
return this._removeLinkCommand ?? (this._removeLinkCommand = new SimpleCommand(MindExecuteEnable, ExecuteRemoveLinkCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _addImageCommand;
|
||
public ICommand AddImageCommand
|
||
{
|
||
get
|
||
{
|
||
return this._addImageCommand ?? (this._addImageCommand = new SimpleCommand(MindExecuteEnable, ExecuteAddImageCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _removeImageCommand;
|
||
public ICommand RemoveImageCommand
|
||
{
|
||
get
|
||
{
|
||
return this._removeImageCommand ?? (this._removeImageCommand = new SimpleCommand(MindExecuteEnable, ExecuteRemoveImageCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _addRemarkCommand;
|
||
public ICommand AddRemarkCommand
|
||
{
|
||
get
|
||
{
|
||
return this._addRemarkCommand ?? (this._addRemarkCommand = new SimpleCommand(MindExecuteEnable, ExecuteAddRemarkCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _removeRemarkCommand;
|
||
public ICommand RemoveRemarkCommand
|
||
{
|
||
get
|
||
{
|
||
return this._removeRemarkCommand ?? (this._removeRemarkCommand = new SimpleCommand(MindExecuteEnable, ExecuteRemoveRemarkCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _addPriorityCommand;
|
||
public ICommand AddPriorityCommand
|
||
{
|
||
get
|
||
{
|
||
return this._addPriorityCommand ?? (this._addPriorityCommand = new SimpleCommand(MindExecuteEnable, ExecuteAddPriorityCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _addRatioCommand;
|
||
public ICommand AddRatioCommand
|
||
{
|
||
get
|
||
{
|
||
return this._addRatioCommand ?? (this._addRatioCommand = new SimpleCommand(MindExecuteEnable, ExecuteAddRatioCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _addTagCommand;
|
||
public ICommand AddTagCommand
|
||
{
|
||
get
|
||
{
|
||
return this._addTagCommand ?? (this._addTagCommand = new SimpleCommand(MindExecuteEnable, ExecuteAddTagCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _removeTagCommand;
|
||
public ICommand RemoveTagCommand
|
||
{
|
||
get
|
||
{
|
||
return this._removeTagCommand ?? (this._removeTagCommand = new SimpleCommand(MindExecuteEnable, ExecuteRemoveTagCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _changeMindTypeCommand;
|
||
public ICommand ChangeMindTypeCommand
|
||
{
|
||
get
|
||
{
|
||
return this._changeMindTypeCommand ?? (this._changeMindTypeCommand = new SimpleCommand(ExecuteEnable, this.ExecutedChangeMindTypeCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _changeMindThemeCommand;
|
||
public ICommand ChangeMindThemeCommand
|
||
{
|
||
get
|
||
{
|
||
return this._changeMindThemeCommand ?? (this._changeMindThemeCommand = new SimpleCommand(ExecuteEnable, this.ExecutedChangeMindThemeCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _clearThemeCommand;
|
||
public ICommand ClearThemeCommand
|
||
{
|
||
get
|
||
{
|
||
return this._clearThemeCommand ?? (this._clearThemeCommand = new SimpleCommand(ExecuteEnable, this.ExecutedClearThemeCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _copyThemeCommand;
|
||
public ICommand CopyThemeCommand
|
||
{
|
||
get
|
||
{
|
||
return this._copyThemeCommand ?? (this._copyThemeCommand = new SimpleCommand(ExecuteEnable, this.ExecutedCopyThemeCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _pasteThemeCommand;
|
||
public ICommand PasteThemeCommand
|
||
{
|
||
get
|
||
{
|
||
return this._pasteThemeCommand ?? (this._pasteThemeCommand = new SimpleCommand(ExecuteEnable, this.ExecutedPasteThemeCommand));
|
||
}
|
||
}
|
||
|
||
private ICommand _expand2LevelCommand;
|
||
public ICommand Expand2LevelCommand
|
||
{
|
||
get
|
||
{
|
||
return this._expand2LevelCommand ?? (this._expand2LevelCommand = new SimpleCommand(ExecuteEnable, this.ExecutedExpand2LevelCommand));
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region ctor和初始化
|
||
public MindDiagramViewModel()
|
||
{
|
||
|
||
}
|
||
|
||
public override void Init()
|
||
{
|
||
if (Items.Count == 0)
|
||
{
|
||
AddRootItem();
|
||
}
|
||
ResetChildren(RootItems);
|
||
RootItems?.ForEach(p => p.LayoutUpdated());
|
||
base.Init();
|
||
}
|
||
|
||
private MindNode AddRootItem()
|
||
{
|
||
ClearSelectedItems();
|
||
MindNode level1node = new MindNode(this) { Root = this, Id = Guid.NewGuid(), Text = "思维导图" };
|
||
level1node.InitLayout(true);
|
||
Items.Add(level1node);
|
||
level1node.IsSelected = true;
|
||
|
||
Move(level1node, null, null);
|
||
|
||
return level1node;
|
||
}
|
||
|
||
protected override void ExecutedResetLayoutCommand(object obj)
|
||
{
|
||
foreach (var item in Items.OfType<MindNode>())
|
||
{
|
||
item.Offset = new DiagramDesigner.Geometrys.PointBase();
|
||
}
|
||
|
||
RootItems?.ForEach(p => p.LayoutUpdated());
|
||
}
|
||
|
||
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));
|
||
foreach (var item in Items.OfType<MindNode>().Where(p => p.ParentId == parent.Id).ToList())
|
||
{
|
||
item.Parent = parent;
|
||
item.InitLayout(false);
|
||
item.InitConnectLayout();
|
||
}
|
||
ResetChildren(parent.Children);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 命令使能
|
||
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;
|
||
|
||
return (SelectedItem as MindNode).NodeLevel != 0;
|
||
}
|
||
#endregion
|
||
|
||
#region 属性改变
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 新增,删除
|
||
public void ExecuteAddRootCommand(object parameter)
|
||
{
|
||
MindNode rootitem = null;
|
||
DoCommandManager.DoNewCommand(this.ToString(),
|
||
() => {
|
||
rootitem = AddRootItem();
|
||
},
|
||
() => {
|
||
if (rootitem != null)
|
||
{
|
||
Remove(rootitem);
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
public void ExecuteAddChildCommand(object parameter)
|
||
{
|
||
List<MindNode> items = new List<MindNode>();
|
||
List<MindNode> newitems = new List<MindNode>();
|
||
if (parameter is MindNode node)
|
||
{
|
||
items.Add(node);
|
||
}
|
||
else if (parameter is IEnumerable<MindNode> para)
|
||
{
|
||
items.AddRange(para);
|
||
}
|
||
else
|
||
{
|
||
items.AddRange(SelectedItems.OfType<MindNode>());
|
||
}
|
||
|
||
DoCommandManager.DoNewCommand(this.ToString(),
|
||
() => {
|
||
|
||
foreach (var item in items)
|
||
{
|
||
var newitem = new MindNode(this) { Text = $"分支主题{item.Children.Count + 1}" };
|
||
newitem.AddTo(item);
|
||
newitems.Add(newitem);
|
||
}
|
||
|
||
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
|
||
},
|
||
() => {
|
||
foreach (var item in newitems)
|
||
{
|
||
item.RemoveFrom();
|
||
}
|
||
|
||
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
|
||
});
|
||
|
||
}
|
||
|
||
public void ExecuteAddParentCommand(object parameter)
|
||
{
|
||
List<MindNode> items = new List<MindNode>();
|
||
List<MindNode> newitems = new List<MindNode>();
|
||
if (parameter is MindNode node)
|
||
{
|
||
items.Add(node);
|
||
}
|
||
else if (parameter is IEnumerable<MindNode> para)
|
||
{
|
||
items.AddRange(para);
|
||
}
|
||
else
|
||
{
|
||
items.AddRange(SelectedItems.OfType<MindNode>());
|
||
}
|
||
|
||
DoCommandManager.DoNewCommand(this.ToString(),
|
||
() => {
|
||
foreach (var item in items)
|
||
{
|
||
if (item.ParentNode == null)
|
||
continue;
|
||
|
||
int index = item.ParentNode.Children.IndexOf(item);
|
||
|
||
var newitem = new MindNode(this) { Text = $"分支主题{index + 1}" };
|
||
newitem.AddTo(item.ParentNode, index);
|
||
item.RemoveFrom();
|
||
item.AddTo(newitem, -1, false);
|
||
newitems.Add(newitem);
|
||
}
|
||
|
||
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
|
||
},
|
||
() => {
|
||
foreach (var item in items)
|
||
{
|
||
if (item.ParentNode == null || item.ParentNode.ParentNode == null)
|
||
continue;
|
||
|
||
var parent = item.ParentNode;
|
||
int index = item.ParentNode.ParentNode.Children.IndexOf(item.ParentNode);
|
||
|
||
item.RemoveFrom();
|
||
parent.RemoveFrom();
|
||
item.AddTo(parent.ParentNode, index);
|
||
}
|
||
|
||
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
|
||
});
|
||
}
|
||
|
||
public void ExecuteAddPearCommand(object parameter)
|
||
{
|
||
List<MindNode> items = new List<MindNode>();
|
||
List<MindNode> newitems = new List<MindNode>();
|
||
if (parameter is MindNode node)
|
||
{
|
||
items.Add(node);
|
||
}
|
||
else if (parameter is IEnumerable<MindNode> para)
|
||
{
|
||
items.AddRange(para);
|
||
}
|
||
else
|
||
{
|
||
items.AddRange(SelectedItems.OfType<MindNode>());
|
||
}
|
||
|
||
DoCommandManager.DoNewCommand(this.ToString(),
|
||
() => {
|
||
foreach (var item in items)
|
||
{
|
||
if (item.ParentNode == null)
|
||
continue;
|
||
|
||
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);
|
||
}
|
||
|
||
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
|
||
},
|
||
() => {
|
||
foreach (var item in newitems)
|
||
{
|
||
item.RemoveFrom();
|
||
item.LayoutUpdated();
|
||
}
|
||
|
||
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
|
||
});
|
||
}
|
||
|
||
private void ExecuteMoveBackCommand(object parameter)
|
||
{
|
||
List<MindNode> items = new List<MindNode>();
|
||
if (parameter is MindNode node)
|
||
{
|
||
items.Add(node);
|
||
}
|
||
else if (parameter is IEnumerable<MindNode> para)
|
||
{
|
||
items.AddRange(para);
|
||
}
|
||
else
|
||
{
|
||
items.AddRange(SelectedItems.OfType<MindNode>());
|
||
}
|
||
|
||
DoCommandManager.DoNewCommand(this.ToString(),
|
||
() => {
|
||
MoveBack(items);
|
||
},
|
||
() => {
|
||
MoveForward(items);
|
||
});
|
||
}
|
||
|
||
private void ExecuteMoveForwardCommand(object parameter)
|
||
{
|
||
List<MindNode> items = new List<MindNode>();
|
||
List<MindNode> newitems = new List<MindNode>();
|
||
if (parameter is MindNode node)
|
||
{
|
||
items.Add(node);
|
||
}
|
||
else if (parameter is IEnumerable<MindNode> para)
|
||
{
|
||
items.AddRange(para);
|
||
}
|
||
else
|
||
{
|
||
items.AddRange(SelectedItems.OfType<MindNode>());
|
||
}
|
||
|
||
DoCommandManager.DoNewCommand(this.ToString(),
|
||
() => {
|
||
MoveForward(items);
|
||
},
|
||
() => {
|
||
MoveBack(items);
|
||
});
|
||
}
|
||
|
||
private void MoveBack(List<MindNode> items)
|
||
{
|
||
foreach (var item in items)
|
||
{
|
||
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);
|
||
}
|
||
}
|
||
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
|
||
}
|
||
|
||
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);
|
||
|
||
if (index > 0)
|
||
{
|
||
item.RemoveFrom();
|
||
item.AddTo(parent, index - 1);
|
||
}
|
||
}
|
||
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
|
||
}
|
||
|
||
protected override bool Delete(object parameter)
|
||
{
|
||
List<MindNode> items = new List<MindNode>();
|
||
List<SelectableDesignerItemViewModelBase> others = new List<SelectableDesignerItemViewModelBase>();
|
||
if (parameter is MindNode node)
|
||
{
|
||
items.Add(node);
|
||
}
|
||
else if (parameter is IEnumerable<MindNode> para)
|
||
{
|
||
items.AddRange(para);
|
||
}
|
||
else
|
||
{
|
||
items.AddRange(SelectedItems.OfType<MindNode>());
|
||
|
||
others = SelectedItems.Where(p => !(p is MindNode)).ToList();
|
||
}
|
||
|
||
if (items.FirstOrDefault()?.IsEditing != false)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
if (items.Any())
|
||
{
|
||
//把子节点都加上
|
||
foreach (var item in items.ToList())
|
||
{
|
||
var children = item.GetChildren();
|
||
items.AddRange(children);
|
||
}
|
||
//去重
|
||
items = items.Distinct().ToList();
|
||
|
||
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())
|
||
{
|
||
item.RemoveFrom();
|
||
}
|
||
|
||
if (others.Any())
|
||
{
|
||
base.Delete(others);
|
||
}
|
||
|
||
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
|
||
},
|
||
() => {
|
||
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.LayoutUpdated());
|
||
});
|
||
return true;
|
||
}
|
||
else
|
||
return false;
|
||
}
|
||
#endregion
|
||
|
||
#region 复制,粘贴
|
||
protected override void FixOtherInfo(List<SelectableDesignerItemViewModelBase> items)
|
||
{
|
||
List<MindNode> parents = new List<MindNode>();
|
||
foreach (var item in items.OfType<MindNode>())
|
||
{
|
||
//item.DesiredPosition = new PointBase(item.DesiredPosition?.X ?? 0 + OffsetX, item.DesiredPosition?.Y ?? 0 + OffsetY);
|
||
var parent = Items.OfType<MindNode>().FirstOrDefault(p => p.Id == item.ParentId);
|
||
if (parent != null && !items.Contains(parent))
|
||
{
|
||
parents.Add(parent);
|
||
}
|
||
else if (item.ParentId == Guid.Empty)
|
||
{
|
||
item.Offset = new PointBase(OffsetX, OffsetX);
|
||
parents.Add(item);
|
||
item.InitLayout(false);
|
||
}
|
||
}
|
||
ResetChildren(parents);
|
||
parents.ForEach(p => p.LayoutUpdated());
|
||
}
|
||
#endregion
|
||
|
||
#region 附加信息
|
||
private void ExecuteAddLinkCommand(object obj)
|
||
{
|
||
if (obj is object[] array && array.Length == 2)
|
||
{
|
||
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;
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
private void ExecuteRemoveLinkCommand(object obj)
|
||
{
|
||
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;
|
||
}
|
||
});
|
||
}
|
||
|
||
private void ExecuteAddImageCommand(object obj)
|
||
{
|
||
if (obj is object[] array && array.Length == 2)
|
||
{
|
||
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;
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
private void ExecuteRemoveImageCommand(object obj)
|
||
{
|
||
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;
|
||
}
|
||
});
|
||
}
|
||
|
||
private void ExecuteAddRemarkCommand(object obj)
|
||
{
|
||
|
||
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;
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
private void ExecuteRemoveRemarkCommand(object obj)
|
||
{
|
||
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;
|
||
}
|
||
});
|
||
}
|
||
|
||
private void ExecuteAddPriorityCommand(object obj)
|
||
{
|
||
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;
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
private void ExecuteAddRatioCommand(object obj)
|
||
{
|
||
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;
|
||
}
|
||
});
|
||
}
|
||
|
||
private void ExecuteAddTagCommand(object obj)
|
||
{
|
||
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());
|
||
});
|
||
});
|
||
|
||
}
|
||
|
||
private void ExecuteRemoveTagCommand(object obj)
|
||
{
|
||
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());
|
||
});
|
||
});
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 改变模式,主题
|
||
private void ExecutedChangeMindTypeCommand(object obj)
|
||
{
|
||
if (obj is MindType mindType)
|
||
{
|
||
MindType = mindType;
|
||
}
|
||
}
|
||
|
||
private void ExecutedChangeMindType(MindType oldvalue, MindType newvalue)
|
||
{
|
||
DoCommandManager.DoNewCommand(this.ToString(),
|
||
() => {
|
||
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitLayout(true); });
|
||
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitConnectLayout(); });
|
||
RootItems?.ForEach(p => p.LayoutUpdated());
|
||
},
|
||
() => {
|
||
_mindType = oldvalue;
|
||
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitLayout(true); });
|
||
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitConnectLayout(); });
|
||
RootItems?.ForEach(p => p.LayoutUpdated());
|
||
});
|
||
}
|
||
|
||
private void ExecutedChangeMindThemeCommand(object obj)
|
||
{
|
||
string oldmindThemeModel = MindThemeModel.Name;
|
||
if (obj is string mindThemeModel && mindThemeModel != oldmindThemeModel)
|
||
{
|
||
DoCommandManager.DoNewCommand(this.ToString(),
|
||
() => {
|
||
MindThemeModel = MindThemeHelper.GetTheme(mindThemeModel);
|
||
if (MindThemeModel?.Dark == true)
|
||
{
|
||
PageBackground = Colors.Black;
|
||
}
|
||
else
|
||
{
|
||
PageBackground = Colors.White;
|
||
}
|
||
Items.OfType<MindNode>().ToList().ForEach(item => { item.ThemeChange(); });
|
||
},
|
||
() => {
|
||
MindThemeModel = MindThemeHelper.GetTheme(oldmindThemeModel);
|
||
if (MindThemeModel?.Dark == true)
|
||
{
|
||
PageBackground = Colors.Black;
|
||
}
|
||
else
|
||
{
|
||
PageBackground = Colors.White;
|
||
}
|
||
Items.OfType<MindNode>().ToList().ForEach(item => { item.ThemeChange(); });
|
||
});
|
||
}
|
||
}
|
||
|
||
private void ExecutedClearThemeCommand(object parameter)
|
||
{
|
||
List<MindNode> items = new List<MindNode>();
|
||
if (parameter is MindNode node)
|
||
{
|
||
items.Add(node);
|
||
}
|
||
else if (parameter is IEnumerable<MindNode> para)
|
||
{
|
||
items.AddRange(para);
|
||
}
|
||
else
|
||
{
|
||
items.AddRange(SelectedItems.OfType<MindNode>());
|
||
}
|
||
|
||
if (items.Any())
|
||
{
|
||
Dictionary<MindNode, MindThemeModel> infos = items.OfType<MindNode>().ToDictionary(p => p, p => MindThemeHelper.GetThemeModel(p));
|
||
DoCommandManager.DoNewCommand(this.ToString(),
|
||
() => {
|
||
foreach (var item in items)
|
||
{
|
||
item.ThemeChange();
|
||
}
|
||
},
|
||
() => {
|
||
foreach (var info in infos)
|
||
{
|
||
MindThemeHelper.SetThemeModel(info.Key, info.Value);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
private MindNode _formatNode;
|
||
private void ExecutedCopyThemeCommand(object parameter)
|
||
{
|
||
if (parameter is MindNode node)
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
node = SelectedItem as MindNode;
|
||
}
|
||
|
||
if (node != null)
|
||
{
|
||
_formatNode = node;
|
||
}
|
||
}
|
||
|
||
private void ExecutedPasteThemeCommand(object parameter)
|
||
{
|
||
if (_formatNode != null)
|
||
{
|
||
List<MindNode> items = new List<MindNode>();
|
||
if (parameter is MindNode node)
|
||
{
|
||
items.Add(node);
|
||
}
|
||
else if (parameter is IEnumerable<MindNode> para)
|
||
{
|
||
items.AddRange(para);
|
||
}
|
||
else
|
||
{
|
||
items.AddRange(SelectedItems.OfType<MindNode>());
|
||
}
|
||
|
||
if (items.Any())
|
||
{
|
||
Dictionary<MindNode, Tuple<IColorViewModel, IFontViewModel>> infos = items.OfType<MindNode>().ToDictionary(p => p, p => new Tuple<IColorViewModel, IFontViewModel>(MindThemeHelper.GetColorViewModel(p), MindThemeHelper.GetFontViewModel(p)));
|
||
DoCommandManager.DoNewCommand(this.ToString(),
|
||
() => {
|
||
foreach (var item in items)
|
||
{
|
||
CopyHelper.CopyPropertyValue(_formatNode.ColorViewModel, item.ColorViewModel);
|
||
CopyHelper.CopyPropertyValue(_formatNode.FontViewModel, item.FontViewModel);
|
||
}
|
||
},
|
||
() => {
|
||
foreach (var info in infos)
|
||
{
|
||
CopyHelper.CopyPropertyValue(info.Value.Item1, info.Key.ColorViewModel);
|
||
CopyHelper.CopyPropertyValue(info.Value.Item2, info.Key.FontViewModel);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 操作
|
||
protected override void ExecuteCenterMoveCommand(object parameter)
|
||
{
|
||
var rootitem = MindSelectedItem?.RootNode;
|
||
if (rootitem != null)
|
||
{
|
||
var left = rootitem.Left;
|
||
var top = rootitem.Top;
|
||
DoCommandManager.DoNewCommand(this.ToString(),
|
||
() => {
|
||
Move(rootitem, null, null);
|
||
},
|
||
() => {
|
||
Move(rootitem, left, top);
|
||
});
|
||
}
|
||
}
|
||
|
||
private void Move(MindNode rootitem, double? left, double? top)
|
||
{
|
||
if (left == null)
|
||
left = (PageSize.Width - rootitem.ItemWidth) / 2;
|
||
if (top == null)
|
||
top = (PageSize.Height - rootitem.ItemHeight) / 2;
|
||
rootitem.Left = left.Value;
|
||
rootitem.Top = top.Value;
|
||
rootitem?.LayoutUpdated();
|
||
FitViewModel = new FitViewModel() { BoundingRect = rootitem.GetBounds() };
|
||
}
|
||
|
||
private void ExecutedExpand2LevelCommand(object obj)
|
||
{
|
||
int level = 0;
|
||
if (int.TryParse(obj?.ToString(), out level))
|
||
{
|
||
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;
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
protected void ExecuteSelectBrotherCommand(object parameter)
|
||
{
|
||
List<MindNode> items = new List<MindNode>();
|
||
if (parameter is MindNode node)
|
||
{
|
||
items.Add(node);
|
||
}
|
||
else if (parameter is IEnumerable<MindNode> para)
|
||
{
|
||
items.AddRange(para);
|
||
}
|
||
else
|
||
{
|
||
items.AddRange(SelectedItems.OfType<MindNode>());
|
||
}
|
||
|
||
if (items.Any())
|
||
{
|
||
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;
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
protected void ExecuteSelectPearCommand(object parameter)
|
||
{
|
||
List<MindNode> items = new List<MindNode>();
|
||
if (parameter is MindNode node)
|
||
{
|
||
items.Add(node);
|
||
}
|
||
else if (parameter is IEnumerable<MindNode> para)
|
||
{
|
||
items.AddRange(para);
|
||
}
|
||
else
|
||
{
|
||
items.AddRange(SelectedItems.OfType<MindNode>());
|
||
}
|
||
|
||
if (items.Any())
|
||
{
|
||
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;
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
protected void ExecuteSelectRouteCommand(object parameter)
|
||
{
|
||
List<MindNode> items = new List<MindNode>();
|
||
if (parameter is MindNode node)
|
||
{
|
||
items.Add(node);
|
||
}
|
||
else if (parameter is IEnumerable<MindNode> para)
|
||
{
|
||
items.AddRange(para);
|
||
}
|
||
else
|
||
{
|
||
items.AddRange(SelectedItems.OfType<MindNode>());
|
||
}
|
||
if (items.Any())
|
||
{
|
||
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;
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
protected void ExecuteSelectChildCommand(object parameter)
|
||
{
|
||
List<MindNode> items = new List<MindNode>();
|
||
if (parameter is MindNode node)
|
||
{
|
||
items.Add(node);
|
||
}
|
||
else if (parameter is IEnumerable<MindNode> para)
|
||
{
|
||
items.AddRange(para);
|
||
}
|
||
else
|
||
{
|
||
items.AddRange(SelectedItems.OfType<MindNode>());
|
||
}
|
||
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;
|
||
}
|
||
});
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
}
|
||
}
|