Mind Editoe

This commit is contained in:
艾竹
2023-03-05 21:30:53 +08:00
parent 9061146139
commit 79f4896fbd
41 changed files with 2090 additions and 484 deletions

View File

@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AIStudio.Wpf.DiagramDesigner;
namespace AIStudio.Wpf.Mind.ViewModels
{
public interface IMindDiagramViewModel : IDiagramViewModel
{
MindType MindType
{
get;set;
}
SimpleCommand AddParentCommand
{
get;
}
SimpleCommand AddChildCommand
{
get;
}
SimpleCommand AddPeerCommand
{
get;
}
SimpleCommand DeleteSelfCommand
{
get;
}
SimpleCommand MoveForwardCommand
{
get;
}
SimpleCommand MoveBackCommand
{
get;
}
SimpleCommand ChangeMindTypeCommand
{
get;
}
SimpleCommand ChangeMindThemeCommand
{
get;
}
}
}

View File

@@ -0,0 +1,382 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AIStudio.Wpf.DiagramDesigner;
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);
}
}
}
#endregion
#region
public SimpleCommand AddParentCommand
{
get; private set;
}
public SimpleCommand AddChildCommand
{
get; private set;
}
public SimpleCommand AddPeerCommand
{
get; private set;
}
public SimpleCommand DeleteSelfCommand
{
get; private set;
}
public SimpleCommand MoveForwardCommand
{
get; private set;
}
public SimpleCommand MoveBackCommand
{
get; private set;
}
private SimpleCommand _changeMindTypeCommand;
public SimpleCommand ChangeMindTypeCommand
{
get
{
return this._changeMindTypeCommand ?? (this._changeMindTypeCommand = new SimpleCommand(MindExecuteEnable, this.ExecutedChangeMindTypeCommand));
}
}
public SimpleCommand ChangeMindThemeCommand
{
get; private set;
}
public SimpleCommand ResetLayout
{
get; private set;
}
public SimpleCommand Expand2Level1
{
get; private set;
}
public SimpleCommand Expand2Level2
{
get; private set;
}
public SimpleCommand Expand2Level3
{
get; private set;
}
public SimpleCommand Expand2Level4
{
get; private set;
}
public SimpleCommand Expand2Level5
{
get; private set;
}
public SimpleCommand Expand2Level6
{
get; private set;
}
#endregion
public MindDiagramViewModel()
{
AddChildCommand = new SimpleCommand(MindExecuteEnable, ExecuteAddChildCommand);
AddParentCommand = new SimpleCommand(MindLevelEnable, ExecuteAddParentCommand);
AddPeerCommand = new SimpleCommand(MindLevelEnable, ExecuteAddPeerCommand);
DeleteSelfCommand = new SimpleCommand(MindLevelEnable, ExecuteDeleteSelfCommand);
MoveForwardCommand = new SimpleCommand(MindExecuteEnable, ExecuteMoveForwardCommand);
MoveBackCommand = new SimpleCommand(MindExecuteEnable, ExecuteMoveBackCommand);
}
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 != NodeLevel.Level1;
}
#region
private void ExecutedChangeMindTypeCommand(object obj)
{
if (obj is MindType mindType)
{
Items.OfType<MindNode>().ToList().ForEach(item => { item.MindType = mindType; });
Items.OfType<MindNode>().FirstOrDefault()?.LayoutUpdated();
}
}
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)
{
var node = new MindNode(this, (NodeLevel)Math.Min((int)parent.NodeLevel + 1, (int)NodeLevel.Level3), this.MindType) { Text = "分支主题" };
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;
}
if (items?.Count == 0)
{
items.Add(new MindNode(this, node.NodeLevel, this.MindType) { Text = "分支主题" });
}
if (node.Parent is MindNode parent)
{
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();
});
}
}
public void ExecuteAddPeerCommand(object parameter)
{
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 (items?.Count == 0)
{
var node = new MindNode(this, pear.NodeLevel, this.MindType) { Text = "分支主题" };
items.Add(node);
}
if (pear.Parent is MindNode parent)
{
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();
}
});
}
}
private void ExecuteDeleteSelfCommand(object parameter)
{
if (parameter is MindNode node)
{
}
else
{
node = SelectedItem as MindNode;
}
if (node.Parent is MindNode parent)
{
int index = parent.Children.IndexOf(node);
DoCommandManager.DoNewCommand(this.ToString(),
() => {
parent.RemoveChild(node, true);
parent.LayoutUpdated();
},
() => {
parent.AddChild(node, index);
parent.LayoutUpdated();
});
}
}
#endregion
}
}

View File

