Imports System.Reflection
Namespace SimpleHistory
Public Class HistoryStack
Private stackPast As New Stack(Of HistoryPoint)
Private stackFuture As New Stack(Of HistoryPoint)
'''
''' Gets the count of history points.
'''
'''
Public ReadOnly Property ChangesCount As Boolean
Get
Return stackPast.Count
End Get
End Property
'''
''' Gets the current stack of all past HistoryPoints that are used for the Undo function.
'''
'''
Public ReadOnly Property PastHistoryPoints As HistoryPoint()
Get
Return stackPast.ToArray
End Get
End Property
'''
''' Gets the current stack of all future HistoryPoints that are used for the Redo function.
'''
'''
Public ReadOnly Property FutureHistoryPoints As HistoryPoint()
Get
Return stackFuture.ToArray
End Get
End Property
'''
''' Checks if the History has past changes.
'''
'''
Public Function HasChanges() As Boolean
Return stackPast.Count > 0
End Function
'''
''' Patch Object States and call Undo Actions.
'''
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
'''
''' Patch Object States and call Redo Actions.
'''
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
'''
''' Clear the History.
'''
Public Sub Clear()
stackPast.Clear()
stackFuture.Clear()
End Sub
'''
''' Store a History Point.
'''
''' The History Point to add to the past changes.
''' The name to set for the History Point.
Public Sub Store(point As HistoryPoint, newName As String)
point.Name = newName
Store(point)
End Sub
'''
''' Store a History Point.
'''
''' The History Point to add to the past changes.
Public Sub Store(point As HistoryPoint)
stackPast.Push(point)
stackFuture.Clear()
End Sub
End Class
End Namespace