Mini Kabibi Habibi
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Input
Imports DevExpress.Utils
Imports DevExpress.Xpf.Editors
Namespace BarsDemo
Public Structure CommandsDemoCommandId
Implements IConvertToInt(Of CommandsDemoCommandId), IEquatable(Of CommandsDemoCommandId)
Public Shared ReadOnly None As CommandsDemoCommandId
Public Shared ReadOnly Cut As CommandsDemoCommandId
Public Shared ReadOnly Copy As CommandsDemoCommandId
Public Shared ReadOnly Paste As CommandsDemoCommandId
Public Shared ReadOnly SelectAll As CommandsDemoCommandId
Public Shared ReadOnly Undo As CommandsDemoCommandId
Public Shared ReadOnly Redo As CommandsDemoCommandId
Public Shared ReadOnly MaximizeValue As CommandsDemoCommandId
Public Shared ReadOnly MinimizeValue As CommandsDemoCommandId
Public Shared ReadOnly IncreaseSmall As CommandsDemoCommandId
Public Shared ReadOnly DecreaseSmall As CommandsDemoCommandId
Public Shared ReadOnly IncreaseLarge As CommandsDemoCommandId
Public Shared ReadOnly DecreaseLarge As CommandsDemoCommandId
Public Shared Operator =(ByVal id1 As CommandsDemoCommandId, ByVal id2 As CommandsDemoCommandId) As Boolean
Return id1.m_value = id2.m_value
End Operator
Public Shared Operator <>(ByVal id1 As CommandsDemoCommandId, ByVal id2 As CommandsDemoCommandId) As Boolean
Return id1.m_value <> id2.m_value
End Operator
Public Sub New(ByVal value As Integer)
m_value = value
End Sub
Public Overrides Overloads Function Equals(ByVal obj As Object) As Boolean
Return ((TypeOf obj Is CommandsDemoCommandId) AndAlso (Me.m_value = (CType(obj, CommandsDemoCommandId)).m_value))
End Function
Public Overrides Function GetHashCode() As Integer
Return m_value.GetHashCode()
End Function
Public Overrides Function ToString() As String
Return m_value.ToString()
End Function
Private ReadOnly m_value As Integer
#Region "IConvertToInt<CommandsDemoCommandId> Members"
Private Function IConvertToInt_ToInt() As Integer Implements IConvertToInt(Of CommandsDemoCommandId).ToInt
Return m_value
End Function
Private Function FromInt(ByVal value As Integer) As CommandsDemoCommandId Implements IConvertToInt(Of CommandsDemoCommandId).FromInt
Return New CommandsDemoCommandId(value)
End Function
#End Region
#Region "IEquatable<CommandsDemoCommandId> Members"
Public Overloads Function Equals(ByVal other As CommandsDemoCommandId) As Boolean Implements IEquatable(Of CommandsDemoCommandId).Equals
Return Me.m_value = other.m_value
End Function
#End Region
Shared Sub New()
None = New CommandsDemoCommandId(0)
Cut = New CommandsDemoCommandId(1)
Copy = New CommandsDemoCommandId(2)
Paste = New CommandsDemoCommandId(3)
SelectAll = New CommandsDemoCommandId(4)
Undo = New CommandsDemoCommandId(5)
Redo = New CommandsDemoCommandId(6)
MaximizeValue = New CommandsDemoCommandId(7)
MinimizeValue = New CommandsDemoCommandId(8)
IncreaseSmall = New CommandsDemoCommandId(9)
DecreaseSmall = New CommandsDemoCommandId(10)
IncreaseLarge = New CommandsDemoCommandId(11)
DecreaseLarge = New CommandsDemoCommandId(12)
End Sub
End Structure
Public Class CommandsDemoCommand
Implements ICommand
Private Shared _cut As ICommand
Private Shared _copy As ICommand
Private Shared _paste As ICommand
Private Shared _selectAll As ICommand
Private Shared _undo As ICommand
Private Shared _redo As ICommand
Private Shared _maximizeValue As ICommand
Private Shared _minimizeValue As ICommand
Private Shared _increaseSmall As ICommand
Private Shared _decreaseSmall As ICommand
Private Shared _increaseLarge As ICommand
Private Shared _decreaseLarge As ICommand
#Region "Static"
Public Shared Property Cut() As ICommand
Get
Return _cut
End Get
Private Set(ByVal value As ICommand)
_cut = value
End Set
End Property
Public Shared Property Copy() As ICommand
Get
Return _copy
End Get
Private Set(ByVal value As ICommand)
_copy = value
End Set
End Property
Public Shared Property Paste() As ICommand
Get
Return _paste
End Get
Private Set(ByVal value As ICommand)
_paste = value
End Set
End Property
Public Shared Property SelectAll() As ICommand
Get
Return _selectAll
End Get
Private Set(ByVal value As ICommand)
_selectAll = value
End Set
End Property
Public Shared Property Undo() As ICommand
Get
Return _undo
End Get
Private Set(ByVal value As ICommand)
_undo = value
End Set
End Property
Public Shared Property Redo() As ICommand
Get
Return _redo
End Get
Private Set(ByVal value As ICommand)
_redo = value
End Set
End Property
Public Shared Property MaximizeValue() As ICommand
Get
Return _maximizeValue
End Get
Private Set(ByVal value As ICommand)
_maximizeValue = value
End Set
End Property
Public Shared Property MinimizeValue() As ICommand
Get
Return _minimizeValue
End Get
Private Set(ByVal value As ICommand)
_minimizeValue = value
End Set
End Property
Public Shared Property IncreaseSmall() As ICommand
Get
Return _increaseSmall
End Get
Private Set(ByVal value As ICommand)
_increaseSmall = value
End Set
End Property
Public Shared Property DecreaseSmall() As ICommand
Get
Return _decreaseSmall
End Get
Private Set(ByVal value As ICommand)
_decreaseSmall = value
End Set
End Property
Public Shared Property IncreaseLarge() As ICommand
Get
Return _increaseLarge
End Get
Private Set(ByVal value As ICommand)
_increaseLarge = value
End Set
End Property
Public Shared Property DecreaseLarge() As ICommand
Get
Return _decreaseLarge
End Get
Private Set(ByVal value As ICommand)
_decreaseLarge = value
End Set
End Property
Shared Sub New()
Cut = New CommandsDemoCommand(CommandsDemoCommandId.Cut)
Copy = New CommandsDemoCommand(CommandsDemoCommandId.Copy)
Paste = New CommandsDemoCommand(CommandsDemoCommandId.Paste)
SelectAll = New CommandsDemoCommand(CommandsDemoCommandId.SelectAll)
Undo = New CommandsDemoCommand(CommandsDemoCommandId.Undo)
Redo = New CommandsDemoCommand(CommandsDemoCommandId.Redo)
MaximizeValue = New CommandsDemoCommand(CommandsDemoCommandId.MaximizeValue)
MinimizeValue = New CommandsDemoCommand(CommandsDemoCommandId.MinimizeValue)
IncreaseSmall = New CommandsDemoCommand(CommandsDemoCommandId.IncreaseSmall)
DecreaseSmall = New CommandsDemoCommand(CommandsDemoCommandId.DecreaseSmall)
IncreaseLarge = New CommandsDemoCommand(CommandsDemoCommandId.IncreaseLarge)
DecreaseLarge = New CommandsDemoCommand(CommandsDemoCommandId.DecreaseLarge)
End Sub
#End Region ' Static
Public ReadOnly Property Text() As String
Get
Return GetTextByCommandId()
End Get
End Property
Public ReadOnly Property CommandId() As CommandsDemoCommandId
Get
Return id
End Get
End Property
Private ReadOnly id As CommandsDemoCommandId
Public Sub New()
End Sub
Protected Sub New(ByVal id As CommandsDemoCommandId)
Me.id = id
End Sub
Public Overridable Function CanExecute(ByVal parameter As Object) As Boolean Implements ICommand.CanExecute
Dim textEdit As TextEdit = TryCast(parameter, TextEdit)
Dim slider As Slider = TryCast(parameter, Slider)
If textEdit IsNot Nothing Then
Return CanExecuteTextEdit(textEdit)
End If
If slider IsNot Nothing Then
Return CanExecuteSlider(slider)
End If
Return True
End Function
Public Custom Event CanExecuteChanged As EventHandler Implements ICommand.CanExecuteChanged
AddHandler(ByVal value As EventHandler)
End AddHandler
RemoveHandler(ByVal value As EventHandler)
End RemoveHandler
RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
End RaiseEvent
End Event
Public Overridable Sub Execute(ByVal parameter As Object) Implements ICommand.Execute
Dim textEdit As TextEdit = TryCast(parameter, TextEdit)
Dim slider As Slider = TryCast(parameter, Slider)
If textEdit IsNot Nothing Then
ExecuteTextEdit(textEdit)
End If
If slider IsNot Nothing Then
ExecuteSlider(slider)
End If
End Sub
Protected Overridable Function GetTextByCommandId() As String
If id.Equals(CommandsDemoCommandId.Undo) Then
Return "Undo"
End If
If id.Equals(CommandsDemoCommandId.Redo) Then
Return "Redo"
End If
If id.Equals(CommandsDemoCommandId.Cut) Then
Return "Cut"
End If
If id.Equals(CommandsDemoCommandId.Copy) Then
Return "Copy"
End If
If id.Equals(CommandsDemoCommandId.Paste) Then
Return "Paste"
End If
If id.Equals(CommandsDemoCommandId.SelectAll) Then
Return "SelectAll"
End If
If id.Equals(CommandsDemoCommandId.MaximizeValue) Then
Return "Maximize"
End If
If id.Equals(CommandsDemoCommandId.MinimizeValue) Then
Return "Minimize"
End If
If id.Equals(CommandsDemoCommandId.IncreaseSmall) Then
Return "Increase Small"
End If
If id.Equals(CommandsDemoCommandId.DecreaseSmall) Then
Return "Decrease Small"
End If
If id.Equals(CommandsDemoCommandId.IncreaseLarge) Then
Return "Increase Large"
End If
If id.Equals(CommandsDemoCommandId.DecreaseLarge) Then
Return "Decrease Large"
End If
Return String.Empty
End Function
Protected Overridable Function CanExecuteSlider(ByVal slider As Slider) As Boolean
Return True
End Function
Protected Overridable Sub ExecuteSlider(ByVal slider As Slider)
If id.Equals(CommandsDemoCommandId.MaximizeValue) Then
ExecuteSliderMaximizeValue(slider)
Return
End If
If id.Equals(CommandsDemoCommandId.MinimizeValue) Then
ExecuteSliderMinimizeValue(slider)
Return
End If
If id.Equals(CommandsDemoCommandId.IncreaseSmall) Then
ExecuteSliderIncreaseSmall(slider)
Return
End If
If id.Equals(CommandsDemoCommandId.DecreaseSmall) Then
ExecuteSliderDecreaseSmall(slider)
Return
End If
If id.Equals(CommandsDemoCommandId.IncreaseLarge) Then
ExecuteSliderIncreaseLarge(slider)
Return
End If
If id.Equals(CommandsDemoCommandId.DecreaseLarge) Then
ExecuteSliderDecreaseLarge(slider)
Return
End If
End Sub
Protected Overridable Sub ExecuteSliderMaximizeValue(ByVal slider As Slider)
slider.Value = slider.Maximum
End Sub
Protected Overridable Sub ExecuteSliderMinimizeValue(ByVal slider As Slider)
slider.Value = slider.Minimum
End Sub
Protected Overridable Sub ExecuteSliderIncreaseSmall(ByVal slider As Slider)
slider.Value += slider.SmallChange
End Sub
Protected Overridable Sub ExecuteSliderDecreaseSmall(ByVal slider As Slider)
slider.Value -= slider.SmallChange
End Sub
Protected Overridable Sub ExecuteSliderIncreaseLarge(ByVal slider As Slider)
slider.Value += slider.LargeChange
End Sub
Protected Overridable Sub ExecuteSliderDecreaseLarge(ByVal slider As Slider)
slider.Value -= slider.LargeChange
End Sub
Protected Overridable Function CanExecuteTextEdit(ByVal textEdit As TextEdit) As Boolean
If id.Equals(CommandsDemoCommandId.Undo) OrElse id.Equals(CommandsDemoCommandId.Redo) Then
Return False
End If
Return True
End Function
Protected Overridable Sub ExecuteTextEdit(ByVal textEdit As TextEdit)
If id.Equals(CommandsDemoCommandId.Undo) OrElse id.Equals(CommandsDemoCommandId.Redo) Then
Return
End If
If id.Equals(CommandsDemoCommandId.Cut) Then
ExecuteTextEditCut(textEdit)
Return
End If
If id.Equals(CommandsDemoCommandId.Copy) Then
ExecuteTextEditCopy(textEdit)
Return
End If
If id.Equals(CommandsDemoCommandId.Paste) Then
ExecuteTextEditPaste(textEdit)
Return
End If
If id.Equals(CommandsDemoCommandId.SelectAll) Then
ExecuteTextEditSelectAll(textEdit)
Return
End If
End Sub
Protected Overridable Sub ExecuteTextEditCut(ByVal textEdit As TextEdit)
ExecuteTextEditCopy(textEdit)
textEdit.SelectedText = String.Empty
End Sub
Protected Overridable Sub ExecuteTextEditCopy(ByVal textEdit As TextEdit)
If textEdit.SelectedText = String.Empty Then
Return
End If
ClipboardSetText(textEdit.SelectedText)
End Sub
Protected Overridable Sub ExecuteTextEditPaste(ByVal textEdit As TextEdit)
textEdit.SelectedText = ClipboardGetText()
textEdit.SelectionStart = textEdit.SelectionStart + textEdit.SelectionLength
textEdit.SelectionLength = 0
End Sub
Protected Overridable Sub ExecuteTextEditSelectAll(ByVal textEdit As TextEdit)
textEdit.SelectAll()
End Sub
Private Sub ClipboardSetText(ByVal text As String)
Try
Clipboard.SetText(text)
Catch
End Try
End Sub
Private Function ClipboardGetText() As String
Try
Return Clipboard.GetText()
Catch
Return String.Empty
End Try
End Function
End Class
Partial Public Class Commands
Inherits BarsDemoModule
Public Sub New()
InitializeComponent()
End Sub
End Class
End Namespace