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

1025 lines
31 KiB
C#
Raw Normal View History

2023-03-05 21:30:53 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
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-03-11 22:27:23 +08:00
using AIStudio.Wpf.Mind.Helpers;
2023-03-05 21:30:53 +08:00
namespace AIStudio.Wpf.Mind.ViewModels
{
public class MindDiagramViewModel : DiagramViewModel, IMindDiagramViewModel
{
#region
private MindType _mindType = Mind.MindType.Mind;
public MindType MindType
{
get
{
return _mindType;
}
set
{
if (SetProperty(ref _mindType, value))
{
ExecutedChangeMindTypeCommand(value);
}
}
}
2023-03-05 23:22:34 +08:00
2023-03-20 23:01:38 +08:00
private MindThemeModel _mindThemeModel = MindThemeHelper.GetTheme("天空蓝");
2023-03-11 22:27:23 +08:00
public MindThemeModel MindThemeModel
{
get
{
return _mindThemeModel;
}
set
{
SetProperty(ref _mindThemeModel, value);
}
}
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-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-03-24 22:32:42 +08:00
private ICommand _deleteCommand;
public override ICommand DeleteCommand
2023-03-08 23:02:50 +08:00
{
get
{
return this._deleteCommand ?? (this._deleteCommand = new SimpleCommand(MindLevelEnable, ExecuteDeleteCommand));
}
}
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 _changeMindTypeCommand;
public ICommand ChangeMindTypeCommand
2023-03-05 21:30:53 +08:00
{
get
{
2023-03-11 22:27:23 +08:00
return this._changeMindTypeCommand ?? (this._changeMindTypeCommand = new SimpleCommand(ExecuteEnable, this.ExecutedChangeMindTypeCommand));
2023-03-05 21:30:53 +08:00
}
2023-03-05 23:22:34 +08:00
}
2023-03-05 21:30:53 +08:00
2023-03-24 22:32:42 +08:00
private ICommand _changeMindThemeCommand;
public ICommand ChangeMindThemeCommand
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._changeMindThemeCommand ?? (this._changeMindThemeCommand = new SimpleCommand(ExecuteEnable, this.ExecutedChangeMindThemeCommand));
}
}
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()
{
if (Items.Count == 0)
{
InitRootItem();
}
2023-03-24 22:32:42 +08:00
ResetChildren(RootItems);
RootItems?.ForEach(p => p.LayoutUpdated());
2023-03-08 23:02:50 +08:00
base.Init();
}
public void InitRootItem()
2023-03-05 21:30:53 +08:00
{
2023-03-24 22:32:42 +08:00
ClearSelectedItemsCommand.Execute(null);
2023-03-12 15:26:58 +08:00
MindNode level1node = new MindNode(this) { Root = this, Id = Guid.NewGuid(), Text = "思维导图" };
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
CenterMoveCommand.Execute(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();
}
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));
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);
item.InitConnectLayout();
}
ResetChildren(parent.Children);
}
}
private List<MindNode> GetParent(MindNode node)
{
List<MindNode> mindnode = new List<MindNode>();
while (node.ParentNode != null)
{
mindnode.Add(node.ParentNode);
node = node.ParentNode;
}
return mindnode;
}
private List<MindNode> GetChildren(MindNode parent)
{
List<MindNode> mindnode = new List<MindNode>();
if (parent.Children != null)
{
foreach (var child in parent.Children)
{
mindnode.Add(child);
mindnode.AddRange(GetChildren(child));
}
}
return mindnode;
}
#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 ,
public void ExecuteAddRootCommand(object parameter)
{
InitRootItem();
}
2023-03-05 21:30:53 +08:00
public void ExecuteAddChildCommand(object parameter)
{
List<MindNode> items = new List<MindNode>();
if (parameter is MindNode parent)
{
}
else if (parameter is IEnumerable<MindNode> para)
{
parent = para.FirstOrDefault();//第一个固定为父节点
items = para.Skip(1).ToList();
}
else
{
parent = SelectedItem as MindNode;
}
if (items?.Count == 0)
{
2023-03-25 22:10:49 +08:00
var node = new MindNode(this) { Text = $"分支主题{parent.Children.Count + 1}" };
2023-03-05 21:30:53 +08:00
items.Add(node);
}
DoCommandManager.DoNewCommand(this.ToString(),
() => {
foreach (var item in items)
{
parent.AddChild(item);
}
parent.LayoutUpdated();
},
() => {
foreach (var item in items)
{
parent.RemoveChild(item);
}
parent.LayoutUpdated();
});
}
public void ExecuteAddParentCommand(object parameter)
{
List<MindNode> items = new List<MindNode>();
if (parameter is MindNode node)
{
}
else if (parameter is IEnumerable<MindNode> para)
{
node = para.FirstOrDefault();//第一个固定为父节点
items = para.Skip(1).ToList();
}
else
{
node = SelectedItem as MindNode;
2023-03-25 22:10:49 +08:00
}
2023-03-05 21:30:53 +08:00
if (node.Parent is MindNode parent)
{
2023-03-25 11:59:31 +08:00
if (items?.Count == 0)
{
items.Add(new MindNode(this) { Text = $"分支主题{parent.Children.Count + 1}" });
}
2023-03-05 21:30:53 +08:00
DoCommandManager.DoNewCommand(this.ToString(),
() => {
int index = parent.Children.IndexOf(node);
parent.AddChild(items[0], index + 1);
parent.RemoveChild(node);
items[0].AddChild(node);
parent.LayoutUpdated();
},
() => {
int index = parent.Children.IndexOf(items[0]);
items[0].RemoveChild(node);
parent.AddChild(node, index + 1);
parent.LayoutUpdated();
});
}
}
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>();
if (parameter is MindNode pear)
{
}
else if (parameter is IEnumerable<MindNode> para)
{
pear = para.FirstOrDefault();//第一个固定为同级节点
items = para.Skip(1).ToList();
}
else
{
pear = SelectedItem as MindNode;
}
if (pear.Parent is MindNode parent)
{
2023-03-25 11:59:31 +08:00
if (items?.Count == 0)
{
var node = new MindNode(this) { Text = $"分支主题{parent.Children.Count + 1}" };
items.Add(node);
}
2023-03-05 21:30:53 +08:00
DoCommandManager.DoNewCommand(this.ToString(),
() => {
int index = parent.Children.IndexOf(pear);
for (int i = 0; i < items.Count; i++)
{
parent.AddChild(items[i], index + i + 1);
}
parent.LayoutUpdated();
},
() => {
for (int i = 0; i < items.Count; i++)
{
parent.RemoveChild(items[i]);
}
parent.LayoutUpdated();
});
}
}
private void ExecuteMoveBackCommand(object parameter)
{
if (parameter is MindNode node)
{
}
else
{
node = SelectedItem as MindNode;
}
if (node.Parent is MindNode parent)
{
DoCommandManager.DoNewCommand(this.ToString(),
() => {
int index = parent.Children.IndexOf(node);
if (index < parent.Children.Count - 1)
{
parent.RemoveChild(node);
parent.AddChild(node, index + 1);
parent.LayoutUpdated();
}
},
() => {
int index = parent.Children.IndexOf(node);
if (index > 0)
{
parent.RemoveChild(node);
parent.AddChild(node, index - 1);
parent.LayoutUpdated();
}
});
}
}
private void ExecuteMoveForwardCommand(object parameter)
{
if (parameter is MindNode node)
{
}
else
{
node = SelectedItem as MindNode;
}
if (node.Parent is MindNode parent)
{
DoCommandManager.DoNewCommand(this.ToString(),
() => {
int index = parent.Children.IndexOf(node);
if (index > 0)
{
parent.RemoveChild(node);
parent.AddChild(node, index - 1);
parent.LayoutUpdated();
}
},
() => {
int index = parent.Children.IndexOf(node);
if (index < parent.Children.Count - 1)
{
parent.RemoveChild(node);
parent.AddChild(node, index + 1);
parent.LayoutUpdated();
}
});
}
}
2023-03-08 23:02:50 +08:00
protected override bool Delete(object parameter)
2023-03-05 21:30:53 +08:00
{
2023-03-10 12:09:13 +08:00
List<MindNode> nodes = new List<MindNode>();
2023-03-25 22:10:49 +08:00
List<SelectableDesignerItemViewModelBase> others = new List<SelectableDesignerItemViewModelBase>();
2023-03-10 12:09:13 +08:00
if (parameter is MindNode node1)
2023-03-05 21:30:53 +08:00
{
2023-03-10 12:09:13 +08:00
nodes.Add(node1);
}
else if (parameter is IEnumerable<MindNode> para)
{
nodes.AddRange(para);
2023-03-05 21:30:53 +08:00
}
else
{
2023-03-10 12:09:13 +08:00
nodes.AddRange(SelectedItems.OfType<MindNode>());
2023-03-25 22:10:49 +08:00
others = SelectedItems.Where(p => !(p is MindNode)).ToList();
2023-03-05 21:30:53 +08:00
}
2023-03-10 12:09:13 +08:00
if (nodes.FirstOrDefault()?.IsEditing != false)
2023-03-08 23:02:50 +08:00
{
return false;
}
2023-03-10 12:09:13 +08:00
if (nodes.Any())
2023-03-05 21:30:53 +08:00
{
2023-03-24 22:32:42 +08:00
Dictionary<MindNode, int> indexs = nodes.ToDictionary(p => p, p => p.ParentNode != null ? p.ParentNode.Children.IndexOf(p) : 0);
2023-03-05 21:30:53 +08:00
DoCommandManager.DoNewCommand(this.ToString(),
() => {
2023-03-10 12:09:13 +08:00
foreach (var node in nodes)
2023-03-12 22:47:45 +08:00
{
2023-03-25 22:10:49 +08:00
node.Remove(true);
2023-03-10 12:09:13 +08:00
}
2023-03-24 22:32:42 +08:00
RootItems.ForEach(p => p.LayoutUpdated());
2023-03-25 22:10:49 +08:00
if (others.Any())
{
base.Delete(others);
}
2023-03-05 21:30:53 +08:00
},
() => {
2023-03-10 12:09:13 +08:00
foreach (var node in nodes)
2023-03-12 22:47:45 +08:00
{
2023-03-10 12:09:13 +08:00
node.ParentNode.AddChild(node, indexs[node]);
}
2023-03-24 22:32:42 +08:00
RootItems.ForEach(p => p.LayoutUpdated());
2023-03-05 21:30:53 +08:00
});
2023-03-08 23:02:50 +08:00
return true;
2023-03-05 21:30:53 +08:00
}
2023-03-08 23:02:50 +08:00
else
return false;
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
{
2023-03-25 22:10:49 +08:00
2023-03-24 22:32:42 +08:00
List<MindNode> parents = new List<MindNode>();
foreach (var item in items.OfType<MindNode>())
{
2023-03-25 22:10:49 +08:00
//item.DesiredPosition = new PointBase(item.DesiredPosition?.X ?? 0 + OffsetX, item.DesiredPosition?.Y ?? 0 + OffsetY);
2023-03-24 22:32:42 +08:00
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-25 22:10:49 +08:00
item.Offset = new PointBase(OffsetX, OffsetX);
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-03-25 11:59:31 +08:00
parents.ForEach(p => p.LayoutUpdated());
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-24 22:32:42 +08:00
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
2023-03-18 22:50:00 +08:00
if (p.LinkInfo == null)
p.LinkInfo = new LinkInfo();
p.LinkInfo.Link = array[0]?.ToString();
p.LinkInfo.Text = array[1]?.ToString();
2023-03-24 22:32:42 +08:00
});
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-18 22:50:00 +08:00
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
if (p.LinkInfo != null)
{
2023-03-24 22:32:42 +08:00
p.LinkInfo.Link = null;
2023-03-19 12:38:08 +08:00
p.LinkInfo.Text = null;
2023-03-18 22:50:00 +08:00
}
});
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)
{
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
if (p.ImageInfo == null)
p.ImageInfo = new ImageInfo();
2023-03-12 22:47:45 +08:00
2023-03-19 12:38:08 +08:00
p.ImageInfo.Url = array[0]?.ToString();
p.ImageInfo.Text = array[1]?.ToString();
});
}
2023-03-11 12:40:44 +08:00
}
private void ExecuteRemoveImageCommand(object obj)
{
2023-03-19 12:38:08 +08:00
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
if (p.ImageInfo != null)
{
p.ImageInfo.Url = null;
p.ImageInfo.Text = null;
}
});
2023-03-11 12:40:44 +08:00
}
private void ExecuteAddRemarkCommand(object obj)
{
2023-03-19 12:38:08 +08:00
SelectedItems.OfType<MindNode>().ToList().ForEach(p => p.Remark = obj?.ToString());
2023-03-11 12:40:44 +08:00
}
private void ExecuteRemoveRemarkCommand(object obj)
{
2023-03-18 21:44:58 +08:00
SelectedItems.OfType<MindNode>().ToList().ForEach(p => p.Remark = null);
2023-03-11 12:40:44 +08:00
}
private void ExecuteAddPriorityCommand(object obj)
{
2023-03-13 22:27:00 +08:00
if (double.TryParse(obj.ToString(), out var priority))
{
SelectedItems.OfType<MindNode>().ToList().ForEach(p => p.Priority = priority);
}
2023-03-15 19:35:53 +08:00
else
{
SelectedItems.OfType<MindNode>().ToList().ForEach(p => p.Priority = null);
}
2023-03-11 12:40:44 +08:00
}
private void ExecuteAddRatioCommand(object obj)
{
2023-03-15 23:05:41 +08:00
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);
}
2023-03-11 12:40:44 +08:00
}
private void ExecuteAddTagCommand(object obj)
{
2023-03-18 21:44:58 +08:00
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
p.Tags.Add(obj?.ToString());
});
2023-03-11 12:40:44 +08:00
}
private void ExecuteRemoveTagCommand(object obj)
{
2023-03-18 21:44:58 +08:00
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
p.Tags.Remove(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
2023-03-06 11:54:41 +08:00
private void ExecutedChangeMindTypeCommand(object obj)
{
if (obj is MindType mindType)
{
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitLayout(true); });
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitConnectLayout(); });
2023-03-24 22:32:42 +08:00
RootItems?.ForEach(p => p.LayoutUpdated());
2023-03-06 11:54:41 +08:00
}
}
private void ExecutedChangeMindThemeCommand(object obj)
{
2023-03-11 22:27:23 +08:00
if (obj is string mindThemeModel)
{
MindThemeModel = MindThemeHelper.GetTheme(mindThemeModel);
2023-03-25 22:10:49 +08:00
if (MindThemeModel?.Dark == true)
2023-03-11 22:27:23 +08:00
{
PageBackground = Colors.Black;
}
else
{
PageBackground = Colors.White;
}
Items.OfType<MindNode>().ToList().ForEach(item => { item.ThemeChange(); });
}
}
private void ExecutedClearThemeCommand(object parameter)
{
List<MindNode> nodes = new List<MindNode>();
if (parameter is MindNode node1)
{
nodes.Add(node1);
}
else if (parameter is IEnumerable<MindNode> para)
{
nodes.AddRange(para);
}
else
{
nodes.AddRange(SelectedItems.OfType<MindNode>());
}
2023-03-06 11:54:41 +08:00
2023-03-11 22:27:23 +08:00
if (nodes.Any())
{
DoCommandManager.DoNewCommand(this.ToString(),
() => {
foreach (var node in nodes)
{
node.ThemeChange();
}
},
() => {
2023-03-12 22:47:45 +08:00
//ToDo
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
{
List<MindNode> nodes = new List<MindNode>();
if (parameter is MindNode node1)
{
nodes.Add(node1);
}
else if (parameter is IEnumerable<MindNode> para)
{
nodes.AddRange(para);
}
else
{
nodes.AddRange(SelectedItems.OfType<MindNode>());
}
2023-03-12 22:47:45 +08:00
2023-03-19 12:38:08 +08:00
if (nodes.Any())
{
DoCommandManager.DoNewCommand(this.ToString(),
() => {
foreach (var node in nodes)
{
2023-03-19 23:26:14 +08:00
CopyHelper.CopyPropertyValue(_formatNode.ColorViewModel, node.ColorViewModel);
CopyHelper.CopyPropertyValue(_formatNode.FontViewModel, node.FontViewModel);
2023-03-19 12:38:08 +08:00
}
},
() => {
//ToDo
});
}
2023-03-24 22:32:42 +08:00
2023-03-19 12:38:08 +08:00
}
2023-03-12 22:47:45 +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)
{
rootitem.Left = (PageSize.Width - rootitem.ItemWidth) / 2;
rootitem.Top = (PageSize.Height - rootitem.ItemHeight) / 2;
rootitem?.LayoutUpdated();
FitViewModel = new FitViewModel() { BoundingRect = rootitem.GetBounds() };
}
2023-03-19 23:26:14 +08:00
}
2023-03-06 11:54:41 +08:00
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;
int.TryParse(obj?.ToString(), out level);
foreach (var item in Items.OfType<MindNode>())
{
if (item.NodeLevel == 0)
{
continue;
}
else if (item.NodeLevel < level)
{
item.IsExpanded = true;
}
else
{
item.IsExpanded = false;
}
}
2023-03-19 23:26:14 +08:00
}
protected void ExecuteSelectBrotherCommand(object parameter)
{
if (parameter is MindNode node)
{
}
else
{
node = SelectedItem as MindNode;
}
if (node != null && node.ParentNode != null)
{
foreach (var child in node.ParentNode.Children)
{
child.IsSelected = true;
}
}
}
protected void ExecuteSelectPearCommand(object parameter)
{
if (parameter is MindNode node)
{
}
else
{
node = SelectedItem as MindNode;
}
if (node != null)
{
foreach (var item in Items.OfType<MindNode>().Where(p => p.NodeLevel == node.NodeLevel))
{
item.IsSelected = true;
}
}
}
protected void ExecuteSelectRouteCommand(object parameter)
{
if (parameter is MindNode node)
{
}
else
{
node = SelectedItem as MindNode;
}
if (node != null)
{
GetParent(node).ForEach(p => p.IsSelected = true);
}
}
protected void ExecuteSelectChildCommand(object parameter)
{
if (parameter is MindNode node)
{
}
else
{
node = SelectedItem as MindNode;
}
if (node != null)
{
GetChildren(node).ForEach(p => p.IsSelected = true);
}
}
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
}
}