@@ -20,6 +20,7 @@ using AIStudio.Wpf.Flowchart.Models;
using AIStudio.Wpf.Mind.Helpers;
using AIStudio.Wpf.Mind.Models;
namespace AIStudio.Wpf.Mind.ViewModels
{
public class MindNode : DiagramItemViewModel
@@ -31,20 +32,19 @@ namespace AIStudio.Wpf.Mind.ViewModels
public MindNode(IDiagramViewModel root, NodeLevel nodeLevel, MindType mindType = MindType.Mind) : base(root)
{
NodeLevel = nodeLevel;
MindType = mindType;
MindType = mindType;
InitLayout();
MindLayout.Appearance(this);
InitLayout(true);
}
public MindNode(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
{
InitLayout();
InitLayout(false);
}
public MindNode(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
{
InitLayout();
InitLayout(false);
}
public override SelectableItemBase GetSerializableObject()
@@ -58,21 +58,25 @@ namespace AIStudio.Wpf.Mind.ViewModels
EnabledForConnection = false;
AddChildCommand = new SimpleCommand(Command_Enable, ExecuteAddChildCommand);
AddParentCommand = new SimpleCommand(Level_Enable, ExecuteAddParentCommand);
AddPeerCommand = new SimpleCommand(Level_Enable, ExecuteAddPeerCommand);
DeleteCommand = new SimpleCommand(Level_Enable, ExecuteDeleteCommand);
MoveForwardCommand = new SimpleCommand(Command_Enable, ExecuteMoveForwardCommand);
MoveBackCommand = new SimpleCommand(Command_Enable, ExecuteMoveBackCommand);
AddChildCommand = (Root as IMindDiagramViewModel)?.AddChildCommand;
AddParentCommand = (Root as IMindDiagramViewModel)?.AddParentCommand;
AddPeerCommand = (Root as IMindDiagramViewModel)?.AddPeerCommand;
DeleteSelfCommand = (Root as IMindDiagramViewModel)?.DeleteSelfCommand;
MoveForwardCommand = (Root as IMindDiagramViewModel)?.MoveForwardCommand;
MoveBackCommand = (Root as IMindDiagramViewModel)?.MoveBackCommand;
BuildMenuOptions();
this.PropertyChanged += this.Item_PropertyChanged;
}
protected void InitLayout()
protected void InitLayout(bool initAppearance)
{
var layout = GlobalType.AllTypes.Where(p => typeof(IMindLayout).IsAssignableFrom(p)).FirstOrDefault(p => p.Name == MindType.ToString() + "Layout");
MindLayout = layout != null ? (System.Activator.CreateInstance(layout) as IMindLayout) : new MindLayout();
if (initAppearance)
{
MindLayout.Appearance(this);
}
this.PropertyChanged += this.Item_PropertyChanged;
}
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)
@@ -103,8 +107,6 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
private bool Level_Enable(object obj)
{
if (Command_Enable(obj) == false) return false;
@@ -115,7 +117,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
#region
public IMindLayout MindLayout
{
get;set;
get; set;
}
[Browsable(false)]
private NodeLevel _nodeLevel;
@@ -130,6 +132,29 @@ namespace AIStudio.Wpf.Mind.ViewModels
SetProperty(ref _nodeLevel, value);
}
}
//public MindNode ParentNode
//{
// get
// {
// return Parent as MindNode;
// }
//}
//public int NodeLevel
//{
// get
// {
// if (ParentNode == null)
// {
// return 0;
// }
// else
// {
// return ParentNode.NodeLevel + 1;
// }
// }
//}
private MindType _mindType;
public MindType MindType
@@ -142,7 +167,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
{
SetProperty(ref _mindType, value);
}
}
}
private bool _isExpanded = true;
public bool IsExpanded
@@ -214,7 +239,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
public bool LayoutUpdating
{
get;set;
get; set;
}
#endregion
@@ -314,7 +339,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
get; private set;
}
public SimpleCommand DeleteCommand
public SimpleCommand DeleteSelfCommand
{
get; private set;
}
@@ -337,136 +362,37 @@ namespace AIStudio.Wpf.Mind.ViewModels
CinchMenuItem menuItem = new CinchMenuItem();
menuItem.Text = "下级";
menuItem.Command = AddChildCommand;
menuItem.CommandParameter = this;
menuOptions.Add(menuItem);
menuItem = new CinchMenuItem();
menuItem.Text = "同级";
menuItem.Command = AddPeerCommand;
menuItem.CommandParameter = this;
menuOptions.Add(menuItem);
menuItem = new CinchMenuItem();
menuItem.Text = "上级";
menuItem.Command = AddParentCommand;
menuItem.CommandParameter = this;
menuOptions.Add(menuItem);
menuItem = new CinchMenuItem();
menuItem.Text = "前移";
menuItem.Command = MoveForwardCommand;
menuItem.CommandParameter = this;
menuOptions.Add(menuItem);
menuItem = new CinchMenuItem();
menuItem.Text = "后移";
menuItem.Command = MoveBackCommand;
menuItem.CommandParameter = this;
menuOptions.Add(menuItem);
menuItem = new CinchMenuItem();
menuItem.Text = "删除";
menuItem.Command = DeleteCommand;
menuItem.Command = DeleteSelfCommand;
menuItem.CommandParameter = this;
menuOptions.Add(menuItem);
}
#endregion
#region
public void ExecuteAddChildCommand(object obj)
{
if (obj is MindNode node)
{
}
else
{
node = new MindNode(Root, (NodeLevel)Math.Min((int)NodeLevel + 1, (int)NodeLevel.Level3), this.MindType) { Text = "分支主题" };
}
AddChild(node);
LayoutUpdated();
}
public void ExecuteAddParentCommand(object obj)
{
if (Parent is MindNode parent)
{
if (obj is MindNode node)
{
}
else
{
if (NodeLevel == NodeLevel.Level1)
{
return;
}
else if (NodeLevel == NodeLevel.Level2)
node = new MindNode(Root, NodeLevel.Level2, this.MindType) { Text = "分支主题" };
else
node = new MindNode(Root, NodeLevel.Level3, this.MindType) { Text = "分支主题" };
}
parent.RemoveChild(this);
int index = parent.Children.IndexOf(this);
parent.AddChild(node, index + 1);
node.AddChild(this);
LayoutUpdated();
}
}
public void ExecuteAddPeerCommand(object obj)
{
if (Parent is MindNode parent)
{
if (obj is MindNode node)
{
}
else
{
if (NodeLevel == NodeLevel.Level1)
{
return;
}
else if (NodeLevel == NodeLevel.Level2)
node = new MindNode(Root, NodeLevel.Level2, this.MindType) { Text = "分支主题" };
else
node = new MindNode(Root, NodeLevel.Level3, this.MindType) { Text = "分支主题" };
}
int index = parent.Children.IndexOf(this);
parent.AddChild(node, index + 1);
LayoutUpdated();
}
}
private void ExecuteMoveBackCommand(object obj)
{
if (Parent is MindNode parent)
{
int index = parent.Children.IndexOf(this);
if (index < parent.Children.Count - 1)
{
parent.RemoveChild(this);
parent.AddChild(this, index + 1);
LayoutUpdated();
}
}
}
private void ExecuteMoveForwardCommand(object obj)
{
if (Parent is MindNode parent)
{
int index = parent.Children.IndexOf(this);
if (index > 0)
{
parent.RemoveChild(this);
parent.AddChild(this, index - 1);
LayoutUpdated();
}
}
}
private void ExecuteDeleteCommand(object obj)
{
if (Parent is MindNode parent)
{
parent.RemoveChild(this, true);
LayoutUpdated();
}
}
#region
public void AddChild(MindNode item, int index = -1)
{
if (this.NodeLevel == NodeLevel.Level1)
@@ -486,13 +412,10 @@ namespace AIStudio.Wpf.Mind.ViewModels
this.Children.Add(item);
}
item.Parent = this;
Root?.DirectAddItemCommand.Execute(item);
ConnectionViewModel connector = MindLayout?.GetConnectionViewModel(this, item);
Root?.DirectAddItemCommand.Execute(connector);
Root?.ClearSelectedItemsCommand.Execute(new SelectableDesignerItemViewModelBase[] { connector });
Root?.BringForwardCommand.Execute(new DesignerItemViewModelBase[] { item });
Root?.DirectAddItemCommand.Execute(new SelectableDesignerItemViewModelBase[] { item, connector });
connector.ZIndex = -1;
this.IsSelected = true;
}
public void RemoveChild(MindNode item, bool removeall = false)
@@ -535,17 +458,9 @@ namespace AIStudio.Wpf.Mind.ViewModels
case nameof(NodeLevel):
MindLayout?.Appearance(this);
break;
//case nameof(MindType):
// if (NodeLevel == NodeLevel.Level1)
// {
// MindLayout?.Appearance(this);
// LayoutUpdated();
// }
// else
// {
// GetLevel1Node().MindType = MindType;
// }
// break;
case nameof(MindType):
InitLayout(true);
break;
case nameof(Left):
{
if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs)
@@ -625,7 +540,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
#endregion
}
public class LinkInfo : BindableBase
{
private string _url;