Projektdateien hinzufügen.
This commit is contained in:
89
Pilz.Collections/SimpleHistory/SimpleHistory.vb
Normal file
89
Pilz.Collections/SimpleHistory/SimpleHistory.vb
Normal file
@@ -0,0 +1,89 @@
|
||||
Imports System.Reflection
|
||||
|
||||
Namespace SimpleHistory
|
||||
|
||||
Public Class HistoryStack
|
||||
|
||||
Private stackPast As New Stack(Of HistoryPoint)
|
||||
Private stackFuture As New Stack(Of HistoryPoint)
|
||||
|
||||
''' <summary>
|
||||
''' Checks if the History has past changes.
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Function HasChanges() As Boolean
|
||||
Return stackPast.Count > 0
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Patch Object States and call Undo Actions.
|
||||
''' </summary>
|
||||
Public Function Undo() As HistoryPoint
|
||||
Dim ret As HistoryPoint
|
||||
|
||||
If stackPast.Count > 0 Then
|
||||
|
||||
Dim hp As HistoryPoint = stackPast.Pop
|
||||
hp.Undo()
|
||||
stackFuture.Push(hp)
|
||||
ret = hp
|
||||
|
||||
Else
|
||||
ret = Nothing
|
||||
|
||||
End If
|
||||
|
||||
Return ret
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Patch Object States and call Redo Actions.
|
||||
''' </summary>
|
||||
Public Function Redo() As HistoryPoint
|
||||
Dim ret As HistoryPoint
|
||||
|
||||
If stackFuture.Count > 0 Then
|
||||
|
||||
Dim hp As HistoryPoint = stackFuture.Pop
|
||||
hp.Redo()
|
||||
stackPast.Push(hp)
|
||||
ret = hp
|
||||
|
||||
Else
|
||||
ret = Nothing
|
||||
|
||||
End If
|
||||
|
||||
Return ret
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Clear the History.
|
||||
''' </summary>
|
||||
Public Sub Clear()
|
||||
stackPast.Clear()
|
||||
stackFuture.Clear()
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Store a History Point.
|
||||
''' </summary>
|
||||
''' <param name="point">The History Point to add to the past changes.</param>
|
||||
''' <param name="newName">The name to set for the History Point.</param>
|
||||
Public Sub Store(point As HistoryPoint, newName As String)
|
||||
point.Name = newName
|
||||
Store(point)
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Store a History Point.
|
||||
''' </summary>
|
||||
''' <param name="point">The History Point to add to the past changes.</param>
|
||||
Public Sub Store(point As HistoryPoint)
|
||||
stackPast.Push(point)
|
||||
stackFuture.Clear()
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user