Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Region " Undo-Redo "
- ' [ Undo-Redo ]
- '
- ' Supported controls:
- '
- ' CheckBox
- ' ComboBox
- ' DateTimePicker
- ' ListBox (single and multi-select)
- ' MaskedTextBox
- ' MonthCalendar
- ' NumericUpDown
- ' RadioButton
- ' TextBox
- '
- ' Examples:
- '
- ' Private WithEvents UndoRedoAction As UndoRedoManager
- ' UndoRedoAction = New UndoRedoManager(Me)
- ' UndoRedoAction.Undo()
- ' UndoRedoAction.Redo()
- #Region " UndoRedoManager "
- '******************************************************************************************************************
- ' Undo/Redo framework (c) Copyright 2009 Etienne Nijboer
- '******************************************************************************************************************
- Public Enum UndoRedoCommandType
- ctNone
- ctUndo
- ctRedo
- End Enum
- Public Class UndoRedoManager
- #Region "UndoRedoMonitor auto register types"
- Private Shared RegisteredUndoRedoMonitorTypes As List(Of Type) = Nothing
- ' ScanAssembly
- ' The first created UndoRedoMonitor will scan the assembly for BaseUndoRedoMonitors and
- ' store these types in the monitor type list.
- '
- Private Shared Sub ScanAssembly()
- If RegisteredUndoRedoMonitorTypes Is Nothing Then
- RegisteredUndoRedoMonitorTypes = New List(Of Type)
- Dim AssemblyTypes() As Type = Reflection.Assembly.GetExecutingAssembly().GetTypes()
- Dim BaseUndoRedoMonitorType As Type = GetType(BaseUndoRedoMonitor)
- For Each typeItem As Type In AssemblyTypes
- If typeItem.BaseType Is BaseUndoRedoMonitorType Then
- RegisteredUndoRedoMonitorTypes.Add(typeItem)
- End If
- Next
- End If
- End Sub
- #End Region
- Private Control As Control = Nothing
- Private UndoRedoMonitors As List(Of BaseUndoRedoMonitor)
- Private ExcludeControls As List(Of Control)
- ' InitializeUndoRedoMonitors
- ' When a new UndoRedoManager instance is created, a new instance of each registered monitor
- ' is created and used only within the scope of this UndoRedoManager, preventing temporary data
- ' moved to another UndoRedoManager. This is because Each form, or group control like a panel
- ' to make seperate undo/redo groups on a single form, can have it's own UndoRedoManager. It is
- ' of course also possible to use one global UndoRedoManager for multiple forms. This lets you
- ' control how data is seperated or combined, depending on the relation between te undo/redo commands.
- Private Sub InitializeUndoRedoMonitors()
- ScanAssembly()
- UndoRedoMonitors = New List(Of BaseUndoRedoMonitor)
- For Each typeItem In RegisteredUndoRedoMonitorTypes
- UndoRedoMonitors.Add(Activator.CreateInstance(typeItem, Me))
- Next
- End Sub
- Public Sub New()
- InitializeUndoRedoMonitors()
- End Sub
- Public Sub New(ByVal AControl As Control)
- Me.New(AControl, New List(Of Control))
- End Sub
- Public Sub New(ByVal AControl As Control, ByVal AExcludeControls As List(Of Control))
- Me.New()
- ExcludeControls = AExcludeControls
- MonitorControl(AControl)
- End Sub
- Public Sub New(ByVal AControl As Control, ByVal ParamArray AExcludeControls() As Control)
- Me.New(AControl, AExcludeControls.ToList)
- End Sub
- ' MonitorControl
- ' If a given control is not in the list of controls to exclude from undo/redo actions,
- ' an attempt is made to attach it to a matching UndoRedoMonitor. If no direct match is
- ' found, a same attempt is made for each control contained within the control recursively.
- Private Sub MonitorControl(ByVal AControl As Control)
- If Not ExcludeControls.Contains(AControl) Then
- If Not BindMonitor(AControl) Then
- For Each ctl As Control In AControl.Controls
- MonitorControl(ctl)
- Next
- End If
- End If
- End Sub
- ' BindMonitor
- ' An attempt is made to bind the control to a each registered monitor. When a match is
- ' found the search ends and the function will return true, false otherwise meaning there
- ' is no specific UndoRedoMonitor for this control.
- Private Function BindMonitor(ByVal AControl As Control) As Boolean
- Dim index As Integer = UndoRedoMonitors.Count - 1, result As Boolean = False
- While index >= 0 And Not result
- result = UndoRedoMonitors(index).Monitor(AControl)
- index -= 1
- End While
- Return result
- End Function
- Public Sub Monitor(ByVal AControl As Control)
- MonitorControl(AControl)
- End Sub
- Private undoStack As Stack(Of BaseUndoRedoCommand) = New Stack(Of BaseUndoRedoCommand)
- Private redoStack As Stack(Of BaseUndoRedoCommand) = New Stack(Of BaseUndoRedoCommand)
- Private _undoRedoCommand As UndoRedoCommandType = UndoRedoCommandType.ctNone
- Private _canUndo As Boolean = False
- Private _canRedo As Boolean = False
- Public Event CanUndoChanged(ByVal Sender As Object, ByVal CanUndo As Boolean)
- Public Event CanRedoChanged(ByVal Sender As Object, ByVal CanRedo As Boolean)
- Public Event UndoRedoStacksChanged(ByVal Sender As Object)
- Private Sub UpdateCanUndoRedo()
- Dim isCanUndoChanged As Boolean = Not (undoStack.Count > 0) = _canUndo, _
- isCanRedoChanged As Boolean = Not (redoStack.Count > 0) = _canRedo
- _canUndo = undoStack.Count > 0
- _canRedo = redoStack.Count > 0
- If isCanUndoChanged Then
- RaiseEvent CanUndoChanged(Me, _canUndo)
- End If
- If isCanRedoChanged Then
- RaiseEvent CanRedoChanged(Me, _canRedo)
- End If
- RaiseEvent UndoRedoStacksChanged(Me)
- End Sub
- Public ReadOnly Property isUndoing() As Boolean
- Get
- Return _undoRedoCommand = UndoRedoCommandType.ctUndo
- End Get
- End Property
- Public ReadOnly Property isRedoing() As Boolean
- Get
- Return _undoRedoCommand = UndoRedoCommandType.ctRedo
- End Get
- End Property
- Public ReadOnly Property isPerformingUndoRedo() As Boolean
- Get
- Return _undoRedoCommand <> UndoRedoCommandType.ctNone
- End Get
- End Property
- Public ReadOnly Property CanUndo() As Boolean
- Get
- Return _canUndo
- End Get
- End Property
- Public ReadOnly Property CanRedo() As Boolean
- Get
- Return _canRedo
- End Get
- End Property
- Public Sub AddUndoCommand(ByVal UndoRedoCommand As BaseUndoRedoCommand)
- If Not isUndoing Then
- undoStack.Push(UndoRedoCommand)
- If Not isRedoing Then
- redoStack.Clear()
- UpdateCanUndoRedo()
- End If
- End If
- End Sub
- Public Sub AddRedoCommand(ByVal UndoRedoCommand As BaseUndoRedoCommand)
- If Not isRedoing Then
- redoStack.Push(UndoRedoCommand)
- If Not isUndoing Then
- UpdateCanUndoRedo()
- End If
- End If
- End Sub
- Public Sub AddCommand(ByVal UndoRedoCommandType As UndoRedoCommandType, ByVal UndoRedoCommand As BaseUndoRedoCommand)
- Select Case UndoRedoCommandType
- Case UndoRedoCommandType.ctUndo
- AddUndoCommand(UndoRedoCommand)
- Case UndoRedoCommandType.ctRedo
- AddRedoCommand(UndoRedoCommand)
- Case Else
- Throw New Exception("An undo or redo command could not be accepted.")
- End Select
- End Sub
- Public Sub Undo()
- If CanUndo Then
- 'Try
- _undoRedoCommand = UndoRedoCommandType.ctUndo
- undoStack.Pop.Undo()
- 'Catch e As Exception
- 'Finally
- UpdateCanUndoRedo()
- _undoRedoCommand = UndoRedoCommandType.ctNone
- 'End Try
- End If
- End Sub
- Public Sub Redo()
- If CanRedo Then
- _undoRedoCommand = UndoRedoCommandType.ctRedo
- redoStack.Pop.Redo()
- UpdateCanUndoRedo()
- _undoRedoCommand = UndoRedoCommandType.ctNone
- End If
- End Sub
- Protected Overrides Sub Finalize()
- MyBase.Finalize()
- End Sub
- #Region "debug info"
- Public Shared Function ArrayToString(ByVal ObjectArray() As Object) As String
- Dim sb As New System.Text.StringBuilder
- For Each item As Object In ObjectArray
- sb.AppendLine(item.ToString)
- Next
- Return sb.ToString
- End Function
- Public Function GetUndoStack() As String
- Return ArrayToString(undoStack.ToArray)
- End Function
- Public Function GetRedoStack() As String
- Return ArrayToString(redoStack.ToArray)
- End Function
- Public Function GetRegisteredUndoRedoMonitorTypes() As String
- Return ArrayToString(RegisteredUndoRedoMonitorTypes.ToArray)
- End Function
- #End Region
- End Class
- #End Region
- #Region " BaseUndoRedoMonitor "
- Public MustInherit Class BaseUndoRedoMonitor
- Public Sub New(ByVal AUndoRedoManager As UndoRedoManager)
- _UndoRedoManager = AUndoRedoManager
- End Sub
- Private _UndoRedoManager As UndoRedoManager
- Public Property UndoRedoManager() As UndoRedoManager
- Get
- Return _UndoRedoManager
- End Get
- Set(ByVal value As UndoRedoManager)
- _UndoRedoManager = value
- End Set
- End Property
- Public ReadOnly Property isUndoing() As Boolean
- Get
- Return UndoRedoManager.isUndoing
- End Get
- End Property
- Public ReadOnly Property isRedoing() As Boolean
- Get
- Return UndoRedoManager.isRedoing
- End Get
- End Property
- Public ReadOnly Property isPerformingUndoRedo() As Boolean
- Get
- Return UndoRedoManager.isPerformingUndoRedo
- End Get
- End Property
- Public Sub AddCommand(ByVal UndoRedoCommandType As UndoRedoCommandType, ByVal UndoRedoCommand As BaseUndoRedoCommand)
- UndoRedoManager.AddCommand(UndoRedoCommandType, UndoRedoCommand)
- End Sub
- Public MustOverride Function Monitor(ByVal AControl As Control) As Boolean
- End Class
- '**************************************************************************
- ' SimpleControl
- ' Controls: TextBox, ComboBox, DateTimePicker, NumericUpDown, MaskedTextBox
- '**************************************************************************
- Public Class SimpleControlMonitor : Inherits BaseUndoRedoMonitor
- Private Data As String
- Public Sub New(ByVal AUndoRedoManager As UndoRedoManager)
- MyBase.New(AUndoRedoManager)
- End Sub
- Public Overrides Function Monitor(ByVal AControl As System.Windows.Forms.Control) As Boolean
- If TypeOf AControl Is TextBox Or _
- TypeOf AControl Is ComboBox Or _
- TypeOf AControl Is DateTimePicker Or _
- TypeOf AControl Is NumericUpDown Or _
- TypeOf AControl Is ListView Or _
- TypeOf AControl Is MaskedTextBox Then
- AddHandler AControl.Enter, AddressOf Control_Enter
- AddHandler AControl.Leave, AddressOf Control_Leave
- Return True
- End If
- Return False
- End Function
- Private Sub Control_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Data = CType(sender, Control).Text
- End Sub
- Private Sub Control_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Dim CurrentData As String = CType(sender, Control).Text
- If Not String.Equals(CurrentData, Data) Then
- AddCommand(UndoRedoCommandType.ctUndo, New SimpleControlUndoRedoCommand(Me, sender, Data))
- End If
- End Sub
- End Class
- '********
- ' ListBox
- '********
- Public Class ListBoxMonitor : Inherits BaseUndoRedoMonitor
- Private Data As Object
- Public Sub New(ByVal AUndoRedoManager As UndoRedoManager)
- MyBase.New(AUndoRedoManager)
- End Sub
- Public Overrides Function Monitor(ByVal AControl As System.Windows.Forms.Control) As Boolean
- If TypeOf AControl Is ListBox Then
- AddHandler AControl.Enter, AddressOf Control_Enter
- AddHandler CType(AControl, ListBox).SelectedIndexChanged, AddressOf Control_Changed
- Return True
- End If
- Return False
- End Function
- Public Function GetSelected(ByVal AListBox As Object) As String
- Dim Indices As List(Of String) = New List(Of String)
- For Each itemIndex As Integer In CType(AListBox, ListBox).SelectedIndices
- Indices.Add(CStr(itemIndex + 1))
- Next
- Return String.Join(",", Indices.ToArray)
- End Function
- Public Sub RestoreSelected(ByVal AListBox As Object, ByVal ASelection As String)
- If Not String.IsNullOrEmpty(ASelection) Then
- Dim Indices As List(Of Integer) = New List(Of Integer)(Array.ConvertAll(ASelection.Split(","), New Converter(Of String, Integer)(AddressOf Integer.Parse)))
- Dim Control As ListBox = CType(AListBox, ListBox)
- Select Case Control.SelectionMode
- Case SelectionMode.None
- Case SelectionMode.One
- Control.SetSelected(Indices(0) - 1, True)
- Case SelectionMode.MultiSimple, SelectionMode.MultiExtended
- For index As Integer = 0 To Control.Items.Count - 1
- Control.SetSelected(index, Indices.IndexOf(index + 1) >= 0)
- Next
- End Select
- Else
- CType(AListBox, ListBox).ClearSelected()
- End If
- End Sub
- Private Sub Control_Changed(ByVal sender As System.Object, ByVal e As System.EventArgs)
- ' Events that are also fired when the undo/redo value is changed by code, like change events,
- ' it is important to make sure that no undo/redo command is added when performing a undo/redo action.
- If Not isPerformingUndoRedo Then
- Dim CurrentData As String = GetSelected(sender)
- If Not String.Equals(Data, CurrentData) Then
- AddCommand(UndoRedoCommandType.ctUndo, New ListBoxUndoRedoCommand(Me, sender, Data))
- Data = CurrentData
- End If
- End If
- End Sub
- Private Sub Control_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Data = GetSelected(sender)
- End Sub
- End Class
- '*********
- ' CheckBox
- '*********
- Public Class CheckBoxMonitor : Inherits BaseUndoRedoMonitor
- Private Data As CheckState
- Public Sub New(ByVal AUndoRedoManager As UndoRedoManager)
- MyBase.New(AUndoRedoManager)
- End Sub
- Public Overrides Function Monitor(ByVal AControl As System.Windows.Forms.Control) As Boolean
- If TypeOf AControl Is CheckBox Then
- AddHandler AControl.Enter, AddressOf Control_Enter
- AddHandler AControl.Leave, AddressOf Control_Leave
- Return True
- End If
- Return False
- End Function
- Private Sub Control_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Data = CType(sender, CheckBox).CheckState
- End Sub
- Private Sub Control_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Dim CurrentData As CheckState = CType(sender, CheckBox).CheckState
- If Data <> CurrentData Then
- AddCommand(UndoRedoCommandType.ctUndo, New CheckBoxUndoRedoCommand(Me, sender, Data))
- End If
- End Sub
- End Class
- '************
- ' RadioButton
- '************
- Public Class RadioButtonMonitor : Inherits BaseUndoRedoMonitor
- Private Data As RadioButton
- Public Sub New(ByVal AUndoRedoManager As UndoRedoManager)
- MyBase.New(AUndoRedoManager)
- End Sub
- Public Overrides Function Monitor(ByVal AControl As System.Windows.Forms.Control) As Boolean
- If TypeOf AControl Is RadioButton Then
- AddHandler CType(AControl, RadioButton).CheckedChanged, AddressOf Control_CheckedChanged
- Return True
- End If
- Return False
- End Function
- Private Sub Control_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
- ' Events that are also fired when the undo/redo value is changed by code, like change events,
- ' it is important to make sure that no undo/redo command is added when performing a undo/redo action.
- If Not isPerformingUndoRedo Then
- If CType(sender, RadioButton).Checked Then
- AddCommand(UndoRedoCommandType.ctUndo, New RadioButtonUndoRedoCommand(Me, sender, Data))
- Else
- Data = sender
- End If
- End If
- End Sub
- End Class
- '**************
- ' MonthCalendar
- '**************
- Public Class MonthCalendarMonitor : Inherits BaseUndoRedoMonitor
- Private Data As SelectionRange
- Public Sub New(ByVal AUndoRedoManager As UndoRedoManager)
- MyBase.New(AUndoRedoManager)
- End Sub
- Public Overrides Function Monitor(ByVal AControl As System.Windows.Forms.Control) As Boolean
- If TypeOf AControl Is MonthCalendar Then
- AddHandler AControl.Enter, AddressOf Control_Enter
- AddHandler CType(AControl, MonthCalendar).DateSelected, AddressOf Control_DateSelected
- Return True
- End If
- Return False
- End Function
- Private Sub Control_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Data = CType(sender, MonthCalendar).SelectionRange
- End Sub
- Private Sub Control_DateSelected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs)
- ' Events that are also fired when the undo/redo value is changed by code, like selected events,
- ' it is important to make sure that no undo/redo command is added when performing a undo/redo action.
- If Not isPerformingUndoRedo Then
- Dim CurrentData As SelectionRange = CType(sender, MonthCalendar).SelectionRange
- If Not SelectionRange.Equals(Data, CurrentData) Then
- AddCommand(UndoRedoCommandType.ctUndo, New MonthCalendarUndoRedoCommand(Me, sender, Data))
- Data = CurrentData
- End If
- End If
- End Sub
- End Class
- #End Region
- #Region " BaseUndoRedoCommand "
- Public MustInherit Class BaseUndoRedoCommand
- Private _UndoRedoMonitor As BaseUndoRedoMonitor
- Private _UndoRedoControl As Control
- Private _UndoRedoData As Object
- Public ReadOnly Property UndoRedoMonitor() As BaseUndoRedoMonitor
- Get
- Return _UndoRedoMonitor
- End Get
- End Property
- Public ReadOnly Property UndoRedoControl() As Control
- Get
- Return _UndoRedoControl
- End Get
- End Property
- Protected Property UndoRedoData() As Object
- Get
- Return _UndoRedoData
- End Get
- Set(ByVal value As Object)
- _UndoRedoData = value
- End Set
- End Property
- Protected Sub New()
- Throw New Exception("Cannot create instance with the default constructor.")
- End Sub
- Public Sub New(ByVal AUndoRedoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control)
- Me.New(AUndoRedoMonitor, AMonitorControl, Nothing)
- End Sub
- Public Sub New(ByVal AUndoRedoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control, ByVal AUndoRedoData As Object)
- _UndoRedoMonitor = AUndoRedoMonitor
- _UndoRedoControl = AMonitorControl
- _UndoRedoData = AUndoRedoData
- End Sub
- Protected Sub AddCommand(ByVal UndoRedoCommandType As UndoRedoCommandType, ByVal UndoRedoCommand As BaseUndoRedoCommand)
- UndoRedoMonitor.AddCommand(UndoRedoCommandType, UndoRedoCommand)
- End Sub
- Public Overridable Sub Undo()
- AddCommand(UndoRedoCommandType.ctRedo, Activator.CreateInstance(Me.GetType, UndoRedoMonitor, UndoRedoControl))
- End Sub
- Public Overridable Sub Redo()
- AddCommand(UndoRedoCommandType.ctUndo, Activator.CreateInstance(Me.GetType, UndoRedoMonitor, UndoRedoControl))
- End Sub
- Public Overridable Sub Undo(ByVal RedoData As Object)
- AddCommand(UndoRedoCommandType.ctRedo, Activator.CreateInstance(Me.GetType, UndoRedoMonitor, UndoRedoControl, RedoData))
- End Sub
- Public Overridable Sub Redo(ByVal UndoData As Object)
- AddCommand(UndoRedoCommandType.ctUndo, Activator.CreateInstance(Me.GetType, UndoRedoMonitor, UndoRedoControl, UndoData))
- End Sub
- Public MustOverride Function CommandAsText() As String
- Public Overrides Function ToString() As String
- Return CommandAsText()
- End Function
- End Class
- '**************************************************************************
- ' SimpleControl
- ' Controls: TextBox, ComboBox, DateTimePicker, NumericUpDown, MaskedTextBox
- '**************************************************************************
- Public Class SimpleControlUndoRedoCommand : Inherits BaseUndoRedoCommand
- Protected ReadOnly Property UndoRedoText() As String
- Get
- Return CStr(UndoRedoData)
- End Get
- End Property
- Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control)
- MyBase.New(AUndoMonitor, AMonitorControl)
- UndoRedoData = UndoRedoControl.Text
- End Sub
- Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control, ByVal AUndoRedoData As String)
- MyBase.New(AUndoMonitor, AMonitorControl, AUndoRedoData)
- End Sub
- Public Overrides Sub Undo()
- MyBase.Undo()
- UndoRedoControl.Text = UndoRedoText
- End Sub
- Public Overrides Sub Redo()
- MyBase.Redo()
- UndoRedoControl.Text = UndoRedoText
- End Sub
- Public Overrides Function CommandAsText() As String
- Return String.Format("Change to '{0}'", UndoRedoText)
- End Function
- End Class
- '********
- ' ListBox
- '********
- Public Class ListBoxUndoRedoCommand : Inherits BaseUndoRedoCommand
- Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control)
- MyBase.New(AUndoMonitor, AMonitorControl)
- UndoRedoData = GetSelection()
- End Sub
- Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control, ByVal AUndoRedoData As Object)
- MyBase.New(AUndoMonitor, AMonitorControl, AUndoRedoData)
- End Sub
- Public ReadOnly Property Control() As ListBox
- Get
- Return CType(UndoRedoControl, ListBox)
- End Get
- End Property
- Private Sub RestoreSelection()
- CType(UndoRedoMonitor, ListBoxMonitor).RestoreSelected(UndoRedoControl, CStr(UndoRedoData))
- End Sub
- Private Function GetSelection() As Object
- Return CType(UndoRedoMonitor, ListBoxMonitor).GetSelected(UndoRedoControl)
- End Function
- Public Overrides Sub Undo()
- MyBase.Undo()
- RestoreSelection()
- End Sub
- Public Overrides Sub Redo()
- MyBase.Redo()
- RestoreSelection()
- End Sub
- Public Overrides Function CommandAsText() As String
- Return String.Format("Select {0}", CStr(UndoRedoData))
- End Function
- End Class
- '*********
- ' CheckBox
- '*********
- Public Class CheckBoxUndoRedoCommand : Inherits BaseUndoRedoCommand
- Protected ReadOnly Property UndoRedoCheckState() As CheckState
- Get
- Return CType(UndoRedoData, CheckState)
- End Get
- End Property
- Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control)
- MyBase.New(AUndoMonitor, AMonitorControl)
- UndoRedoData = Control.CheckState
- End Sub
- Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control, ByVal AUndoRedoData As String)
- MyBase.New(AUndoMonitor, AMonitorControl, AUndoRedoData)
- End Sub
- Public ReadOnly Property Control() As CheckBox
- Get
- Return CType(UndoRedoControl, CheckBox)
- End Get
- End Property
- Public Overrides Sub Undo()
- MyBase.Undo()
- Control.CheckState = UndoRedoCheckState
- End Sub
- Public Overrides Sub Redo()
- MyBase.Redo()
- Control.CheckState = UndoRedoCheckState
- End Sub
- Public Overrides Function CommandAsText() As String
- Return String.Format("Change to '{0}'", UndoRedoCheckState.ToString)
- End Function
- End Class
- '************
- ' RadioButton
- '************
- Public Class RadioButtonUndoRedoCommand : Inherits BaseUndoRedoCommand
- Protected ReadOnly Property UndoRedoRadioButton() As RadioButton
- Get
- Return CType(UndoRedoData, RadioButton)
- End Get
- End Property
- Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control)
- MyBase.New(AUndoMonitor, AMonitorControl)
- UndoRedoData = Control.Checked
- End Sub
- Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control, ByVal AUndoRedoData As Control)
- MyBase.New(AUndoMonitor, AMonitorControl, AUndoRedoData)
- End Sub
- Public ReadOnly Property Control() As RadioButton
- Get
- Return CType(UndoRedoControl, RadioButton)
- End Get
- End Property
- Public Overrides Sub Undo()
- MyBase.Undo(UndoRedoRadioButton)
- Control.Checked = False
- If UndoRedoRadioButton IsNot Nothing Then
- UndoRedoRadioButton.Checked = True
- End If
- End Sub
- Public Overrides Sub Redo()
- MyBase.Redo(UndoRedoRadioButton)
- If UndoRedoRadioButton IsNot Nothing Then
- UndoRedoRadioButton.Checked = False
- End If
- Control.Checked = True
- End Sub
- Public Overrides Function CommandAsText() As String
- If UndoRedoRadioButton IsNot Nothing Then
- Return String.Format("Invert '{0}'/'{1}'", Control.Text, UndoRedoRadioButton.Text)
- Else
- Return String.Format("Change '{0}'", Control.Text)
- End If
- End Function
- End Class
- '**************
- ' MonthCalendar
- '**************
- Public Class MonthCalendarUndoRedoCommand : Inherits BaseUndoRedoCommand
- Protected ReadOnly Property UndoRedoSelectionRange() As SelectionRange
- Get
- Return CType(UndoRedoData, SelectionRange)
- End Get
- End Property
- Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control)
- MyBase.New(AUndoMonitor, AMonitorControl)
- UndoRedoData = Control.SelectionRange
- End Sub
- Public Sub New(ByVal AUndoMonitor As BaseUndoRedoMonitor, ByVal AMonitorControl As Control, ByVal AUndoRedoData As SelectionRange)
- MyBase.New(AUndoMonitor, AMonitorControl, AUndoRedoData)
- End Sub
- Public ReadOnly Property Control() As MonthCalendar
- Get
- Return CType(UndoRedoControl, MonthCalendar)
- End Get
- End Property
- Public Overrides Sub Undo()
- MyBase.Undo()
- Control.SelectionRange = UndoRedoSelectionRange
- End Sub
- Public Overrides Sub Redo()
- MyBase.Redo()
- Control.SelectionRange = UndoRedoSelectionRange
- End Sub
- Public Overrides Function CommandAsText() As String
- If Date.Equals(UndoRedoSelectionRange.Start, UndoRedoSelectionRange.End) Then
- Return String.Format("Select date {0}", FormatDateTime(UndoRedoSelectionRange.Start, DateFormat.ShortDate))
- Else
- End If
- Return String.Format("Change to '{0}'", String.Format("{0} until {1}", FormatDateTime(UndoRedoSelectionRange.Start, DateFormat.ShortDate), _
- FormatDateTime(UndoRedoSelectionRange.End, DateFormat.ShortDate)))
- End Function
- End Class
- #End Region
- #End Region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement