Imports System.Reflection Namespace SimpleHistory Public Class HistoryStack Private stackPast As New Stack(Of HistoryPoint) Private stackFuture As New Stack(Of HistoryPoint) ''' ''' 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