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

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AIStudio.Wpf.DiagramDesigner
{
class DoCommandManager
public class DoCommandManager
{
#region Command定义
public class Command
@@ -24,9 +24,18 @@ namespace AIStudio.Wpf.DiagramDesigner
this.clearAction = clearAction;
}
internal void Do() { action(); }
internal void UnDo() { unDoAction(); }
internal void Clear() { if (clearAction != null) clearAction(); }
internal void Do()
{
action();
}
internal void UnDo()
{
unDoAction();
}
internal void Clear()
{
if (clearAction != null) clearAction();
}
public override string ToString()
{
@@ -35,35 +44,57 @@ namespace AIStudio.Wpf.DiagramDesigner
}
#endregion
public Stack<Command> ReDoActionStack { get; private set; }
public Stack<Command> UnDoActionStack { get; private set; }
public Stack<Command> ReDoActionStack
{
get; private set;
}
public Stack<Command> UnDoActionStack
{
get; private set;
}
public int Capacity { get; set; } = 10;
public DoCommandManager()
{
Init();
}
public void Init()
{
ReDoActionStack = new Stack<Command>();
UnDoActionStack = new Stack<Command>();
}
private bool _undoing;
public void DoNewCommand(string name, Action action, Action unDoAction, Action clearAction = null, bool doit = true)
{
if (UnDoActionStack.Count >= Capacity)
{
//清理
var clear = UnDoActionStack.LastOrDefault();
clear.Clear();
UnDoActionStack = new Stack<Command>(UnDoActionStack.Take(Capacity - 1).Reverse());
}
var cmd = new Command(name, action, unDoAction, clearAction);
UnDoActionStack.Push(cmd);
ReDoActionStack.Clear();
if (doit)
if (_undoing == true) return;
try
{
cmd.Do();
_undoing = true;
if (UnDoActionStack.Count >= Capacity)
{
//清理
var clear = UnDoActionStack.LastOrDefault();
clear.Clear();
UnDoActionStack = new Stack<Command>(UnDoActionStack.Take(Capacity - 1).Reverse());
}
var cmd = new Command(name, action, unDoAction, clearAction);
UnDoActionStack.Push(cmd);
ReDoActionStack.Clear();
if (doit)
{
cmd.Do();
}
}
finally
{
_undoing = false;
}
}
@@ -72,9 +103,19 @@ namespace AIStudio.Wpf.DiagramDesigner
if (!CanUnDo)
return;
var cmd = UnDoActionStack.Pop();
ReDoActionStack.Push(cmd);
cmd.UnDo();
if (_undoing == true) return;
try
{
_undoing = true;
var cmd = UnDoActionStack.Pop();
ReDoActionStack.Push(cmd);
cmd.UnDo();
}
finally
{
_undoing = false;
}
}
public void ReDo()
@@ -82,13 +123,34 @@ namespace AIStudio.Wpf.DiagramDesigner
if (!CanReDo)
return;
var cmd = ReDoActionStack.Pop();
UnDoActionStack.Push(cmd);
cmd.Do();
if (_undoing == true) return;
try
{
_undoing = true;
var cmd = ReDoActionStack.Pop();
UnDoActionStack.Push(cmd);
cmd.Do();
}
finally
{
_undoing = false;
}
}
public bool CanUnDo { get { return UnDoActionStack.Count != 0; } }
public bool CanReDo { get { return ReDoActionStack.Count != 0; } }
public bool CanUnDo
{
get
{
return UnDoActionStack.Count != 0;
}
}
public bool CanReDo
{
get
{
return ReDoActionStack.Count != 0;
}
}
//public IEnumerable<Command> Actions { get { return ReDoActionStack.Reverse().Concat(UnDoActionStack); } }
}
}