mind序列化完善中

This commit is contained in:
艾竹
2023-03-08 23:02:50 +08:00
parent c80923d19c
commit e4f6335224
11 changed files with 74 additions and 40 deletions

View File

@@ -119,7 +119,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
private void GetDataExcute(object obj)
{
OutputData = GetDataFunc();
OutputData = GetDataFunc?.Invoke();
}
private void SetDataExcute(object obj)

View File

@@ -81,7 +81,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
private void GetDataExcute(object obj)
{
OutputData = GetDataFunc();
OutputData = GetDataFunc?.Invoke();
}
private void SetDataExcute(object obj)

View File

@@ -784,7 +784,7 @@ namespace AIStudio.Wpf.DiagramDesigner
}
private SimpleCommand _deleteCommand;
public SimpleCommand DeleteCommand
public virtual SimpleCommand DeleteCommand
{
get
{
@@ -955,7 +955,7 @@ namespace AIStudio.Wpf.DiagramDesigner
}
#endregion
public DoCommandManager DoCommandManager = new DoCommandManager();
protected DoCommandManager DoCommandManager = new DoCommandManager();
public event DiagramEventHandler Event;
@@ -989,6 +989,13 @@ namespace AIStudio.Wpf.DiagramDesigner
PhysicalGridMarginSize = diagramItem.PhysicalGridMarginSize;
GridColor = diagramItem.GridColor;
AllowDrop = diagramItem.AllowDrop;
Init();
}
public virtual void Init()
{
DoCommandManager.Init();
}
public virtual bool ExecuteEnable(object para)
@@ -2087,12 +2094,12 @@ namespace AIStudio.Wpf.DiagramDesigner
return true;
}
private void ExecuteDeleteCommand(object parameter)
protected void ExecuteDeleteCommand(object parameter)
{
Delete(parameter);
}
private bool Delete(object parameter)
protected virtual bool Delete(object parameter)
{
List<SelectableDesignerItemViewModelBase> itemsToRemove;

View File

@@ -329,6 +329,8 @@ namespace AIStudio.Wpf.DiagramDesigner
}
#endregion
void Init();
bool ExecuteShortcut(KeyEventArgs e);
event PropertyChangedEventHandler PropertyChanged;

View File

@@ -18,7 +18,7 @@
<RowDefinition/>
</Grid.RowDefinitions>
<!-- ToolBox Control -->
<ContentControl Template="{Binding ToolBox,RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/>
<ContentControl x:Name="PART_ContentControl" Template="{Binding ToolBox,RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/>
<ScrollViewer Grid.Row="1">
<!-- Diagram Control -->

View File

