-
Notifications
You must be signed in to change notification settings - Fork 34
/
iwp-main-dialog.rkt
executable file
·363 lines (273 loc) · 12.9 KB
/
iwp-main-dialog.rkt
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#lang racket
;; This module implements IWP main control panel window
;; License GPLv3
;; (c) 2010-2017 Corvideon Ltd
(provide
;; show the main gui
show-main-window
;; hide the main gui
hide-main-window)
;; —————————————————————————————————
;; import and implementation section
(require
racket/gui/base
"iwp-config.rkt"
"iwp-constants.rkt"
"iwp-resources.rkt"
"iwp-environment.rkt"
"iwp-actions.rkt"
"iwp-quit-dialog.rkt")
;; --------------------------------------
;; button and label creation functions
;; --------------------------------------
;; get the button sleep delay
(define BUTTON_SLEEP (string->number (get-config-setting "buttonSleepAfterClick")))
(define (create-new-button parent bitmap label width height callback)
(new button% [parent parent]
[label (list bitmap (lpad label) 'left)]
[min-width width]
[min-height height]
[callback (lambda (button event)
(callback))]))
(define (create-new-label label width height parent)
(new message%
[label label]
[enabled LBL_ENABLED]
[min-width width]
[min-height height]
[parent parent]
[stretchable-height #f]))
(define (lpad label-string)
(string-append LEFT_PADDING label-string))
;; --------------------------------------
;; define main window
;; --------------------------------------
;; define root window value hash
(define iwp-window-hash (make-hash))
;; get the window title - VERSION/PREFNAME
(define window-title (string-append IWP_DIALOG_TITLE
" ("(get-config-setting "AppVersion") " / "
(get-config-setting "AppPreferredName") " / "
(get-config-setting "AppDate") ")"))
;; set the root window hash values
(hash-set! iwp-window-hash "label" window-title)
(hash-set! iwp-window-hash "width" MAIN_GUI_WIDTH)
(hash-set! iwp-window-hash "height" MAIN_GUI_HEIGHT)
;; turn on/off the WP Resources in tab list
(define (get-tab-list)
(cond
[(string=? (get-config-setting "showWPResourcesTab") "no") (list CONTROL_PANEL_TAB ADVANCED_TAB)]
[(string=? (get-config-setting "showWPResourcesTab") "yes") (list CONTROL_PANEL_TAB ADVANCED_TAB WP_RESOURCES_TAB)]))
;; set up tabs
(define my-tabs-list (get-tab-list))
;; custom frame with exit - main window
(define root-window (new (class frame% (super-new)
(define/augment (on-close)
(do-exit)))
[label (hash-ref iwp-window-hash "label")]
[width (hash-ref iwp-window-hash "width")]
[height (hash-ref iwp-window-hash "height")]
[style '(no-resize-border)]))
;; logo at the top of dialog
(define logo (iwp-logo))
(define logo-label (new message% (parent root-window) (label logo)))
;; define tab control
(define tab-control (new tab-panel%
(parent root-window)
(choices my-tabs-list)
(callback
(lambda (tpanel event)
(case (send tpanel get-selection)
((0) (send tpanel change-children (lambda (children) (list start-panel))))
((1) (send tpanel change-children (lambda (children) (list advanced-panel))))
((2) (send tpanel change-children (lambda (children) (list wp-resources-panel)))))))))
;; define panels
(define start-panel (new panel% (parent tab-control)))
(define advanced-panel (new vertical-panel% (parent tab-control)))
(define wp-resources-panel (new panel% (parent tab-control)))
;; this panel holds the buttons at the bottom of dialog
(define base-buttons-panel (new horizontal-pane% (parent root-window) [alignment '(right bottom)] [stretchable-height #f]))
;; hide other tabs
(send tab-control change-children (lambda (children) (list start-panel)))
;; --------------------------------------
;; main window control functions
;; --------------------------------------
;; Show the frame by calling its show method
(define (show-main-window)
(send root-window show #t)
(send root-window center))
;; Hide the frame by calling its show method
(define (hide-main-window)
(send root-window show #f))
;; quit action
(define (do-quit-action)
(cond
[(should-quit-iwp?) (do-exit)]))
(define (do-exit)
(message-box "InstantWP Close" "InstantWP will now close." #f '(ok no-icon))
(hide-main-window)
(show-quit-window)
(exit 1))
;; --------------------------------------
;; start panel control definitions
;; --------------------------------------
;; start panel vertical panel for holding horizontal panels
(define start-panel-v0 (new vertical-pane% (parent start-panel) [alignment '(center center)] [border 10]))
;; start panel horizontal panels
(define start-panel-h0 (new horizontal-pane% (parent start-panel-v0) [alignment '(center top)]))
(define start-panel-h1 (new horizontal-pane% (parent start-panel-v0) [alignment '(center top)]))
(define start-panel-h2 (new horizontal-pane% (parent start-panel-v0) [alignment '(center top)]))
(define start-panel-h3 (new horizontal-pane% (parent start-panel-v0) [alignment '(center top)]))
(define start-panel-h4 (new horizontal-pane% (parent start-panel-v0) [alignment '(center top)]))
(define start-panel-h5 (new horizontal-pane% (parent start-panel-v0) [alignment '(center top)]))
(define wp-frontpage-button
(create-new-button start-panel-h0 (wp-frontpage-bitmap) "WordPress Frontpage"
MAIN_BTN_WIDTH MAIN_BTN_HEIGHT
do-wpfrontpage-action))
(define wp-frontpage-label
(create-new-label WPFRONTPAGE_INFO MAIN_LBL_WIDTH 10 start-panel-h0))
(define wp-admin-button
(create-new-button start-panel-h1 (wp-admin-bitmap) "WordPress Admin"
MAIN_BTN_WIDTH MAIN_BTN_HEIGHT
do-wpadmin-action))
(define wp-admin-label
(create-new-label WPADMIN_INFO MAIN_LBL_WIDTH MAIN_LBL_HEIGHT start-panel-h1))
(define wp-themes-button
(create-new-button start-panel-h2 (wp-themes-bitmap) "Themes Folder"
MAIN_BTN_WIDTH MAIN_BTN_HEIGHT
do-themes-action))
(define wp-themes-label
(create-new-label WPTHEMES_INFO MAIN_LBL_WIDTH MAIN_LBL_HEIGHT start-panel-h2))
(define wp-plugins-button
(create-new-button start-panel-h3 (wp-plugins-bitmap) "Plugin Folder"
MAIN_BTN_WIDTH MAIN_BTN_HEIGHT
do-plugins-action))
(define wp-plugins-label
(create-new-label WPPLUGINS_INFO MAIN_LBL_WIDTH MAIN_LBL_HEIGHT start-panel-h3))
(define wp-mysql-button
(create-new-button start-panel-h4 (wp-mysql-bitmap) "MySQL Admin"
MAIN_BTN_WIDTH MAIN_BTN_HEIGHT
do-mysql-action))
(define wp-mysql-label
(create-new-label MYSQL_INFO MAIN_LBL_WIDTH MAIN_LBL_HEIGHT start-panel-h4))
(define docs-button
(create-new-button start-panel-h5 (wp-docs-bitmap) "Help"
MAIN_BTN_WIDTH MAIN_BTN_HEIGHT
do-docs-action))
(define docs-label
(create-new-label DOCS_INFO MAIN_LBL_WIDTH MAIN_LBL_HEIGHT start-panel-h5))
;; Deployment Button details
(define (create-new-deploy-button parent bitmap width height callback)
(new button% [parent parent]
[label bitmap]
[callback (lambda (button event)
(callback))]))
(define (do-deploy-action) (do-open-url "https://instantwp.com/go/IWPControlPanelButton/"))
(define deployment-button
(create-new-deploy-button base-buttons-panel (deploy-bitmap)
MAIN_BTN_WIDTH MAIN_BTN_HEIGHT
do-deploy-action))
(cond
[(string=? (get-config-setting SHOW_DEPLOY) "no") (send deployment-button show #f)])
;; -----
;; About button definition
(define about-button
(create-new-button base-buttons-panel (about-bitmap) "About"
MAIN_BTN_WIDTH MAIN_BTN_HEIGHT
do-about-action))
;; Quit button definition
(define quit-button
(create-new-button base-buttons-panel (quit-bitmap) "Quit"
MAIN_BTN_WIDTH MAIN_BTN_HEIGHT
do-quit-action))
;; --------------------------------------
;; advanced panel control definitions
;; --------------------------------------
;; start panel vertical panel for holding horizontal panels
(define advanced-panel-v0 (new vertical-pane% (parent advanced-panel) [alignment '(center center)] [border 10]))
;; advanced panel horizontal panels
(define advanced-panel-h0 (new horizontal-pane% (parent advanced-panel-v0) [alignment '(center top)]))
(define advanced-panel-h1 (new horizontal-pane% (parent advanced-panel-v0) [alignment '(center top)]))
(define advanced-panel-h2 (new horizontal-pane% (parent advanced-panel-v0) [alignment '(center top)]))
(define advanced-panel-h3 (new horizontal-pane% (parent advanced-panel-v0) [alignment '(center top)]))
(define advanced-panel-h4 (new horizontal-pane% (parent advanced-panel-v0) [alignment '(center top)]))
(define advanced-panel-h5 (new horizontal-pane% (parent advanced-panel-v0) [alignment '(center top)]))
;; SSH button and label
(define ssh-button
(create-new-button advanced-panel-h0 (ssh-bitmap) "SSH Terminal"
ADV_BTN_WIDTH ADV_BTN_HEIGHT
do-start-ssh))
(define ssh-label
(create-new-label SSH_INFO ADV_LBL_WIDTH ADV_LBL_HEIGHT advanced-panel-h0))
;; SFTP button and label
(define sftp-button
(create-new-button advanced-panel-h1 (sftp-bitmap) "SFTP Client"
ADV_BTN_WIDTH ADV_BTN_HEIGHT
do-start-sftp))
(define sftp-label
(create-new-label SFTP_INFO ADV_LBL_WIDTH ADV_LBL_HEIGHT advanced-panel-h1))
;; QEMU monitor button and label
(define qemu-button
(create-new-button advanced-panel-h2 (qemu-bitmap) "QEMU Monitor"
ADV_BTN_WIDTH ADV_BTN_HEIGHT
do-start-qemu-monitor))
(define qemu-label
(create-new-label QEMU_MONITOR_INFO ADV_LBL_WIDTH ADV_LBL_HEIGHT advanced-panel-h2))
;; Web console button and label
(define webconsole-button
(create-new-button advanced-panel-h3 (webconsole-bitmap) "IWP Web Console"
ADV_BTN_WIDTH ADV_BTN_HEIGHT
do-webconsole-action))
(define webconsole-label
(create-new-label WEB_CONSOLE_INFO ADV_LBL_WIDTH ADV_LBL_HEIGHT advanced-panel-h3))
;; Edit config button and label
(define edit-config-button
(create-new-button advanced-panel-h4 (edit-config-bitmap) "Edit Config File"
ADV_BTN_WIDTH ADV_BTN_HEIGHT
do-start-edit-config))
(define edit-config-label
(create-new-label EDIT_CONFIG_INFO ADV_LBL_WIDTH ADV_LBL_HEIGHT advanced-panel-h4))
;; PHP info button and label
(define phpinfo-button
(create-new-button advanced-panel-h5 (phpinfo-bitmap) "PHP Info"
ADV_BTN_WIDTH ADV_BTN_HEIGHT
do-phpinfo-action))
(define phpinfo-label
(create-new-label PHP_INFO_INFO ADV_LBL_WIDTH ADV_LBL_HEIGHT advanced-panel-h5))
;; --------------------------------------
;; wp resources panel control definitions
;; --------------------------------------
;; wp-resources panel vertical panel for holding horizontal panels
(define wp-resources-panel-v0 (new vertical-pane% (parent wp-resources-panel) [alignment '(center center)] [border 10]))
;; wp-resources panel horizontal panel for holding horizontal panels
(define wp-resources-h0 (new horizontal-pane% (parent wp-resources-panel-v0) [alignment '(center top)]))
(define wp-resources-h1 (new horizontal-pane% (parent wp-resources-panel-v0) [alignment '(center top)]))
(define wp-resources-h2 (new horizontal-pane% (parent wp-resources-panel-v0) [alignment '(center top)]))
(define wp-resources-h3 (new horizontal-pane% (parent wp-resources-panel-v0) [alignment '(center top)]))
;; WP Resources image
(define wp-resources-logo (new message% (parent wp-resources-h0) (label (wp-resources))))
;; WP Resources buttons
(define wp-resources-plugins-button
(new button% [parent wp-resources-h1]
[label (list (wp-frontpage-bitmap) (lpad "WordPress Plugins") 'left)]
[min-width WP_RESOURCES_BTN_WIDTH]
[min-height WP_RESOURCES_BTN_HEIGHT]
[stretchable-height #f ]
[callback (lambda (button event)
(do-wp-resources-action-plugins))]))
(define wp-resources-themes-button
(new button% [parent wp-resources-h2]
[label (list (wp-frontpage-bitmap) (lpad "WordPress Themes") 'left)]
[min-width WP_RESOURCES_BTN_WIDTH]
[min-height WP_RESOURCES_BTN_HEIGHT]
[stretchable-height #f ]
[callback (lambda (button event)
(do-wp-resources-action-themes))]))
(define wp-resources-hosting-button
(new button% [parent wp-resources-h3]
[label (list (wp-frontpage-bitmap) (lpad "WordPress Hosting") 'left)]
[min-width WP_RESOURCES_BTN_WIDTH]
[min-height WP_RESOURCES_BTN_HEIGHT]
[stretchable-height #f ]
[callback (lambda (button event)
(do-wp-resources-action-hosting))]))