-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathViewToDictionaryBinder.cls
104 lines (91 loc) · 3.09 KB
/
ViewToDictionaryBinder.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "ViewToDictionaryBinder"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
'===============================================================================
' Ìîäóëü : FormToDictionaryBinder
' Âåðñèÿ : 2024.06.18
' Àâòîð : elvin-nsk ([email protected])
' Ñàéò : https://github.com/elvin-nsk/LowCoupledFromCore
' Íàçíà÷åíèå : Ïðèâÿçûâàåò êîíòðîëû ôîðìû ê ñëîâàðþ
' äëÿ àâòîìàòè÷åñêîé çàãðóçêè/ñîõðàíåíèÿ ñîñòîÿíèÿ
' Çàâèñèìîñòè : LibCore, JsonConverter
'===============================================================================
'@Interface
'@PredeclaredId
Option Explicit
'===============================================================================
' # Declarations
Private Type This
ControlNames As Variant
Dictionary As Scripting.IDictionary
ReadOnly As Boolean
View As MSForms.UserForm
End Type
Private This As This
Attribute This.VB_VarHelpID = -1
'===============================================================================
' # Constructors
Friend Function New_( _
ByVal Dictionary As Scripting.IDictionary, _
ByVal View As MSForms.UserForm, _
ByVal ControlNames As Variant _
) As ViewToDictionaryBinder
Set New_ = New ViewToDictionaryBinder
New_.Inject Dictionary, View, ControlNames
End Function
Friend Sub Inject( _
ByVal Dictionary As Scripting.IDictionary, _
ByVal View As MSForms.UserForm, _
ByVal ControlNames As Variant _
)
With This
Set .Dictionary = Dictionary
Assign .ControlNames, ControlNames
Set .View = View
.ReadOnly = ReadOnly
RefreshForm
End With
End Sub
'===============================================================================
' # Public
Public Property Get Dictionary() As Scripting.Dictionary
Set Dictionary = This.Dictionary
End Property
'@DefaultMember
Public Property Get Item(ByVal Key As String) As Variant
Item = This.Dictionary(Key)
End Property
Public Property Let Item(ByVal Key As String, RHS As Variant)
Attribute Item.VB_UserMemId = 0
This.Dictionary(Key) = RHS
End Property
Public Function RefreshDictionary() As Scripting.Dictionary
With This
Dim ItemName As Variant
For Each ItemName In This.ControlNames
.Dictionary(ItemName) = .View.Controls(ItemName)
Next ItemName
Set RefreshDictionary = .Dictionary
End With
End Function
Public Sub RefreshForm()
With This
Dim ItemName As Variant
For Each ItemName In This.ControlNames
If .Dictionary.Exists(ItemName) Then
.View.Controls(ItemName) = .Dictionary(ItemName)
End If
Next ItemName
End With
End Sub
Public Property Get Self() As ViewToDictionaryBinder
Set Self = Me
End Property
'===============================================================================
' # Helpers