@@ -11,6 +11,7 @@ using System.Xml.Linq;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.DiagramDesigner.Geometrys;
using AIStudio.Wpf.Mind.ViewModels;
using AIStudio.Wpf.DiagramModels;
namespace AIStudio.Wpf.Mind.Controls
{
@@ -18,10 +19,13 @@ namespace AIStudio.Wpf.Mind.Controls
/// MindEditor.xaml 的交互逻辑
/// </summary>
[TemplatePart(Name = PART_DiagramControl, Type = typeof(DiagramControl))]
[TemplatePart(Name = PART_ContentControl, Type = typeof(ContentControl))]
public partial class MindEditor : UserControl
{
public const string PART_DiagramControl = "PART_DiagramControl";
public const string PART_ContentControl = "PART_ContentControl";
private DiagramControl _diagramControl;
private ContentControl _contentControl;
private MindDiagramViewModel _diagramViewModel;
@@ -47,7 +51,10 @@ namespace AIStudio.Wpf.Mind.Controls
_diagramControl = GetTemplateChild(PART_DiagramControl) as DiagramControl;
_diagramControl.HorizontalAlignment = HorizontalAlignment.Stretch;
_diagramControl.VerticalAlignment = VerticalAlignment.Stretch;
this.DataContext = _diagramViewModel;
_diagramControl.DataContext = _diagramViewModel;
_contentControl = GetTemplateChild(PART_ContentControl) as ContentControl;
_contentControl.DataContext = _diagramViewModel;
GetDataFunc = GetData;
}
@@ -90,14 +97,13 @@ namespace AIStudio.Wpf.Mind.Controls
private void CreateFlowchartModel(string json)
{
//_diagramViewModel.IsLoading = true;
//_diagramViewModel.Items.Clear();
//MindNode level1node = new MindNode(_diagramViewModel) { Text = "思维导图" };
//_diagramViewModel.DirectAddItemCommand.Execute(level1node);
//level1node.Left = 200;
//level1node.Top = 200;
//_diagramViewModel.DoCommandManager.Init();
//_diagramViewModel.IsLoading = false;
_diagramViewModel.IsLoading = true;
_diagramViewModel.Items.Clear();
_diagramViewModel.ToObject(json);
_diagramViewModel.Init();
_diagramViewModel.IsLoading = false;
}
public static readonly DependencyProperty GetDataFuncProperty =

View File

@@ -85,7 +85,7 @@
<TextBlock>编辑</TextBlock>
</StackPanel>
</Button>
<Button Style="{StaticResource FlatButtonStyle}" Grid.Column="4" Command="{Binding DeleteSelfCommand}" Height="22" Grid.RowSpan="2" VerticalAlignment="Bottom">
<Button Style="{StaticResource FlatButtonStyle}" Grid.Column="4" Command="{Binding DeleteCommand}" Height="22" Grid.RowSpan="2" VerticalAlignment="Bottom">
<StackPanel Orientation="Horizontal">
<Path Width="12" Height="12" Stretch="Uniform" Fill="Black" Data="M 25.3333,23.75L 50.6667,23.75C 51.5411,23.75 51.8541,27.3125 51.8541,27.3125L 24.1458,27.3125C 24.1458,27.3125 24.4589,23.75 25.3333,23.75 Z M 35.625,19.7917L 40.375,19.7917C 40.8122,19.7917 41.9583,20.9378 41.9583,21.375C 41.9583,21.8122 40.8122,22.9584 40.375,22.9584L 35.625,22.9584C 35.1878,22.9584 34.0416,21.8122 34.0416,21.375C 34.0416,20.9378 35.1878,19.7917 35.625,19.7917 Z M 27.7083,28.5L 48.2916,28.5C 49.1661,28.5 49.875,29.2089 49.875,30.0834L 48.2916,53.8334C 48.2916,54.7078 47.5828,55.4167 46.7083,55.4167L 29.2917,55.4167C 28.4172,55.4167 27.7083,54.7078 27.7083,53.8334L 26.125,30.0834C 26.125,29.2089 26.8339,28.5 27.7083,28.5 Z M 30.0833,31.6667L 30.4792,52.25L 33.25,52.25L 32.8542,31.6667L 30.0833,31.6667 Z M 36.4167,31.6667L 36.4167,52.25L 39.5833,52.25L 39.5833,31.6667L 36.4167,31.6667 Z M 43.1458,31.6667L 42.75,52.25L 45.5208,52.25L 45.9167,31.6667L 43.1458,31.6667 Z "></Path>
<TextBlock>删除</TextBlock>

View File

@@ -1,4 +1,5 @@
using System.Windows;
using System.Collections.Generic;
using System.Windows;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.DiagramModels;
using AIStudio.Wpf.DiagramModels.ViewModels;
@@ -33,7 +34,6 @@ namespace AIStudio.Wpf.Flowchart.Models
mindNode.Spacing = Spacing;
mindNode.Offset = Offset;
mindNode.IsExpanded = IsExpanded;
return mindNode;
}

View File

