第一次提交至Git
This commit is contained in:
78
UTS_Core/Undo/CommandManager.vb
Normal file
78
UTS_Core/Undo/CommandManager.vb
Normal file
@@ -0,0 +1,78 @@
|
||||
Namespace Undo
|
||||
Public Class CommandManager
|
||||
Protected Property UndoCommands As New Stack(Of ICommand)
|
||||
|
||||
Protected Property RedoCommands As New Stack(Of ICommand)
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 运行命令,并将命令添加至撤销堆栈
|
||||
''' </summary>
|
||||
''' <param name="command"></param>
|
||||
Public Sub RunCommand(command As ICommand)
|
||||
command.Execute()
|
||||
|
||||
AddUndoCommand(command)
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 将命令添加至撤销堆栈
|
||||
''' </summary>
|
||||
Public Sub AddUndoCommand(command As ICommand)
|
||||
UndoCommands.Push(command)
|
||||
|
||||
If RedoCommands.Count > 0 Then
|
||||
ClearRedoCommands()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 清空撤销命令堆栈
|
||||
''' </summary>
|
||||
Public Sub ClearUndoCommands()
|
||||
UndoCommands.Clear()
|
||||
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 清空重做命令堆栈
|
||||
''' </summary>
|
||||
Public Sub ClearRedoCommands()
|
||||
RedoCommands.Clear()
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 清空撤销与重做命令堆栈
|
||||
''' </summary>
|
||||
Public Sub ClearCommands()
|
||||
ClearUndoCommands()
|
||||
ClearRedoCommands()
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 执行撤销命令
|
||||
''' </summary>
|
||||
Public Sub Undo()
|
||||
If UndoCommands.Count <= 0 Then Return
|
||||
Dim command As ICommand = UndoCommands.Pop()
|
||||
command.Undo()
|
||||
|
||||
RedoCommands.Push(command)
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 执行重做命令
|
||||
''' </summary>
|
||||
Public Sub Redo()
|
||||
If RedoCommands.Count <= 0 Then Return
|
||||
|
||||
Dim command As ICommand = RedoCommands.Pop()
|
||||
command.Redo()
|
||||
|
||||
UndoCommands.Push(command)
|
||||
'MemberwiseClone()‘浅拷贝
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
20
UTS_Core/Undo/ICommand.vb
Normal file
20
UTS_Core/Undo/ICommand.vb
Normal file
@@ -0,0 +1,20 @@
|
||||
Namespace Undo
|
||||
Public Interface ICommand
|
||||
''' <summary>
|
||||
''' 运行一条需要记录在撤销栈的命令
|
||||
''' </summary>
|
||||
Sub Execute()
|
||||
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 重做命令
|
||||
''' </summary>
|
||||
Sub Redo()
|
||||
|
||||
''' <summary>
|
||||
''' 撤销命令
|
||||
''' </summary>
|
||||
Sub Undo()
|
||||
End Interface
|
||||
End NameSpace
|
||||
Reference in New Issue
Block a user