This commit is contained in:
kwai
2023-02-27 20:18:58 +08:00
parent 298ec29dd9
commit f8c2115f03
21 changed files with 326 additions and 75 deletions

View File

@@ -3,8 +3,10 @@ using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data.Common;
using System.Linq;
using System.Reactive.Linq;
using System.Reflection.Metadata;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
@@ -836,16 +838,44 @@ namespace AIStudio.Wpf.DiagramDesigner
private bool _undoing;
private void UndoExecuted(object para)
{
Undo(para);
}
private bool Undo(object para)
{
var first = SelectedItems.OfType<DesignerItemViewModelBase>().FirstOrDefault();
if (first != null && first.IsEditing == true)
{
return false;
}
_undoing = true;
DoCommandManager.UnDo();
_undoing = false;
return true;
}
private void RedoExecuted(object para)
{
Redo(para);
}
private bool Redo(object para)
{
var first = SelectedItems.OfType<DesignerItemViewModelBase>().FirstOrDefault();
if (first != null && first.IsEditing == true)
{
return false;
}
_undoing = true;
DoCommandManager.ReDo();
_undoing = false;
return true;
}
private bool Undo_Enabled(object para)
{
return DoCommandManager.CanUnDo;
@@ -1684,6 +1714,11 @@ namespace AIStudio.Wpf.DiagramDesigner
#region
private void ExecuteCopyCommand(object parameter)
{
Copy(parameter);
}
private bool Copy(object parameter)
{
List<DesignerItemViewModelBase> selectedDesignerItems;
@@ -1696,6 +1731,15 @@ namespace AIStudio.Wpf.DiagramDesigner
}
else
{
if (SelectedItems.Count == 0)
{
return false;
}
var first = SelectedItems.OfType<DesignerItemViewModelBase>().FirstOrDefault();
if (first != null && first.IsEditing == true)
{
return false;
}
selectedDesignerItems = SelectedItems.OfType<DesignerItemViewModelBase>().ToList();
selectedConnections = SelectedItems.OfType<ConnectionViewModel>().ToList();
}
@@ -1732,16 +1776,23 @@ namespace AIStudio.Wpf.DiagramDesigner
OffsetY = 10;
System.Windows.Clipboard.Clear();
System.Windows.Clipboard.SetData(System.Windows.DataFormats.Serializable, json);
return true;
}
private void ExecutePasteCommand(object parameter)
{
Paste(parameter);
}
private bool Paste(object parameter)
{
if (System.Windows.Clipboard.ContainsData(System.Windows.DataFormats.Serializable))
{
string clipboardData = System.Windows.Clipboard.GetData(System.Windows.DataFormats.Serializable) as String;
if (string.IsNullOrEmpty(clipboardData))
return;
return false;
try
{
List<SelectableDesignerItemViewModelBase> items = new List<SelectableDesignerItemViewModelBase>();
@@ -1816,6 +1867,12 @@ namespace AIStudio.Wpf.DiagramDesigner
{
System.Windows.MessageBox.Show(e.StackTrace, e.Message, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
}
return true;
}
else
{
return false;
}
}
@@ -1831,13 +1888,27 @@ namespace AIStudio.Wpf.DiagramDesigner
private void ExecuteCutCommand(object parameter)
{
ExecutePasteCommand(null);
Cut(parameter);
}
private bool Cut(object parameter)
{
if (Paste(null) == false)
return false;
OffsetX = 0;
OffsetY = 0;
ExecuteDeleteCommand(null);
if (Delete(null) == false)
return false;
return true;
}
private void ExecuteDeleteCommand(object parameter)
{
Delete(parameter);
}
private bool Delete(object parameter)
{
List<SelectableDesignerItemViewModelBase> itemsToRemove;
@@ -1847,6 +1918,15 @@ namespace AIStudio.Wpf.DiagramDesigner
}
else
{
if (SelectedItems.Count == 0)
{
return false;
}
var first = SelectedItems.OfType<DesignerItemViewModelBase>().FirstOrDefault();
if (first != null && first.IsEditing == true)
{
return false;
}
itemsToRemove = SelectedItems.OfType<SelectableDesignerItemViewModelBase>().ToList();
}
@@ -1868,6 +1948,8 @@ namespace AIStudio.Wpf.DiagramDesigner
itemsToRemove.AddRange(connectionsToAlsoRemove);
RemoveItemCommand.Execute(itemsToRemove);
return true;
}
#endregion
@@ -2119,33 +2201,27 @@ namespace AIStudio.Wpf.DiagramDesigner
}
else if (DiagramOption.ShortcutOption.Copy(e))
{
CopyCommand.Execute(null);
return true;
return Copy(null);
}
else if (DiagramOption.ShortcutOption.Paste(e))
{
PasteCommand.Execute(null);
return true;
return Paste(null);
}
else if (DiagramOption.ShortcutOption.Cut(e))
{
CutCommand.Execute(null);
return true;
return Cut(null);
}
else if (DiagramOption.ShortcutOption.Undo(e))
{
UndoCommand.Execute(null);
return true;
return Undo(null);
}
else if (DiagramOption.ShortcutOption.Redo(e))
{
RedoCommand.Execute(null);
return true;
return Redo(null);
}
else if (DiagramOption.ShortcutOption.Delete(e))
{
DeleteCommand.Execute(null);
return true;
return Delete(null);
}
else if (DiagramOption.ShortcutOption.LeftMove(e))
{