Files
aistudio-wpf-diagram/AIStudio.Wpf.DiagramDesigner/ViewModels/BlockViewModel/BlockDiagramViewModel.cs

141 lines
4.1 KiB
C#
Raw Normal View History

2023-06-19 15:47:39 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2023-06-20 13:46:26 +08:00
using System.Windows.Controls;
2023-06-19 15:47:39 +08:00
using System.Windows.Input;
namespace AIStudio.Wpf.DiagramDesigner
{
2023-06-20 13:46:26 +08:00
public class BlockDiagramViewModel : DiagramViewModel, IBlockDiagramViewModel
2023-06-19 15:47:39 +08:00
{
public BlockDiagramViewModel()
{
}
#region
private ICommand _addNextCommand;
public ICommand AddNextCommand
{
get
{
return this._addNextCommand ?? (this._addNextCommand = new SimpleCommand(ExecuteEnable, this.ExecutedAddNextCommand));
}
}
private ICommand _removeNextCommand;
public ICommand RemoveNextCommand
{
get
{
return this._removeNextCommand ?? (this._removeNextCommand = new SimpleCommand(ExecuteEnable, this.ExecutedRemoveNextCommand));
}
}
private ICommand _addChildCommand;
public ICommand AddChildCommand
{
get
{
return this._addChildCommand ?? (this._addChildCommand = new SimpleCommand(ExecuteEnable, this.ExecutedAddChildCommand));
}
}
private ICommand _removeChildCommand;
public ICommand RemoveChildCommand
{
get
{
return this._removeChildCommand ?? (this._removeChildCommand = new SimpleCommand(ExecuteEnable, this.ExecutedRemoveChildCommand));
}
}
#endregion
#region Block使用
private void ExecutedAddNextCommand(object parameter)
{
2023-06-20 13:46:26 +08:00
if (parameter is BlockNextPara blockItemPara)
2023-06-19 15:47:39 +08:00
{
2023-06-20 13:46:26 +08:00
DoCommandManager.DoNewCommand(this.ToString(),
() => {
blockItemPara.Item.AddNext(blockItemPara.Next);
},
() => {
blockItemPara.Item.RemoveNext();
});
2023-06-19 15:47:39 +08:00
}
}
private void ExecutedRemoveNextCommand(object parameter)
{
2023-06-20 13:46:26 +08:00
if (parameter is BlockNextPara blockItemPara)
{
DoCommandManager.DoNewCommand(this.ToString(),
() => {
blockItemPara.Item.RemoveNext();
},
() => {
blockItemPara.Item.AddNext(blockItemPara.Next);
});
}
2023-06-19 15:47:39 +08:00
}
private void ExecutedAddChildCommand(object parameter)
{
2023-06-20 13:46:26 +08:00
if (parameter is BlockContainerPara blockContainerPara)
{
DoCommandManager.DoNewCommand(this.ToString(),
() => {
blockContainerPara.Item.AddChild(blockContainerPara.Child, blockContainerPara.Container);
},
() => {
blockContainerPara.Item.RemoveChild(blockContainerPara.Child, blockContainerPara.Container);
});
}
2023-06-19 15:47:39 +08:00
}
private void ExecutedRemoveChildCommand(object parameter)
{
2023-06-20 13:46:26 +08:00
if (parameter is BlockContainerPara blockContainerPara)
{
DoCommandManager.DoNewCommand(this.ToString(),
() => {
blockContainerPara.Item.RemoveChild(blockContainerPara.Child, blockContainerPara.Container);
},
() => {
blockContainerPara.Item.AddChild(blockContainerPara.Child, blockContainerPara.Container);
});
}
2023-06-19 15:47:39 +08:00
}
#endregion
}
2023-06-20 13:46:26 +08:00
public class BlockNextPara
{
public BlockDesignerItemViewModel Item
{
get; set;
}
public BlockDesignerItemViewModel Next
{
get;set;
}
}
public class BlockContainerPara
{
public BlockDesignerItemViewModel Item
{
get; set;
}
public BlockDesignerItemViewModel Child
{
get; set;
}
public BlockItemsContainerInfo Container
{
get; set;
}
}
2023-06-19 15:47:39 +08:00
}