mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-28 20:23:25 +08:00
修改内部使用方法,不需要使用页面绑定的命令
This commit is contained in:
@@ -60,7 +60,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
pointList.Add(this.startPoint.Value);
|
||||
var item = new PointDesignerItemViewModel(startPoint.Value);
|
||||
item.ShowConnectors = true;
|
||||
_viewModel.DirectAddItemCommand.Execute(item);
|
||||
_viewModel.Add(item);
|
||||
pointDesignerItemViewModelList.Add(item);
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
pointList.Add(endPoint.Value);
|
||||
var item = new PointDesignerItemViewModel(endPoint.Value);
|
||||
item.ShowConnectors = true;
|
||||
_viewModel.DirectAddItemCommand.Execute(item);
|
||||
_viewModel.Add(item);
|
||||
pointDesignerItemViewModelList.Add(item);
|
||||
|
||||
UpdateSelection();
|
||||
@@ -135,7 +135,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
itemBase.PointDesignerItemViewModels.ForEach(p =>
|
||||
{
|
||||
p.ParentId = itemBase.Id;
|
||||
_viewModel.DirectAddItemCommand.Execute(p);
|
||||
_viewModel.Add(p);
|
||||
});
|
||||
}
|
||||
else if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Text)
|
||||
@@ -156,14 +156,14 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
itemBase.PointDesignerItemViewModels.ForEach(p =>
|
||||
{
|
||||
p.ParentId = itemBase.Id;
|
||||
_viewModel.DirectAddItemCommand.Execute(p);
|
||||
_viewModel.Add(p);
|
||||
});
|
||||
}
|
||||
}
|
||||
this._service.DrawModeViewModel.ResetDrawMode();
|
||||
}
|
||||
|
||||
pointDesignerItemViewModelList.ForEach(p => _viewModel.DirectRemoveItemCommand.Execute(p));
|
||||
pointDesignerItemViewModelList.ForEach(p => _viewModel.Remove(p));
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
rectangleBounds.Bottom + (rectangleBounds.Height / 2));
|
||||
partialConnection = new ConnectionViewModel(_viewModel, sourceDataItem, new PartCreatedConnectorInfo(point.X, point.Y), DrawMode, RouterMode);
|
||||
|
||||
_viewModel.DirectAddItemCommand.Execute(partialConnection);
|
||||
_viewModel.Add(partialConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -324,7 +324,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Point point = new Point(rectangleBounds.Left + (rectangleBounds.Width / 2),
|
||||
rectangleBounds.Bottom + (rectangleBounds.Height / 2));
|
||||
partialConnection = new ConnectionViewModel(_viewModel, sourceConnectorInfo, new PartCreatedConnectorInfo(point.X, point.Y), DrawMode, RouterMode);
|
||||
_viewModel.DirectAddItemCommand.Execute(partialConnection);
|
||||
_viewModel.Add(partialConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -375,7 +375,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (connectorsHit.Count == 0)
|
||||
{
|
||||
LinkPointDesignerItemViewModel pointItemView = new LinkPointDesignerItemViewModel(rubberbandSelectionStartPoint.Value);
|
||||
_viewModel.DirectAddItemCommand.Execute(pointItemView);
|
||||
_viewModel.Add(pointItemView);
|
||||
SourceConnectorInfo = pointItemView.Connectors.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
@@ -472,7 +472,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
FullyCreatedConnectorInfo sinkDataItem = sinkConnector.Info;
|
||||
|
||||
int indexOfLastTempConnection = sinkDataItem.DataItem.Root.Items.Count - 1;
|
||||
sinkDataItem.DataItem.Root.DirectRemoveItemCommand.Execute(
|
||||
sinkDataItem.DataItem.Root.Remove(
|
||||
sinkDataItem.DataItem.Root.Items[indexOfLastTempConnection]);
|
||||
sinkDataItem.DataItem.Root.AddItemCommand.Execute(new ConnectionViewModel(_viewModel, sourceDataItem, sinkDataItem, DrawMode, RouterMode));
|
||||
}
|
||||
@@ -486,8 +486,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
FullyCreatedConnectorInfo sinkDataItem = pointItemView.TopConnector;
|
||||
|
||||
int indexOfLastTempConnection = _viewModel.Items.Count - 1;
|
||||
_viewModel.DirectRemoveItemCommand.Execute(_viewModel.Items[indexOfLastTempConnection]);
|
||||
_viewModel.DirectAddItemCommand.Execute(pointItemView);
|
||||
_viewModel.Remove(_viewModel.Items[indexOfLastTempConnection]);
|
||||
_viewModel.Add(pointItemView);
|
||||
|
||||
var connector = new ConnectionViewModel(_viewModel, sourceDataItem, sinkDataItem, DrawMode, RouterMode);
|
||||
_viewModel.AddItemCommand.Execute(connector);
|
||||
@@ -499,7 +499,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
//Need to remove last item as we did not finish drawing the path
|
||||
int indexOfLastTempConnection = sourceDataItem.DataItem.Root.Items.Count - 1;
|
||||
sourceDataItem.DataItem.Root.DirectRemoveItemCommand.Execute(
|
||||
sourceDataItem.DataItem.Root.Remove(
|
||||
sourceDataItem.DataItem.Root.Items[indexOfLastTempConnection]);
|
||||
|
||||
|
||||
|
||||
@@ -648,15 +648,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _directAddItemCommand;
|
||||
public ICommand DirectAddItemCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._directAddItemCommand ?? (this._directAddItemCommand = new SimpleCommand(ExecuteEnable, ExecuteDirectAddItemCommand));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _addItemCommand;
|
||||
public ICommand AddItemCommand
|
||||
{
|
||||
@@ -666,15 +657,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _directRemoveItemCommand;
|
||||
public ICommand DirectRemoveItemCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._directRemoveItemCommand ?? (this._directRemoveItemCommand = new SimpleCommand(ExecuteEnable, ExecuteDirectRemoveItemCommand));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _removeItemCommand;
|
||||
public ICommand RemoveItemCommand
|
||||
{
|
||||
@@ -1249,28 +1231,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
protected virtual void ExecuteCreateNewDiagramCommand(object parameter)
|
||||
{
|
||||
this.Items.Clear();
|
||||
}
|
||||
|
||||
private void ExecuteDirectAddItemCommand(object parameter)
|
||||
{
|
||||
if (parameter is SelectableDesignerItemViewModelBase ite)
|
||||
{
|
||||
if (AddVerify(ite) != true) return;
|
||||
|
||||
ClearSelectedItems();
|
||||
Add(ite);
|
||||
}
|
||||
else if (parameter is IEnumerable<SelectableDesignerItemViewModelBase> items)
|
||||
{
|
||||
if (items.Select(p => AddVerify(p)).Any() != true) return;
|
||||
|
||||
ClearSelectedItems();
|
||||
foreach (var item in items)
|
||||
{
|
||||
Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteAddItemCommand(object parameter)
|
||||
{
|
||||
@@ -1316,7 +1277,27 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Add(SelectableDesignerItemViewModelBase item)
|
||||
//使用程序添加对象,比如Demo初始化
|
||||
public void Add(object parameter)
|
||||
{
|
||||
if (parameter is SelectableDesignerItemViewModelBase ite)
|
||||
{
|
||||
if (AddVerify(ite) != true) return;
|
||||
|
||||
Add(ite, false);
|
||||
}
|
||||
else if (parameter is IEnumerable<SelectableDesignerItemViewModelBase> items)
|
||||
{
|
||||
if (items.Select(p => AddVerify(p)).Any() != true) return;
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
Add(item, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Add(SelectableDesignerItemViewModelBase item, bool isSelected = true)
|
||||
{
|
||||
item.Root = this;
|
||||
item.ZIndex = Items.Any() ? Items.Max(p => p.ZIndex) + 1 : 0;
|
||||
@@ -1337,10 +1318,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
designerItemViewModelBase.SetCellAlignment();
|
||||
}
|
||||
Items.Add(item);
|
||||
item.IsSelected = true;
|
||||
item.IsSelected = isSelected;
|
||||
}
|
||||
|
||||
private void ExecuteDirectRemoveItemCommand(object parameter)
|
||||
public void Remove(object parameter)
|
||||
{
|
||||
if (parameter is SelectableDesignerItemViewModelBase ite)
|
||||
{
|
||||
@@ -1595,7 +1576,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
items.AddRange(connectors);
|
||||
DirectAddItemCommand.Execute(items);
|
||||
Add(items);
|
||||
|
||||
FixOtherInfo(items);
|
||||
}
|
||||
@@ -2490,7 +2471,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
groupItem = new GroupDesignerItemViewModel();
|
||||
}
|
||||
|
||||
DirectAddItemCommand.Execute(groupItem);
|
||||
Add(groupItem);
|
||||
|
||||
foreach (DesignerItemViewModelBase item in items)
|
||||
item.ParentId = groupItem.Id;
|
||||
|
||||
@@ -35,10 +35,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get;
|
||||
}
|
||||
ICommand DirectAddItemCommand
|
||||
{
|
||||
get;
|
||||
}
|
||||
ICommand AddItemCommand
|
||||
{
|
||||
get;
|
||||
@@ -47,10 +43,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get;
|
||||
}
|
||||
ICommand DirectRemoveItemCommand
|
||||
{
|
||||
get;
|
||||
}
|
||||
ICommand ClearSelectedItemsCommand
|
||||
{
|
||||
get;
|
||||
@@ -339,6 +331,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
void Init();
|
||||
|
||||
void Add(object parameter);
|
||||
|
||||
void Remove(object parameter);
|
||||
|
||||
bool ExecuteShortcut(KeyEventArgs e);
|
||||
|
||||
event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
Reference in New Issue
Block a user