-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSpiderBiteConfig.pb
507 lines (338 loc) · 13.8 KB
/
SpiderBiteConfig.pb
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
EnableExplicit
Structure sSpiderBiteCfg
PbCompiler.s
AspxTemplate.s
AspxServerFilename.s
AspxServerAddress.s
AspTemplate.s
AspServerFilename.s
AspServerAddress.s
PbCgiTemplate.s
PbCgiServerFilename.s
PbCgiServerAddress.s
NodeJsServerFilename.s
NodeJsServerAddress.s
NodeJsTemplate.s
PhpTemplate.s
PhpServerFilename.s
PhpServerAddress.s
PythonTemplate.s
PythonServerFilename.s
PythonServerAddress.s
EndStructure
Global NewMap SpiderBiteCfg.sSpiderBiteCfg()
Global GlobalQuit
Global DialogXML
Global Dialog
#AppName = "SpiderBiteConfig"
XIncludeFile "includes/functions.pbi"
Enumeration
#Action_Add = 1
#Action_Edit
#Action_Delete
EndEnumeration
Global Action
Runtime Enumeration
#winConfig
#winConfig_txtProfileName
#winConfig_txtPbCompiler
#winConfig_cmdPbCompiler
#winConfig_txtPbCgiTemplate
#winConfig_cmdPbCgiTemplate
#winConfig_txtPbCgiServerFilename
#winConfig_cmdPbCgiServerFilename
#winConfig_txtPbCgiServerAddress
#winConfig_txtPhpTemplate
#winConfig_cmdPhpTemplate
#winConfig_txtPhpServerFilename
#winConfig_cmdPhpServerFilename
#winConfig_txtPhpServerAddress
#winConfig_txtAspTemplate
#winConfig_cmdAspTemplate
#winConfig_txtAspServerFilename
#winConfig_cmdAspServerFilename
#winConfig_txtAspServerAddress
#winConfig_txtAspxTemplate
#winConfig_cmdAspxTemplate
#winConfig_txtAspxServerFilename
#winConfig_cmdAspxServerFilename
#winConfig_txtAspxServerAddress
#winConfig_txtNodeJsFilename
#winConfig_cmdNodeJsFilename
#winConfig_txtNodeJsServerAddress
#winConfig_txtPythonTemplate
#winConfig_cmdPythonTemplate
#winConfig_txtPythonServerFilename
#winConfig_cmdPythonServerFilename
#winConfig_txtPythonServerAddress
#winConfig_cmdOK
#winConfig_cmdCancel
#winMain
#winMain_lstProfiles
#winMain_cmdAdd
#winMain_cmdEdit
#winMain_cmdDelete
#winMain_txtProfileName
#winMain_cmdCopyToClipboard
EndEnumeration
Procedure LoadConfig()
Protected Filename.s = GetExePath() + "SpiderBite.cfg"
If LoadJSON(0, FileName)
ExtractJSONMap(JSONValue(0), SpiderBiteCfg())
EndIf
EndProcedure
Procedure SaveConfig()
Protected Filename.s = GetExePath() + "SpiderBite.cfg"
If CreateJSON(0)
InsertJSONMap(JSONValue(0), SpiderBiteCfg())
SaveJSON(0, FileName, #PB_JSON_PrettyPrint)
EndIf
EndProcedure
Runtime Procedure winConfig_ChoosePathEvent()
Protected Filename.s
Protected SelectedFilename.s
Select EventGadget()
Case #winConfig_cmdPbCompiler
Filename = GetGadgetText(#winConfig_txtPbCompiler)
Case #winConfig_cmdPbCgiTemplate
Filename = GetGadgetText(#winConfig_txtPbCgiTemplate)
Case #winConfig_cmdPbCgiServerFilename
Filename = GetGadgetText(#winConfig_txtPbCgiServerFilename)
Case #winConfig_cmdPhpTemplate
Filename = GetGadgetText(#winConfig_txtPhpTemplate)
Case #winConfig_cmdPhpServerFilename
Filename = GetGadgetText(#winConfig_txtPhpServerFilename)
Case #winConfig_cmdAspTemplate
Filename = GetGadgetText(#winConfig_txtAspTemplate)
Case #winConfig_cmdAspServerFilename
Filename = GetGadgetText(#winConfig_txtAspServerFilename)
Case #winConfig_cmdAspxTemplate
Filename = GetGadgetText(#winConfig_txtAspxTemplate)
Case #winConfig_cmdAspxServerFilename
Filename = GetGadgetText(#winConfig_txtAspxServerFilename)
Case #winConfig_cmdPythonTemplate
Filename = GetGadgetText(#winConfig_txtPythonTemplate)
Case #winConfig_cmdPythonServerFilename
Filename = GetGadgetText(#winConfig_txtPythonServerFilename)
EndSelect
SelectedFilename = OpenFileRequester("Please choose a file", Filename, "All files (*.*)|*.*", 0)
If SelectedFilename
Select EventGadget()
Case #winConfig_cmdPbCompiler
SetGadgetText(#winConfig_txtPbCompiler, SelectedFilename)
Case #winConfig_cmdPbCgiTemplate
SetGadgetText(#winConfig_txtPbCgiTemplate, SelectedFilename)
Case #winConfig_cmdPbCgiServerFilename
SetGadgetText(#winConfig_txtPbCgiServerFilename, SelectedFilename)
Case #winConfig_cmdPhpTemplate
SetGadgetText(#winConfig_txtPhpTemplate, SelectedFilename)
Case #winConfig_cmdPhpServerFilename
SetGadgetText(#winConfig_txtPhpServerFilename, SelectedFilename)
Case #winConfig_cmdAspTemplate
SetGadgetText(#winConfig_txtAspTemplate, SelectedFilename)
Case #winConfig_cmdAspServerFilename
SetGadgetText(#winConfig_txtAspServerFilename, SelectedFilename)
Case #winConfig_cmdAspxTemplate
SetGadgetText(#winConfig_txtAspxTemplate, SelectedFilename)
Case #winConfig_cmdAspxServerFilename
SetGadgetText(#winConfig_txtAspxServerFilename, SelectedFilename)
Case #winConfig_cmdPythonTemplate
SetGadgetText(#winConfig_txtPythonTemplate, SelectedFilename)
Case #winConfig_cmdPythonServerFilename
SetGadgetText(#winConfig_txtPythonServerFilename, SelectedFilename)
EndSelect
EndIf
EndProcedure
Procedure CheckButtons()
Protected Flag = #False
If GetGadgetState(#winMain_lstProfiles) = -1
Flag = #True
EndIf
DisableGadget(#winMain_cmdEdit, Flag)
DisableGadget(#winMain_cmdDelete, Flag)
If Flag = #False
SetGadgetText(#winMain_txtProfileName, "#SpiderBite_Profile = " + Chr(34) + GetGadgetText(#winMain_lstProfiles) + Chr(34))
Else
SetGadgetText(#winMain_txtProfileName, "")
EndIf
EndProcedure
Procedure ReFillProfileList(ProfileName.s = "")
NewList DummyList.s()
ForEach SpiderBiteCfg()
AddElement(DummyList())
DummyList() = MapKey(SpiderBiteCfg())
Next
SortList(DummyList(), #PB_Sort_Ascending | #PB_Sort_NoCase)
ClearGadgetItems(#winMain_lstProfiles)
ForEach DummyList()
AddGadgetItem(#winMain_lstProfiles, -1, DummyList())
Next
If ProfileName <> ""
SetGadgetText(#winMain_lstProfiles, ProfileName)
EndIf
If GetGadgetState(#winMain_lstProfiles) = -1
SetGadgetState(#winMain_lstProfiles, 0)
EndIf
CheckButtons()
EndProcedure
Runtime Procedure winConfig_cmdOK_Event()
Protected ProfileName.s = Trim(GetGadgetText(#winConfig_txtProfileName))
Protected ProfileNameExists
If ProfileName = ""
MessageRequester(#AppName, "ProfileName must not be empty.")
SetActiveGadget(#winConfig_txtProfileName)
ProcedureReturn
EndIf
Select Action
Case #Action_Add
; Check, if ProfileName exists...
ForEach SpiderBiteCfg()
If LCase(ProfileName) = LCase(MapKey(SpiderBiteCfg()))
ProfileNameExists = #True
Break
EndIf
Next
If ProfileNameExists
MessageRequester(#AppName, "ProfileName already exists." + #LF$ + "Please choose another one.")
SetActiveGadget(#winConfig_txtProfileName)
ProcedureReturn
EndIf
Case #Action_Edit
If LCase(ProfileName) <> LCase(GetGadgetText(#winMain_lstProfiles))
; rename profilename
; Check, if ProfileName exists elsewhere...
ForEach SpiderBiteCfg()
If LCase(ProfileName) = LCase(MapKey(SpiderBiteCfg()))
ProfileNameExists = #True
Break
EndIf
Next
If ProfileNameExists
MessageRequester(#AppName, "ProfileName already exists." + #LF$ + "Please choose another one.")
SetActiveGadget(#winConfig_txtProfileName)
ProcedureReturn
EndIf
EndIf
DeleteMapElement(SpiderBiteCfg(), GetGadgetText(#winMain_lstProfiles))
EndSelect
SpiderBiteCfg(ProfileName)\PbCompiler = GetGadgetText(#winConfig_txtPbCompiler)
SpiderBiteCfg(ProfileName)\PbCgiTemplate = GetGadgetText(#winConfig_txtPbCgiTemplate)
SpiderBiteCfg(ProfileName)\PbCgiServerFilename = GetGadgetText(#winConfig_txtPbCgiServerFilename)
SpiderBiteCfg(ProfileName)\PbCgiServerAddress = GetGadgetText(#winConfig_txtPbCgiServerAddress)
SpiderBiteCfg(ProfileName)\PhpTemplate = GetGadgetText(#winConfig_txtPhpTemplate)
SpiderBiteCfg(ProfileName)\PhpServerFilename = GetGadgetText(#winConfig_txtPhpServerFilename)
SpiderBiteCfg(ProfileName)\PhpServerAddress = GetGadgetText(#winConfig_txtPhpServerAddress)
SpiderBiteCfg(ProfileName)\AspTemplate = GetGadgetText(#winConfig_txtAspTemplate)
SpiderBiteCfg(ProfileName)\AspServerFilename = GetGadgetText(#winConfig_txtAspServerFilename)
SpiderBiteCfg(ProfileName)\AspServerAddress = GetGadgetText(#winConfig_txtAspServerAddress)
SpiderBiteCfg(ProfileName)\AspxTemplate = GetGadgetText(#winConfig_txtAspxTemplate)
SpiderBiteCfg(ProfileName)\AspxServerFilename = GetGadgetText(#winConfig_txtAspxServerFilename)
SpiderBiteCfg(ProfileName)\AspxServerAddress = GetGadgetText(#winConfig_txtAspxServerAddress)
SpiderBiteCfg(ProfileName)\PythonTemplate = GetGadgetText(#winConfig_txtPythonTemplate)
SpiderBiteCfg(ProfileName)\PythonServerFilename = GetGadgetText(#winConfig_txtPythonServerFilename)
SpiderBiteCfg(ProfileName)\PythonServerAddress = GetGadgetText(#winConfig_txtPythonServerAddress)
SaveConfig()
CloseWindow(#winConfig)
ReFillProfileList(ProfileName)
DisableWindow(#winMain, #False)
EndProcedure
Runtime Procedure winConfig_cmdCancel_Event()
CloseWindow(#winConfig)
DisableWindow(#winMain, #False)
EndProcedure
Procedure winConfig_Close()
CloseWindow(#winConfig)
DisableWindow(#winMain, #False)
EndProcedure
Runtime Procedure winMain_cmdAdd_Event()
Action = #Action_Add
DisableWindow(#winMain, #True)
OpenXMLDialog(Dialog, DialogXML, "winConfig", #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore, WindowID(#winMain))
SetWindowTitle(#winConfig, "Add profile")
BindEvent(#PB_Event_CloseWindow, @winConfig_Close(), #winConfig)
SetActiveGadget(#winConfig_txtProfileName)
EndProcedure
Runtime Procedure winMain_cmdEdit_Event()
Action = #Action_Edit
DisableWindow(#winMain, #True)
OpenXMLDialog(Dialog, DialogXML, "winConfig", #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore, WindowID(#winMain))
SetWindowTitle(#winConfig, "Edit profile")
BindEvent(#PB_Event_CloseWindow, @winConfig_Close(), #winConfig)
Protected SelectedProfile.s = GetGadgetText(#winMain_lstProfiles)
SetGadgetText(#winConfig_txtProfileName, SelectedProfile)
SetGadgetText(#winConfig_txtPbCompiler, SpiderBiteCfg(SelectedProfile)\PbCompiler)
SetGadgetText(#winConfig_txtPbCgiTemplate, SpiderBiteCfg(SelectedProfile)\PbCgiTemplate)
SetGadgetText(#winConfig_txtPbCgiServerFilename, SpiderBiteCfg(SelectedProfile)\PbCgiServerFilename)
SetGadgetText(#winConfig_txtPbCgiServerAddress, SpiderBiteCfg(SelectedProfile)\PbCgiServerAddress)
SetGadgetText(#winConfig_txtPhpTemplate, SpiderBiteCfg(SelectedProfile)\PhpTemplate)
SetGadgetText(#winConfig_txtPhpServerFilename, SpiderBiteCfg(SelectedProfile)\PhpServerFilename)
SetGadgetText(#winConfig_txtPhpServerAddress, SpiderBiteCfg(SelectedProfile)\PhpServerAddress)
SetGadgetText(#winConfig_txtAspTemplate, SpiderBiteCfg(SelectedProfile)\AspTemplate)
SetGadgetText(#winConfig_txtAspServerFilename, SpiderBiteCfg(SelectedProfile)\AspServerFilename)
SetGadgetText(#winConfig_txtAspServerAddress, SpiderBiteCfg(SelectedProfile)\AspServerAddress)
SetGadgetText(#winConfig_txtAspxTemplate, SpiderBiteCfg(SelectedProfile)\AspxTemplate)
SetGadgetText(#winConfig_txtAspxServerFilename, SpiderBiteCfg(SelectedProfile)\AspxServerFilename)
SetGadgetText(#winConfig_txtAspxServerAddress, SpiderBiteCfg(SelectedProfile)\AspxServerAddress)
SetGadgetText(#winConfig_txtPythonTemplate, SpiderBiteCfg(SelectedProfile)\PythonTemplate)
SetGadgetText(#winConfig_txtPythonServerFilename, SpiderBiteCfg(SelectedProfile)\PythonServerFilename)
SetGadgetText(#winConfig_txtPythonServerAddress, SpiderBiteCfg(SelectedProfile)\PythonServerAddress)
EndProcedure
Runtime Procedure winMain_cmdDelete_Event()
If MessageRequester(#AppName, "Sure?", #PB_MessageRequester_YesNo)=#PB_MessageRequester_No
ProcedureReturn
EndIf
Action = #Action_Delete
Protected SelectedProfile.s = GetGadgetText(#winMain_lstProfiles)
DeleteMapElement(SpiderBiteCfg(), SelectedProfile)
SaveConfig()
ReFillProfileList()
EndProcedure
Runtime Procedure winMain_cmdCopyToClipboard_Event()
SetClipboardText(GetGadgetText(#winMain_txtProfileName))
EndProcedure
Procedure winMain_Close()
GlobalQuit = #True
EndProcedure
Procedure winMain_Open()
OpenXMLDialog(Dialog, DialogXML, "winMain")
BindEvent(#PB_Event_CloseWindow, @winMain_Close(), #winMain)
DisableGadget(#winMain_txtProfileName, #True)
Protected SelectedWord.s = GetEnvironmentVariable("PB_TOOL_Word")
If FindMapElement(SpiderBiteCfg(), SelectedWord) = 0
SelectedWord = ""
EndIf
ReFillProfileList(SelectedWord)
EndProcedure
Runtime Procedure winMain_lstProfiles_Event()
CheckButtons()
If EventType() = #PB_EventType_LeftDoubleClick
If GetGadgetState(#winMain_lstProfiles) > -1
winMain_cmdEdit_Event()
EndIf
EndIf
EndProcedure
Procedure Main()
Protected Event
DialogXML = ParseXML(#PB_Any, PeekS(?SpiderBiteConfigDialogs, -1, #PB_UTF8))
If DialogXML
If XMLStatus(DialogXML) = #PB_XML_Success
Dialog = CreateDialog(#PB_Any)
winMain_Open()
Repeat
Event = WaitWindowEvent()
If GlobalQuit
Break
EndIf
ForEver
Else
Debug "XML error: " + XMLError(DialogXML) + " (Line: " + XMLErrorLine(DialogXML) + ")"
EndIf
EndIf
EndProcedure
LoadConfig()
Main()
DataSection
SpiderBiteConfigDialogs:
IncludeBinary "includes/SpiderBiteConfigDialogs.xml"
Data.b 0
EndDataSection