-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUI.bas
160 lines (96 loc) · 2.97 KB
/
UI.bas
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
Attribute VB_Name = "UI"
Option Explicit
Private ribbon As Office.IRibbonUI
Private Sub UpdateUI()
ribbon.Invalidate
End Sub
Private Sub UpdateControl(control As IRibbonControl)
ribbon.InvalidateControl control.Id
End Sub
' This is an event
Public Sub OnUILoaded(rbn As IRibbonUI)
On Error GoTo HandleError
Set ribbon = rbn
Main.Init
UpdateUI
Exit Sub
HandleError:
LogLastErrorAt "UI.OnUILoaded"
End Sub
' This is a UI callabck
Public Sub ProcessText(control As IRibbonControl, text As String)
If Not IsNumeric(text) Then
MsgBox "Positive integer number required!", vbCritical, "PPVoting error"
UpdateControl control
Exit Sub
End If
If CInt(text) <= 0 Then
MsgBox "Positive integer number required!", vbCritical, "PPVoting error"
UpdateControl control
Exit Sub
End If
Utils.UpdateSetting control.Tag, CInt(text)
End Sub
' This is a UI callabck
Public Sub GetText(control As IRibbonControl, ByRef text As Variant)
text = settings(control.Tag)
End Sub
' This is a UI callabck
Public Sub ProcessBool(control As IRibbonControl, state As Boolean)
Utils.UpdateSetting control.Tag, state
End Sub
' This is a UI callabck
Public Sub GetBool(control As IRibbonControl, ByRef state As Variant)
state = settings(control.Tag)
End Sub
' This is a UI callabck
Public Sub CheckConnection()
voting.CheckConnection
End Sub
' This is a UI callabck
Public Sub ChooseLogFile()
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.InitialFileName = "*.txt"
If .Show <> -1 Then Exit Sub
Dim path As String
path = .SelectedItems(1)
Utils.UpdateSetting "logging.file", path
End With
End Sub
' This is a UI callabck
Public Sub ViewLogFile()
On Error GoTo HandleError
Dim path As String
path = settings("logging.file")
If path = "" Then
MsgBox "No log file selected", vbInformation, "PPVoting info"
Exit Sub
End If
If Dir(path) = "" Then
MsgBox "Cannot find " & Utils.QuoteString(path), vbExclamation, "PPVoting info"
Exit Sub
End If
Utils.GetShell().Run "notepad " & Utils.QuoteString(path)
Exit Sub
HandleError:
LogLastErrorAt "UI.ViewLogFile"
End Sub
' This is a UI callabck
Public Sub OpenDeviceManager()
On Error GoTo HandleError
Utils.GetShell().Run "devmgmt.msc"
Exit Sub
HandleError:
LogLastErrorAt "UI.OpenDeviceManager"
End Sub
' This is a UI callabck
Public Sub RemoveSettings()
Dim result As Boolean
result = Utils.DeleteSettings
If result Then
MsgBox "Successfully removed all PPVoting settings", vbInformation, "PPVoting info"
Else
MsgBox "No PPVoting settings present", vbExclamation, "PPVoting info"
End If
End Sub