@@ -34,11 +34,6 @@ namespace AIStudio.Wpf.Mind.ViewModels
get;
}
SimpleCommand DeleteSelfCommand
{
get;
}
SimpleCommand MoveForwardCommand
{
get;

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Documents;
using AIStudio.Wpf.DiagramDesigner;
namespace AIStudio.Wpf.Mind.ViewModels
@@ -61,15 +62,6 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _deleteSelfCommand;
public SimpleCommand DeleteSelfCommand
{
get
{
return this._deleteSelfCommand ?? (this._deleteSelfCommand = new SimpleCommand(MindLevelEnable, ExecuteDeleteSelfCommand));
}
}
private SimpleCommand _moveForwardCommand;
public SimpleCommand MoveForwardCommand
{
@@ -88,6 +80,15 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _deleteCommand;
public override SimpleCommand DeleteCommand
{
get
{
return this._deleteCommand ?? (this._deleteCommand = new SimpleCommand(MindLevelEnable, ExecuteDeleteCommand));
}
}
private SimpleCommand _changeMindTypeCommand;
public SimpleCommand ChangeMindTypeCommand
{
@@ -162,6 +163,22 @@ namespace AIStudio.Wpf.Mind.ViewModels
#endregion
public MindDiagramViewModel()
{
}
public override void Init()
{
if (Items.Count == 0)
{
InitRootItem();
}
GetChildren(RootItem);
RootItem?.LayoutUpdated();
base.Init();
}
public void InitRootItem()
{
MindNode level1node = new MindNode(this) { Root = this, Id = Guid.NewGuid(), Left = 200, Top = 200, Text = "思维导图" };
level1node.InitLayout(true);
@@ -392,7 +409,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
private void ExecuteDeleteSelfCommand(object parameter)
protected override bool Delete(object parameter)
{
if (parameter is MindNode node)
{
@@ -403,6 +420,11 @@ namespace AIStudio.Wpf.Mind.ViewModels
node = SelectedItem as MindNode;
}
if (node.IsEditing == true)
{
return false;
}
if (node.Parent is MindNode parent)
{
int index = parent.Children.IndexOf(node);
@@ -415,7 +437,11 @@ namespace AIStudio.Wpf.Mind.ViewModels
parent.AddChild(node, index);
parent.LayoutUpdated();
});
return true;
}
else
return false;
}
@@ -467,8 +493,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
#endregion
protected override void ExecutedInitLayoutCommand(object obj)
{
GetChildren(RootItem);
RootItem?.LayoutUpdated();
}
protected override void ExecutedResetLayoutCommand(object obj)
{

View File

@@ -59,7 +59,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
AddChildCommand = (Root as IMindDiagramViewModel)?.AddChildCommand;
AddParentCommand = (Root as IMindDiagramViewModel)?.AddParentCommand;
AddPeerCommand = (Root as IMindDiagramViewModel)?.AddPeerCommand;
DeleteSelfCommand = (Root as IMindDiagramViewModel)?.DeleteSelfCommand;
DeleteCommand = (Root as IMindDiagramViewModel)?.DeleteCommand;
MoveForwardCommand = (Root as IMindDiagramViewModel)?.MoveForwardCommand;
MoveBackCommand = (Root as IMindDiagramViewModel)?.MoveBackCommand;
BuildMenuOptions();
@@ -97,7 +97,6 @@ namespace AIStudio.Wpf.Mind.ViewModels
mindNodeModel.Spacing = Spacing;
mindNodeModel.Offset = Offset;
mindNodeModel.IsExpanded = IsExpanded;
return mindNodeModel;
}
@@ -309,7 +308,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
get; private set;
}
public SimpleCommand DeleteSelfCommand
public SimpleCommand DeleteCommand
{
get; private set;
}
@@ -356,7 +355,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
menuOptions.Add(menuItem);
menuItem = new CinchMenuItem();
menuItem.Text = "删除";
menuItem.Command = DeleteSelfCommand;
menuItem.Command = DeleteCommand;
menuItem.CommandParameter = this;
menuOptions.Add(menuItem);
}