commit b8246693780550a28c6dd45701291918795d0809 Author: veroxzik <43590004+veroxzik@users.noreply.github.com> Date: Wed Nov 2 21:31:00 2022 -0400 Deleting a hold end will turn the previous joint into the end. commit 597510e605b8687fb004d55245e1c10edf3c8ab6 Author: veroxzik <43590004+veroxzik@users.noreply.github.com> Date: Tue Nov 1 23:01:15 2022 -0400 Fix undo/redo for RemoveHold operations. commit 40936e13d4bcb66ae24573c5860b79714ee38b32 Author: veroxzik <43590004+veroxzik@users.noreply.github.com> Date: Sun Oct 30 17:33:21 2022 -0400 Fix undo/redo for InsertHold operations.
74 lines
2.0 KiB
C#
74 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BAKKA_Editor.Operations
|
|
{
|
|
internal class OperationManager
|
|
{
|
|
public event EventHandler? OperationHistoryChanged;
|
|
public event EventHandler? ChangesCommitted;
|
|
|
|
protected Stack<IOperation> UndoStack { get; } = new Stack<IOperation>();
|
|
protected Stack<IOperation> RedoStack { get; } = new Stack<IOperation>();
|
|
|
|
private IOperation? LastCommittedOperation { get; set; } = null;
|
|
|
|
public IEnumerable<string> UndoOperationsDescription
|
|
{
|
|
get { return UndoStack.Select(p => p.Description); }
|
|
}
|
|
|
|
public IEnumerable<string> RedoOperationsDescription
|
|
{
|
|
get { return RedoStack.Select(p => p.Description); }
|
|
}
|
|
|
|
public bool CanUndo { get { return UndoStack.Count > 0; } }
|
|
|
|
public bool CanRedo { get { return RedoStack.Count > 0; } }
|
|
|
|
public void Push(IOperation op)
|
|
{
|
|
UndoStack.Push(op);
|
|
RedoStack.Clear();
|
|
OperationHistoryChanged?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
|
|
public void InvokeAndPush(IOperation op)
|
|
{
|
|
op.Redo();
|
|
Push(op);
|
|
}
|
|
|
|
public IOperation Undo()
|
|
{
|
|
IOperation op = UndoStack.Pop();
|
|
op.Undo();
|
|
var type = op.GetType();
|
|
RedoStack.Push(op);
|
|
OperationHistoryChanged?.Invoke(this, EventArgs.Empty);
|
|
return op;
|
|
}
|
|
|
|
public IOperation Redo()
|
|
{
|
|
IOperation op = RedoStack.Pop();
|
|
op.Redo();
|
|
UndoStack.Push(op);
|
|
OperationHistoryChanged?.Invoke(this, EventArgs.Empty);
|
|
return op;
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
UndoStack.Clear();
|
|
RedoStack.Clear();
|
|
LastCommittedOperation = null;
|
|
OperationHistoryChanged?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
}
|