Permalink
Browse files

Added IDisposable dependency to IValueEditor

  • Loading branch information...
1 parent 0a0790c commit 72e63701c4b8c2a291f7bc3db65ed82f8f48cde7 @Strilanc committed Apr 7, 2010
@@ -54,7 +54,12 @@ Namespace Bnet.Protocol
setter:=Sub(value)
If Not addressControl.Value.Equals(value.Address) Then addressControl.Value = value.Address
If portControl.Value <> value.Port Then portControl.Value = CUShort(value.Port)
- End Sub)
+ End Sub,
+ disposer:=Sub()
+ addressControl.Dispose()
+ portControl.Dispose()
+ panel.Dispose()
+ End Sub)
End Function
End Class
End Namespace
@@ -57,7 +57,8 @@ Namespace Bnet.Protocol
Control:=subControl.Control,
eventAdder:=Sub(action) AddHandler subControl.ValueChanged, Sub() action(),
getter:=Function() ParseRawValue(subControl.Value),
- setter:=Sub(value) subControl.Value = PackRawValue(value))
+ setter:=Sub(value) subControl.Value = PackRawValue(value),
+ disposer:=Sub() subControl.Dispose())
End Function
End Class
End Namespace
@@ -173,7 +173,12 @@ Namespace Bnet.Protocol
setter:=Sub(value)
resultControl.Value = value.Result
gamesControl.Value = PackRawGameDescriptions(value.Games)
- End Sub)
+ End Sub,
+ disposer:=Sub()
+ resultControl.Dispose()
+ gamesControl.Dispose()
+ panel.Dispose()
+ End Sub)
End Function
End Class
End Namespace
@@ -39,7 +39,8 @@ Namespace Pickling
End Sub,
getter:=Function() New EmptyValue(),
setter:=Sub(value)
- End Sub)
+ End Sub,
+ disposer:=Sub() control.Dispose())
End Function
End Class
End Namespace
@@ -83,7 +83,8 @@
For Each pair In flags
control.SetItemChecked(pair.Item2, value.EnumIncludes(pair.Item1))
Next pair
- End Sub)
+ End Sub,
+ disposer:=Sub() control.Dispose())
End Function
Private Function MakeDefinedValueControl() As IValueEditor(Of TEnum)
Contract.Requires(Not _isFlagEnum)
@@ -102,7 +103,8 @@
control:=control,
eventAdder:=Sub(action) AddHandler control.SelectedIndexChanged, Sub() action(),
getter:=Function() DirectCast(control.SelectedItem, TEnum),
- setter:=Sub(value) control.SelectedItem = value)
+ setter:=Sub(value) control.SelectedItem = value,
+ disposer:=Sub() control.Dispose())
End Function
Private Function MakeUndefinedValueControl() As IValueEditor(Of TEnum)
Contract.Requires(Not _isFlagEnum)
@@ -130,7 +132,8 @@
setter:=Sub(value)
control.SelectedIndex = -1
control.Text = Describe(value)
- End Sub)
+ End Sub,
+ disposer:=Sub() control.Dispose())
End Function
Public Overrides Function MakeControl() As IValueEditor(Of TEnum)
@@ -223,7 +223,12 @@
End If
End If
If checkControl.Checked <> value.HasValue Then checkControl.Checked = value.HasValue
- End Sub)
+ End Sub,
+ disposer:=Sub()
+ checkControl.Dispose()
+ valueControl.Dispose()
+ panel.Dispose()
+ End Sub)
End Function
End Class
@@ -87,7 +87,12 @@ Namespace Pickling
setter:=Sub(value)
If Not value.Key.Equals(keyControl.Value) Then keyControl.Value = value.Key
If Not value.Value.Equals(valueControl.Value) Then valueControl.Value = value.Value
- End Sub)
+ End Sub,
+ disposer:=Sub()
+ keyControl.Dispose()
+ valueControl.Dispose()
+ panel.Dispose()
+ End Sub)
End Function
End Class
End Namespace
@@ -114,6 +114,7 @@
End Class
Public NotInheritable Class ListValueEditor(Of T)
+ Inherits DisposableWithTask
Implements IValueEditor(Of IReadableList(Of T))
Private ReadOnly subControls As New List(Of Entry)
@@ -133,6 +134,8 @@
End Sub
Private Class Entry
+ Inherits DisposableWithTask
+
Private ReadOnly _subControl As IValueEditor(Of T)
Private ReadOnly _removeControl As New Button() With {.Text = "Remove"}
Private ReadOnly _insertControl As New Button() With {.Text = "Insert"}
@@ -185,6 +188,17 @@
Return _subControl
End Get
End Property
+
+ Protected Overrides Function PerformDispose(ByVal finalizing As Boolean) As System.Threading.Tasks.Task
+ If finalizing Then Return Nothing
+ _subControl.Dispose()
+ _removeControl.Dispose()
+ _insertControl.Dispose()
+ _moveUpControl.Dispose()
+ _commandPanel.Dispose()
+ _fullPanel.Dispose()
+ Return Nothing
+ End Function
End Class
Public Sub New(ByVal subJar As IJar(Of T))
@@ -308,5 +322,15 @@
Me.Value = DirectCast(value, IReadableList(Of T))
End Set
End Property
+
+ Protected Overrides Function PerformDispose(ByVal finalizing As Boolean) As System.Threading.Tasks.Task
+ If finalizing Then Return Nothing
+ For Each subControl In subControls
+ subControl.Dispose()
+ Next subControl
+ mainControl.Dispose()
+ addButton.Dispose()
+ Return Nothing
+ End Function
End Class
End Namespace
@@ -37,7 +37,12 @@ Namespace Pickling
Control:=panel,
eventAdder:=Sub(action) AddHandler subControl.ValueChanged, Sub() action(),
getter:=Function() subControl.Value,
- setter:=Sub(value) subControl.Value = value)
+ setter:=Sub(value) subControl.Value = value,
+ disposer:=Sub()
+ label.Dispose()
+ subControl.Dispose()
+ panel.Dispose()
+ End Sub)
End Function
Public Overrides Function ToString() As String
@@ -46,7 +46,8 @@
control:=control,
eventAdder:=Sub(action) AddHandler control.ValueChanged, Sub() action(),
getter:=Function() CByte(control.Value),
- setter:=Sub(value) control.Value = value)
+ setter:=Sub(value) control.Value = value,
+ disposer:=Sub() control.Dispose())
End Function
End Class
@@ -99,7 +100,8 @@
control:=control,
eventAdder:=Sub(action) AddHandler control.ValueChanged, Sub() action(),
getter:=Function() CUShort(control.Value),
- setter:=Sub(value) control.Value = value)
+ setter:=Sub(value) control.Value = value,
+ disposer:=Sub() control.Dispose())
End Function
End Class
@@ -152,7 +154,8 @@
control:=control,
eventAdder:=Sub(action) AddHandler control.ValueChanged, Sub() action(),
getter:=Function() CUInt(control.Value),
- setter:=Sub(value) control.Value = value)
+ setter:=Sub(value) control.Value = value,
+ disposer:=Sub() control.Dispose())
End Function
End Class
@@ -256,7 +256,8 @@
control:=control,
eventAdder:=Sub(action) AddHandler control.TextChanged, Sub() action(),
getter:=Function() Parse(control.Text),
- setter:=Sub(value) control.Text = Describe(value))
+ setter:=Sub(value) control.Text = Describe(value),
+ disposer:=Sub() control.Dispose())
End Function
Private Function SimpleMakeControl() As ISimpleValueEditor Implements ISimpleJar.MakeControl
@@ -290,12 +291,15 @@
<ContractClass(GetType(ISimpleValueEditor.ContractClass))>
Public Interface ISimpleValueEditor
+ Inherits IDisposable
+
ReadOnly Property Control As Control
Property Value As Object
Event ValueChanged(ByVal sender As ISimpleValueEditor)
<ContractClassFor(GetType(ISimpleValueEditor))>
MustInherit Class ContractClass
+ Inherits DisposableWithTask
Implements ISimpleValueEditor
Public Event ValueChanged(ByVal sender As ISimpleValueEditor) Implements ISimpleValueEditor.ValueChanged
Public ReadOnly Property Control As System.Windows.Forms.Control Implements ISimpleValueEditor.Control
@@ -340,11 +344,13 @@
End Class
Public Class DelegatedValueEditor(Of T)
+ Inherits DisposableWithTask
Implements IValueEditor(Of T)
Private ReadOnly _getter As Func(Of T)
Private ReadOnly _setter As Action(Of T)
Private ReadOnly _control As Control
+ Private ReadOnly _disposer As Action
Private _blockEvents As Boolean
@@ -355,19 +361,23 @@
Contract.Invariant(_getter IsNot Nothing)
Contract.Invariant(_setter IsNot Nothing)
Contract.Invariant(_control IsNot Nothing)
+ Contract.Invariant(_disposer IsNot Nothing)
End Sub
Public Sub New(ByVal control As Control,
ByVal getter As Func(Of T),
ByVal setter As Action(Of T),
- ByVal eventAdder As Action(Of Action))
+ ByVal eventAdder As Action(Of Action),
+ ByVal disposer As Action)
Contract.Requires(control IsNot Nothing)
Contract.Requires(getter IsNot Nothing)
Contract.Requires(setter IsNot Nothing)
Contract.Requires(eventAdder IsNot Nothing)
+ Contract.Requires(disposer IsNot Nothing)
Me._control = control
Me._getter = getter
Me._setter = setter
+ Me._disposer = disposer
Call eventAdder(AddressOf RaiseValueChanged)
End Sub
Private Sub RaiseValueChanged()
@@ -404,5 +414,11 @@
Me.Value = DirectCast(value, T).AssumeNotNull
End Set
End Property
+
+ Protected Overrides Function PerformDispose(ByVal finalizing As Boolean) As Task
+ If finalizing Then Return Nothing
+ Call _disposer()
+ Return Nothing
+ End Function
End Class
End Namespace
@@ -63,7 +63,8 @@ Namespace Pickling
control:=control,
eventAdder:=Sub(action) AddHandler control.TextChanged, Sub() action(),
getter:=Function() control.Text,
- setter:=Sub(value) control.Text = value)
+ setter:=Sub(value) control.Text = value,
+ disposer:=Sub() control.Dispose())
End Function
End Class
@@ -77,7 +77,13 @@ Namespace Pickling
Dim v = value.ItemRaw(pair.Item1.Name)
If Not c.Value.Equals(v) Then c.Value = v
Next pair
- End Sub)
+ End Sub,
+ disposer:=Sub()
+ For Each subControl In subControls
+ subControl.Dispose()
+ Next subControl
+ panel.Dispose()
+ End Sub)
End Function
End Class
End Namespace
@@ -89,7 +89,11 @@ Namespace WC3
control:=panel,
eventAdder:=Sub(action) AddHandler control.ValueChanged, Sub() action(),
getter:=Function() New PlayerId(CByte(control.Value)),
- setter:=Sub(value) control.Value = value.Index)
+ setter:=Sub(value) control.Value = value.Index,
+ disposer:=Sub()
+ label.Dispose()
+ control.Dispose()
+ End Sub)
End Function
End Class
End Namespace
@@ -99,7 +99,8 @@ Namespace WC3.Protocol
Control:=subControl.Control,
eventAdder:=Sub(action) AddHandler subControl.ValueChanged, Sub() action(),
getter:=Function() subControl.Value,
- setter:=Sub(value) subControl.Value = value)
+ setter:=Sub(value) subControl.Value = value,
+ disposer:=Sub() subControl.Dispose())
End Function
End Class
End Namespace
@@ -33,7 +33,12 @@ Namespace WC3.Protocol
setter:=Sub(value)
allocControl.Value = value.AllocatedId
counterControl.Value = value.CounterId
- End Sub)
+ End Sub,
+ disposer:=Sub()
+ allocControl.Dispose()
+ counterControl.Dispose()
+ panel.Dispose()
+ End Sub)
End Function
End Class
End Namespace
@@ -208,7 +208,8 @@ Namespace WC3.Protocol
Control:=subControl.Control,
eventAdder:=Sub(action) AddHandler subControl.ValueChanged, Sub() action(),
getter:=Function() ParseDataValue(subControl.Value),
- setter:=Sub(value) subControl.Value =PackDataValue(value))
+ setter:=Sub(value) subControl.Value = PackDataValue(value),
+ disposer:=Sub() subControl.Dispose())
End Function
End Class
End Namespace
@@ -43,7 +43,8 @@ Namespace WC3.Protocol
control:=control,
eventAdder:=Sub(action) AddHandler control.TextChanged, Sub() action(),
getter:=Function() Parse(control.Text),
- setter:=Sub(value) control.Text = Describe(value))
+ setter:=Sub(value) control.Text = Describe(value),
+ disposer:=Sub() control.Dispose())
End Function
End Class
End Namespace
@@ -55,7 +55,8 @@ Namespace WC3.Protocol
setter:=Sub(value)
control.SelectedIndex = -1
control.Text = Describe(value)
- End Sub)
+ End Sub,
+ disposer:=Sub() control.Dispose())
End Function
End Class
End Namespace
@@ -114,7 +114,8 @@ Namespace WC3.Protocol
subControl.Value.ItemAs(Of IReadableList(Of GameAction))("actions")),
setter:=Sub(value) subControl.Value = New Dictionary(Of InvariantString, Object) From {
{"source", value.Id},
- {"actions", value.Actions}})
+ {"actions", value.Actions}},
+ disposer:=Sub() subControl.Dispose())
End Function
End Class
End Namespace
@@ -99,7 +99,8 @@ Namespace WC3.Replay
Control:=subControl.Control,
eventAdder:=Sub(action) AddHandler subControl.ValueChanged, Sub() action(),
getter:=Function() subControl.Value,
- setter:=Sub(value) subControl.Value = value)
+ setter:=Sub(value) subControl.Value = value,
+ disposer:=Sub() subControl.Dispose())
End Function
End Class
End Namespace

0 comments on commit 72e6370

Please sign in to comment.