-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhat you see.ahk
1891 lines (1610 loc) · 59.8 KB
/
what you see.ahk
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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; initial declarations
#SingleInstance off ;force
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
;--------------------------------------------------------------------------------------
; Version with:
; listbox for showing code
; parameter for input file
; external ini file
;--------------------------------------------------------------------------------------
; parameters:
; A_Args[1] = routine calls file = outfile.txt
; A_Args[2] = source code file = outfile.cbl
; A_Args[3] = path where above files created = z:\bussup\txt\\
; A_Args[4] = use existing files or select = *NEW|*OLD|*SELECT (default)
; *NEW = try to load above files
; *OLD = use existing file found in showRoutines.ini
; *SELECT = open file selector
;
;--------------------------------------------------------------------------------------
; 1. read text file CBTREEF5.TXT containing the output of program CBTREER5:
; 00001, 0886.00, 0913.00, 0899.00,MAIN ,INITIALIZE-ROUTINE
; 00002, 0886.00, 0913.00, 0900.00,MAIN ,MAIN-ROUTINE
; 00003, 0916.00, 0940.00, 0000.00,INITIALIZE-ROUTINE ,
; 00004, 0943.00, 0976.00, 0968.00,MAIN-ROUTINE ,RFCONLIF-ROUTINE
; etc...
; 2. populate array of routines allRoutines[] with above data.
;--------------------------------------------------------------------------------------
; file cbtreef5.txt was created in AS400 with:
; cbtree_2 ....
; cpyf qtemp/cbtreef5 dcommon/cbtreef5 *replace
; CVTDBF FROMFILE(DCOMMON/CBTREEF5) TOSTMF('/output/bussup/txt/cbtreef5') TOFMT(*FIXED) FIXED(*CRLF (*DBF) (*DBF) *SYSVAL *COMMA)
;--------------------------------------------------------------------------------------
global allRoutines ; array of class "routine"
global allCode ; array of source code to show
global currThread ; keeps all routines in the current thread in order to avoid circular dependencies
global tmpRoutine
global fullFileRoutines, fileRoutines ; text file with all routine calls, is the output from AS400.
global fullFileCode, fileCode ; text file with source code.
global path
global itemLevels
global levels_LastIndex
global scriptNameNoExt
global TreeViewWidth, treeviewWidthStep
global ListBoxWidth
global MyTreeView, MyListBox, MyEdit_routine, MyEdit_code
global exportedRoutines, exportDescriptions
global MaxLevel, includeDescriptions, MyRadioGroup, ExportedFilename
global winX, winY ; main window position
global winWidth, winHeight ; main window size
global LVX, LVY,LVWidth, LVHeight
global from_line_number, to_line_number
global gui_offset, gui_height, gui_width
global letterColor, fontSize, fontColor, codeEditor
global subGui2_W, subGui2_H
global subGui3_W, subGui3_H
global subGui4_W, subGui4_H
global gCurrentLevel ; holds the fold level or 0 if none.
global targetX, targetY, targetWidth, targetHeight ; main window coordinates
global ExportSelected, nodesToExport, ExportWhatYouSee
initialize()
mainProcess()
return
mainProcess() {
setup()
populateRoutines()
populateCode()
loadTreeview()
saveRoutines(".\data\allRoutines.txt", header, true)
updateStatusBar()
showGui()
}
showGui() {
global
OnMessage(0x232, "Move_window") ; to move children guis with the parent
processLevel(2)
updateStatusbar()
Gui, 1:Show, X%winX% Y%winY% W%winWidth% H%winHeight%, %fileCode%
return
}
;---------------------------------------------------------------------
; show help window
;---------------------------------------------------------------------
showHelp() {
Gui, 2:Destroy
subGui2_W := 420
subGui2_H := 220
WinGetPos, targetX, targetY, targetWidth, targetHeight, A
newX := targetX + (targetWidth - subGui2_W) / 2
newY := targetY + (targetHeight - subGui2_H) / 2
Gui, 2:+AlwaysOnTop -Caption +Owner1
Gui, 2:Add,GroupBox,xm+5 y+20 w%subGui2_W% h%subGui2_H%, Function keys
Gui, 2:Add,Text,xm+10 yp+20 w400,
(
F1 = show help
F2 = export tree
F3/F4 = fold/unfold all
F5/F6 = fold/unfold current node recursively
F7/F8 = fold/unfold current level
shift F1..F12 = fold level 2..13
F9/F10 = search next/previous
F11 = toggle bookmark for export
ctrl right cursor = increase tree width
ctrl left cursor = decrease tree width
)
Gui, 2:Add, button, xm+10 y+20 g2Close,Close
Gui, 2:show, x%newX% y%newY%, Gui 2
HWND_GUI2 := WinExist(A)
return
}
2Escape:
2GuiEscape:
2Close:
Gui, 2:Destroy
return
;---------------------------------------------------------------------
; show export window
;---------------------------------------------------------------------
showExport() {
inputFilename := fileRoutines
outputFormat := "txt"
Gui, 3:Destroy
global subGui3_W, subGui3_H
subGui3_W := 420
subGui3_H := 180
WinGetPos, targetX, targetY, targetWidth, targetHeight, A
newX := targetX + (targetWidth - subGui3_W) / 2
newY := targetY + (targetHeight - subGui3_H) / 2
Gui, 3:+AlwaysOnTop -Caption +Owner1
Gui, 3:Add,GroupBox,xm+5 y+10 w%subGui3_W% h%subGui3_H%, Export
; filename
Gui, 3:Add,Text,xm+20 yp+40, Exported filename
Gui, 3:Add,Edit, vExportedFilename xp+90 yp-5 w300, exported_%inputFilename%
; Gui, 3:Add,Edit, vExportedFilename xp+90 yp-5 w300, %scriptDir%\data\%inputFilename%
; max level
Gui, 3:Add,Text,xm+20 yp+35, Max level to export
Gui, 3:Add,Edit, vMaxLevel xp+100 yp-5 w40 +Number
Gui, 3:Add, UpDown, Range2-999, 999
; include descriptions?
Checked1 := exportDescriptions == "true" ? "Checked" : ""
Gui, 3:Add, Checkbox, vincludeDescriptions g3IncludeDescriptions xm+20 yp+35 %Checked1% , Include routines descriptions
; output format
Gui, 3:Add, Text, xm+20 yp+30, Output format
Gui, 3:Add, Radio, Group g3Check vMyRadioGroup Checked xp+80 yp, txt
Gui, 3:Add, Radio, g3Check xp+50 yp, json
Gui, 3:Add, Radio, g3Check xp+50 yp, xml
; Export, Close buttons
Gui, 3:Add, button, xm+60 ym+190 w50 g3ExportAll, All
Gui, 3:Add, button, xp+50 ym+190 w50 g3ExportSelected vExportSelected, Selected
Gui, 3:Add, button, xp+50 ym+190 w80 g3ExportWhatYouSee vExportWhatYouSee, What you see
Gui, 3:Add, button, xp+130 g3Close, Close
if (nodesToExport.MaxIndex()>0)
GuiControl, 3:Enable, ExportSelected
else
GuiControl, 3:Disable, ExportSelected
; show window
Gui, 3:show, x%newX% y%newY%, Gui 3
HWND_GUI3 := WinExist(A)
return
}
;---------------------------------------------------------------------
; checkbox <include descriptions> handler
;---------------------------------------------------------------------
3IncludeDescriptions:
Gui, 3:Submit, NoHide
if (includeDescriptions = 1) ; checked
exportDescriptions := "true"
else
exportDescriptions := "false"
return
;---------------------------------------------------------------------
; radiogroup <exrpot type> handler
;---------------------------------------------------------------------
3Check:
Gui, 3:Submit, NoHide
if (MyRadioGroup = 1)
outputFormat := "txt"
outputFormat := "txt"
if (MyRadioGroup = 2)
outputFormat := "json"
if (MyRadioGroup = 3)
outputFormat := "xml"
Return
;---------------------------------------------------------------------
; button <All> handler
;---------------------------------------------------------------------
3ExportAll:
Gui, 3:Submit, NoHide
if (MaxLevel < 2 or MaxLevel > 999) {
MsgBox, max level must be between 2 and 999
return
}
if (trim(ExportedFilename) = "") {
MsgBox, filename cannot be empty
return
}
exportedString := exportTreeview()
saveExportedString(exportedString)
goto 3Close
;---------------------------------------------------------------------
; button <Selected> handler
;---------------------------------------------------------------------
3ExportSelected:
Gui, 3:Submit, NoHide
exportedString := exportNodes()
saveExportedString(exportedString)
goto 3Close
;---------------------------------------------------------------------
; button <WhatYouSee> handler
;---------------------------------------------------------------------
3ExportWhatYouSee:
Gui, 3:Submit, NoHide
Gui, 1:Default ; necessary to use the TV_* functions on the gui 1 treeview!
exportedString := exportWhatYouSee()
saveExportedString(exportedString)
goto 3Close
;---------------------------------------------------------------------
; <close> handler
;---------------------------------------------------------------------
3Escape:
3GuiEscape:
3Close:
Gui, 3:Destroy
return
;---------------------------------------------------------------------
; save created export into file and open it.
;---------------------------------------------------------------------
saveExportedString(exportedString) {
if (exportedString <> "") {
filename := ".\data\" . ExportedFilename
if FileExist(filename)
FileDelete, %filename%
FileAppend, %exportedString%, %filename%
openNotepad(filename)
} else
MsgBox, No bookmark to export.
}
;--------------------------------------------
; show window with editable settings
;--------------------------------------------
showSettings() {
static font_size, font_color, tree_step, window_color, control_color, showOnlyRoutine, showOnlyRoutineFlag, MyRadioGroup, checked1, checked2
win_title := "Settings"
IniRead, font_size, showRoutines.ini, font, size
IniRead, font_color, showRoutines.ini, font, color
IniRead, tree_step, showRoutines.ini, position, treeviewWidthStep
IniRead, window_color, showRoutines.ini, backgroundColor, window
IniRead, control_color, showRoutines.ini, backgroundColor, control
IniRead, showOnlyRoutine, showRoutines.ini, general, showOnlyRoutine
IniRead, codeEditor, showRoutines.ini, general, codeEditor
if (codeEditor == "code") {
checked1 := "checked1"
checked2 := "checked0"
} else {
checked1 := "checked0"
checked2 := "checked1"
}
if (WinExist(win_title))
Gui, 4:Destroy
Loop:
;------
; Font
;------
Gui, 4:Add, GroupBox, x+5 y+10 w160 h100 , Font
Gui, 4:Add, Text, xm+20 ym+40 +0x200, Size
Gui, 4:Add, Edit, vfont_size xm+50 ym+35 w40 +Number, %font_size%
Gui, 4:Add, UpDown, Range7-20, %font_size%
Gui, 4:Add, Text, xm+20 ym+70 w60 +0x200, Color
Gui, 4:Add, Edit, vfont_color xm+50 ym+65 w50, %font_color%
Gui, 4:Add, Progress, w25 h20 xs110 ys61 c%font_color%, 100
;-----------------
; background color
;-----------------
Gui, 4:Add, GroupBox, w170 h100 x+50 ys section, Background Color
Gui, 4:Add, Text, w50 xs15 ys36 +0x200, Window
Gui, 4:Add, Edit, vwindow_color w50 xs60 ys31, %window_color%
Gui, 4:Add, Progress, w25 h20 xs120 ys31 c%window_color%, 100
Gui, 4:Add, Text, w50 xs15 ys66 +0x200, Controls
Gui, 4:Add, Edit, vcontrol_color w50 xs60 ys61, %control_color%
Gui, 4:Add, Progress, w25 h20 xs120 ys61 c%control_color%, 100
;-----------------
; other settings
;-----------------
Gui, 4:Add, Text, xm+5 yp+60 +0x200 section, Tree width +/-
Gui, 4:Add, Edit, vtree_step w50 xp+80 yp-5 +Number, %tree_step%
Gui, 4:Add, UpDown, Range10-200, %tree_step%
Gui, 4:Add, Text, xm+5 yp+40, Code editor
Gui, 4:Add, Radio, Group g4check vMyRadioGroup %checked1% xp+80 yp, vscode
Gui, 4:Add, Radio, g4check %checked2% xp+70 yp, notepad++
checked := showOnlyRoutine == "false" ? "" : "Checked"
Gui, 4:Add, Checkbox, vshowOnlyRoutineFlag %checked% xs200 ys, Show only selected routine
;---------------------------------------------
; buttons to save, cancel, load default values
;---------------------------------------------
Gui, 4:Add, Button, x70 y220 w80, Save
Gui, 4:Add, Button, x160 y220 w80 default, Cancel
Gui, 4:Add, Button, x250 y220 w80, Default
4show:
Gui, 4:+AlwaysOnTop -Caption +Owner1
; Gui, 4:+Resize -SysMenu +ToolWindow
showSubGui(400, 250, win_title)
Return
4Check:
gui, 4:submit, nohide
; GuiControlGet, MyRadioGroup
if (MyRadioGroup = 1)
codeEditor := "code"
if (MyRadioGroup = 2)
codeEditor := "notepad++"
Return
4ButtonSave:
Gui, 4:Submit, NoHide
if (font_size < 7 or font_size > 20) {
msgbox, % "Font size must be between 6 and 20"
Goto, 4show
} else
if (tree_step < 10 or tree_step > 200) {
msgbox, % "Step must be between 10 and 200"
Goto, 4show
} else {
Progress, zh0 fs10, % "Settings saved"
; Sleep, 200
Progress, off
IniWrite, %font_size%, showRoutines.ini, font, size
IniWrite, %font_color%, showRoutines.ini, font, color
if (tree_step > 0)
IniWrite, %tree_step%, showRoutines.ini, position, treeviewWidthStep
IniWrite, %window_color%, showRoutines.ini, backgroundColor, window
IniWrite, %control_color%, showRoutines.ini, backgroundColor, control
showOnlyRoutine := showOnlyRoutineFlag ? "true" : "false"
IniWrite, %showOnlyRoutine%, showRoutines.ini, general, showOnlyRoutine
IniWrite, %codeEditor%, showRoutines.ini, general, codeEditor
Goto, 4GuiClose
}
Goto, 4show
; Load the default values (again from ini file).
4ButtonDefault:
{
IniRead, treeviewWidth, showRoutines.ini, default, treeviewWidth
IniRead, font_size, showRoutines.ini, default, fontsize
IniRead, font_color, showRoutines.ini, default, fontcolor
IniRead, tree_step, showRoutines.ini, default, treeviewWidthStep
IniRead, window_color, showRoutines.ini, default, windowcolor
IniRead, control_color, showRoutines.ini, default, controlcolor
IniRead, codeEditor, showRoutines.ini, default, codeEditor
Gui, 4:Destroy
Goto, Loop
}
4GuiEscape:
;Reload
4GuiClose:
4ButtonCancel:
Gui, 4:Destroy
Return
}
;--------------------------------------------
; show window with editable settings
;--------------------------------------------
showSubGui(subGui_W, subGui_H, subGui_Title) {
WinGetPos, targetX, targetY, targetWidth, targetHeight, A
newX := targetX + (targetWidth - subGui_W) / 2
newY := targetY + (targetHeight - subGui_H) / 2
subGui4_W := subGui_W
subGui4_H := subGui_H
Gui, 4:Show, x%newX% y%newY% w%subGui_W% h%subGui_H%, Gui 4 ; %subGui_Title%
}
;---------------------------------------------------------------------
; open exported routines in editor beside main window
;---------------------------------------------------------------------
openNotepad(filename) {
x := targetX + targetWidth - 10
y := targetY
RunWait, notepad++.exe -nosession -ro -x%x% -y%y% "%filename%"
}
;---------------------------------------------------------------------
; move secondary windows
;---------------------------------------------------------------------
Move_window() {
global
IfWinExist, Gui 2
{
WinGetPos, targetX, targetY, targetWidth, targetHeight, A
newX := targetX + (targetWidth - subGui2_W) / 2
newY := targetY + (targetHeight - subGui2_H) / 2
Gui, 2:show, x%newX% y%newY%, Gui 2
}
IfWinExist, Gui 3
{
WinGetPos, targetX, targetY, targetWidth, targetHeight, A
newX := targetX + (targetWidth - subGui3_W) / 2
newY := targetY + (targetHeight - subGui3_H) / 2
Gui, 3:show, x%newX% y%newY%, Gui 3
}
IfWinExist, Gui 4
{
WinGetPos, targetX, targetY, targetWidth, targetHeight, A
newX := targetX + (targetWidth - subGui4_W) / 2
newY := targetY + (targetHeight - subGui4_H) / 2
Gui, 4:show, x%newX% y%newY%, Gui 4
}
}
;--------------------------------------------------
; check arguments, check run system, set filename,
; move/rename files if needed.
; called on first run only!
;--------------------------------------------------
initialize() {
global
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
params_exist = false
user := ""
path := A_ScriptDir . "\data\"
fileRoutines := ""
fileCode := ""
; the global variable scriptNameNoExt is used for accessing the .INI file from multiple places
; so it is defined at the beggining.
SplitPath, A_ScriptFullPath , scriptFileName, scriptDir, scriptExtension, scriptNameNoExt, scriptDrive
if (A_Args[1] <> "" and A_Args[2] <> "" and A_Args[3] <> "" and A_Args[4] <> "")
params_exist = true
user := getSystem()
; set default filenames when run from my home.
if (user ="SYSTEM_HOME") {
; fileSelector(path, "(*.txt)")
fileRoutines := "B9Y36.txt"
fileCode := "B9Y36.cbl"
}
; otherwise get filenames from params.
if (user = "SYSTEM_WORK") {
; use existing files(*NEW/*OLD):
; load the files either from showRoutines.ini or from arguments.
if (trim(A_Args[4]) = "*NEW" or trim(A_Args[4]) = "*OLD") {
IniRead, fileRoutines, %A_ScriptDir%\%scriptNameNoExt%.ini, files, fileRoutines
IniRead, fileCode, %A_ScriptDir%\%scriptNameNoExt%.ini, files, fileCode
; routines calls file
fileRoutines := params_exist ? A_Args[1] : fileRoutines
; routines code file
fileCode := params_exist ? A_Args[2] : fileCode
}
; use existing files(*no):
; move file.txt & file.cbl.txt from ieffect folder to .\data
if (trim(A_Args[4]) = "*NEW") {
pathIeffect := parms_exist ? A_Args[3] : "z:\bussup\txt\"
if (!FileExist(pathIeffect)) {
msgbox, "Folder " . %pathIeffect% . " doesn't exist. Press enter and select file"
fileRoutines := "" ; clear in order next to show file selector!
} else {
Progress, zh0 fs10, % "Trying to move file " . pathIeffect . fileRoutines . " to folder " . path
FileMove, %pathIeffect%%fileRoutines% , %path% , 1
if (ErrorLevel <> 0) {
msgbox, % "Cannot move file " . pathIeffect . fileRoutines . " to folder " . path
}
Progress, Off
; cut .txt from filename.cbl.txt
OLDfileCode := fileCode
FoundPos := InStr(fileCode, ".cbl.txt" , CaseSensitive:=false)
if (foundPos > 0) {
fileCode := SubStr(fileCode, 1, foundPos-1) . ".cbl"
}
Progress, zh0 fs10, % "Trying to move file " . pathIeffect . fileCode . " to folder/file " . path
FileMove, %pathIeffect%%OLDfileCode% , %path%%fileCode% , 1 ; 1=ovewrite
if (ErrorLevel <> 0) {
msgbox, % "Cannot move file " . pathIeffect . OLDfileCode . " to folder " . path
}
Progress, Off
}
}
; use existing files(*select) or ini file has not corresponding entry: open file selector
if (A_Args[4] = "*SELECT" or fileRoutines = "") {
if (!fileSelector(path, "(*.txt)"))
ExitApp
}
}
}
;--------------------------------------------
; set environment, populate data structures
;--------------------------------------------
setup() {
global
allRoutines := []
allCode := []
tmpRoutine := {}
itemLevels := []
nodesToExport := []
levels_LastIndex := 0
fullFileRoutines := path . fileRoutines
fullFileCode := path . fileCode
; read last saved values
IniRead, TreeViewWidth, %A_ScriptDir%\%scriptNameNoExt%.ini, position, treeviewWidth
IniRead, winX, %A_ScriptDir%\%scriptNameNoExt%.ini, position, winX
IniRead, winY, %A_ScriptDir%\%scriptNameNoExt%.ini, position, winY
IniRead, winWidth, %A_ScriptDir%\%scriptNameNoExt%.ini, position, winWidth
IniRead, winHeight, %A_ScriptDir%\%scriptNameNoExt%.ini, position, winHeight
IniRead, valueOfFontsize, %A_ScriptDir%\%scriptNameNoExt%.ini, font, size
IniRead, valueOfFontcolor, %A_ScriptDir%\%scriptNameNoExt%.ini, font, color
IniRead, valueOfwindow_color, %A_ScriptDir%\%scriptNameNoExt%.ini, backgroundColor, window
IniRead, valueOfcontrol_color, %A_ScriptDir%\%scriptNameNoExt%.ini, backgroundColor, control
IniRead, codeEditor, %A_ScriptDir%\%scriptNameNoExt%.ini, general, codeEditor
if (TreeViewWidth = 0)
TreeViewWidth := 600
ListBoxWidth := winWidth - TreeViewWidth - 30 ; 1000 - TreeViewWidth - 30
LVX := TreeViewWidth + 10
search2_x := TreeViewWidth + 10
if (valueOfFontsize >=6 and valueOfFontsize<=20)
fontSize := valueOfFontsize
else
fontSize := 10
VSCODE_LETTERS := "C4C4C4"
VSCODE_EDIT_WIN := "232323"
VSCODE_LEFT_WIN := "2E3132"
VSCODE_HEAD := "3E3E3E"
VSCODE_SELECTED_MENUITEM := "114970"
if (valueOfFontcolor <> "")
fontColor := valueOfFontcolor
else
fontColor := VSCODE_LETTERS
if (valueOfwindow_color <> "")
window_color := valueOfwindow_color
else
window_color := VSCODE_HEAD
if (valueOfcontrol_color <> "")
control_color := valueOfcontrol_color
else
control_color := VSCODE_EDIT_WIN
Gui, 1:Font, c%fontColor% s%fontSize%, Courier New
Gui, 1:Color, %window_color%, %control_color%
Gui, 1:+Resize +Border
Gui, 1:Add, Text, x5 y10 , Search for routine:
Gui, 1:Add, Edit, r1 vMyEdit_routine x+5 y5 w150
Gui, 1:Add, Text, x%search2_x% y10 , Search inside code:
Gui, 1:Add, Edit, r1 vMyEdit_code x+5 y5 w150
Gui, 1:Add, Button, x+1 Hidden Default, OK ; hidden button to catch enter key! x+1 = show on same line with textbox
Gui, 1:Add, TreeView, vMyTreeView w%TreeViewWidth% r15 x5 gMyTreeView AltSubmit
; Gui, Add, TreeView, vMyTreeView r80 w%TreeViewWidth% x5 gMyTreeView AltSubmit ImageList%ImageListID% ; Background%color1% ; x5= 5 pixels left border
Gui, 1:Add, ListBox, r100 vMyListBox w%ListBoxWidth% x+5, click any routine from the tree to show the code|double click any routine to open in default editor
Gui, 1:add, StatusBar, Background c%control_color%
; Gui, add, StatusBar, Background c%window_color%
; define the context menu.
Menu, MyContextMenu, Add, Fold all `tF3, contextMenuHandler
Menu, MyContextMenu, Add, Unfold all `tF4, contextMenuHandler
Menu, MyContextMenu, Add, Fold recursively `tF5, contextMenuHandler
Menu, MyContextMenu, Add, Unfold recursively `tF6, contextMenuHandler
Menu, MyContextMenu, Add, Fold same level `tF7, contextMenuHandler
Menu, MyContextMenu, Add, Unfold same level `tF8, contextMenuHandler
Menu, MyContextMenu, Add, Fold level 2..13 `tshift F1..F12, contextMenuHandler
Menu, MyContextMenu, Disable, Fold level 2..13 `tshift F1..F12
Menu, MyContextMenu, Add,
Menu, MyContextMenu, Add, Toggle bookmark for export `tF11, contextMenuHandler
Menu, MyContextMenu, Add, Search next `tF9, contextMenuHandler
Menu, MyContextMenu, Add, Search previous `tF10, contextMenuHandler
; file submenu
Menu, FileMenu, Add, &Open file, MenuHandler
Menu, FileMenu, Icon, &Open file, shell32.dll, 4
Menu, FileMenu, Add, Save position, MenuHandler
Menu, FileMenu, Disable, Save position
Menu, FileMenu, Add, Export tree as..., MenuHandler
Menu, FileMenu, Icon, Export tree as..., shell32.dll, 259
Menu, FileMenu, Add, &Exit, MenuHandler
Menu, FileMenu, Icon, &Exit, shell32.dll, 123
; edit submenu
Menu, EditMenu, Add, Toggle bookmark for export `tF11, contextMenuHandler
Menu, EditMenu, Add
Menu, EditMenu, Add, Search next `tF9, contextMenuHandler
Menu, EditMenu, Add, Search previous `tF10, contextMenuHandler
; view submenu
Menu, ViewMenu, Add, Fold all `tF3, contextMenuHandler
Menu, ViewMenu, Add, Unfold all `tF4, contextMenuHandler
Menu, ViewMenu, Add, Fold recursively `tF5, contextMenuHandler
Menu, ViewMenu, Add, Unfold recursively `tF6, contextMenuHandler
Menu, ViewMenu, Add, Fold same level `tF7, contextMenuHandler
Menu, ViewMenu, Add, Unfold same level `tF8, contextMenuHandler
; settings submenu
Menu, SettingsMenu, Add, &Settings, MenuHandler
Menu, SettingsMenu, Icon, &Settings, shell32.dll, 317
; help submenu
Menu, HelpMenu, Add, &Help `tF1, MenuHandler
; define the menu bar.
Menu, MyMenuBar, Add, &File, :FileMenu
Menu, MyMenuBar, Add, &Edit, :EditMenu
Menu, MyMenuBar, Add, &View, :ViewMenu
Menu, MyMenuBar, Add, &Settings, :SettingsMenu
Menu, MyMenuBar, Add, &Help, :HelpMenu
Gui, 1:Menu, MyMenuBar
Gui, 1:Add, Button, gExit, Exit This Example
Menu, Tray, Icon, icons\shell32_16806.ico ;shell32.dll, 85
return
}
;---------------------------------------
; define shortcut keys
;---------------------------------------
#IfWinActive ahk_class AutoHotkeyGUI
global searchText
^left:: ;{ <-- decrease treeview
changeTreeviewWidth("-")
return
^right:: ;{ <-- increase treeview
changeTreeviewWidth("+")
return
F1::
showHelp() ;{ <-- help
return
F2::
showExport() ;{ <-- export
return
F3:: ;{ <-- fold all routines
processAll("-Expand")
return
F4:: ;{ <-- unfold all routines
processAll("Expand")
return
F5:: ;{ <-- fold recursively current routine
processChildren(TV_GetSelection(), "-Expand")
return
F6:: ;{ <-- unfold recursively current routine
processChildren(TV_GetSelection(), "Expand")
return
F7:: ;{ <-- fold same level
selected_itemID := TV_GetSelection()
processSameLevel(selected_itemID, "-Expand")
; processSameLevel(TV_GetSelection(), "-Expand")
return
F8:: ;{ <-- unfold same level
processSameLevel(TV_GetSelection(), "Expand")
return
F9:: ;{ <-- find next
GuiControlGet, searchText, ,MyEdit_routine ;get search text from input field
if (searchText <> "")
searchItemInRoutine(searchText, "next")
return
F10:: ;{ <-- find previous
GuiControlGet, searchText, ,MyEdit_routine ;get search text from input field
if (searchText <> "")
searchItemInRoutine(searchText, "previous")
return
F11:: ;{ <-- Toggle bookmark for export
toggleBookmark()
return
+F1::
processLevel(2)
return
+F2::
processLevel(3)
return
+F3::
processLevel(4)
return
+F4::
processLevel(5)
return
+F5::
processLevel(6)
return
+F6::
processLevel(7)
return
+F7::
processLevel(8)
return
+F8::
processLevel(9)
return
+F9::
processLevel(10)
return
+F10::
processLevel(11)
return
+F11::
processLevel(12)
return
+F12::
processLevel(13)
return
#IfWinActive
;-----------------------------------------------------------
; Handle user actions (such as clicking).
;-----------------------------------------------------------
MyTreeView:
{
global currentRoutine
; click an item: load routine code
if (A_GuiEvent = "S") {
TV_GetText(SelectedItemText, A_EventInfo) ; get item text
loadListbox(SelectedItemText) ; load routine code
}
; doubleclick an item: open code in default editor and position to selected routine.
if (A_GuiEvent = "DoubleClick") {
statements := []
routineName := ""
sourceCode := ""
IniRead, showOnlyRoutine, showRoutines.ini, general, showOnlyRoutine
TV_GetText(routineName, TV_GetSelection()) ; get item text
statements := findRoutineFirstStatement(routineName)
statement := statements[1]
WinGetPos, X_main, Y_main, Width_main, Height_main, A
actWin := WinExist("A")
GetClientSize(actWin, Width_main, Height_main)
x := X_main + Width_main
y := Y_main
if (showOnlyRoutine == "false")
if (codeEditor == "notepad++")
RunWait, notepad++.exe -lcobol -nosession -ro -n%statement% -x%x% -y%y% "%fullFileCode%"
else
RunWait, "C:\Program Files\Microsoft VS Code\Code.exe" --new-window --goto "%fullFileCode%:%statement%"
else {
filename := path . "tempfile" . ".cbl"
FileDelete, %filename%
count := statements[2] - statements[1]
line_number := statements[1]
while (line_number <= statements[2]) {
sourceCode .= allcode[line_number] . (line_number < statements[2] ? "`n" : "")
line_number ++
}
FileAppend, %sourceCode%, %filename%
; msgbox, %filename%
if (codeEditor == "notepad++")
RunWait, notepad++.exe -lcobol -nosession -ro -x%x% -y%y% "%filename%"
else
RunWait, "C:\Program Files\Microsoft VS Code\Code.exe" --new-window "%filename%"
}
; Sleep, 300 ; wait to open
; position besides main window
; if (codeEditor == "notepad++")
; WinMove, ahk_class notepad++, , X_main + Width_main , Y_main
; else
; WinMove, ahk_exe Code.exe, , X_main + Width_main , Y_main
}
; spacebar an item: load the routine code.
if (A_GuiEvent = "K" and A_EventInfo = 32) {
; msgbox, % "[" A_EventInfo "]" ; A_EventInfo contains the ascii character as number
}
return
}
;-----------------------------------------------------------
; set status bar text
;-----------------------------------------------------------
updateStatusBar(currentRoutine := "MAIN") {
; first find the routine names from the bookmarks
index1 := findBookmark(nodesToExport[1])
routine1 := itemLevels[index1, 3]
index2 := findBookmark(nodesToExport[2])
routine2 := itemLevels[index2, 3]
bookmarks := routine1 <> "" ? ("[" . routine1 . "]" . (routine2 <> "" ? "---" . "[" . routine2 . "]" : "")) : (routine2 <> ? "[" . routine2 . "]" : "")
SB_SetText("Routines:" . allRoutines.MaxIndex() . " | Current level: " . gCurrentLevel . " | Bookmarks:" . bookmarks)
; SB_SetText("Routines:" . allRoutines.MaxIndex() . " | Statements:" . allCode.MaxIndex()
; . " | File:" . fileCode . " | Current routine:" . currentRoutine)
}
;---------------------------------------------------------------------
; Expand/shrink the TreeView in response to user's resizing of window.
;---------------------------------------------------------------------
GuiSize:
{
if (A_EventInfo = 1) ; The window has been minimized. No action needed.
return
gui_height := A_GuiHeight
gui_width := A_GuiWidth
gui_offset := 60
; Otherwise, the window has been resized or maximized. Resize the controls to match.
GuiControl, Move, MyTreeView, % "H" . (A_GuiHeight - gui_offset) . " W" . TreeViewWidth ; -30 for StatusBar and margins.
GuiControl, Move, MyListBox, % "X" . LVX . " H" . (A_GuiHeight - gui_offset ) . " W" . (A_GuiWidth - TreeViewWidth - 10) ; width = total - treeview - (3 X 5) margins.
; GuiControl, Move, MyListBox, % "X" . LVX . " H" . (A_GuiHeight - 30) . " W" . (A_GuiWidth - TreeViewWidth - 15) ; width = total - treeview - (3 X 5) margins.
return
}
;----------------------------------------------------------------
; on app close save to INI file last position & size.
;----------------------------------------------------------------
GuiClose: ; Exit the script when the user closes the TreeView's GUI window.
exitApplication()
return
;-----------------------------------------------------------
; Handle enter key (such as clicking).
;-----------------------------------------------------------
ButtonOK:
{
GuiControlGet, searchText, ,MyEdit_routine ;get search text from input field
if (searchText <> "")
searchItemInRoutine(searchText, "next")
else {
GuiControlGet, searchText, ,MyEdit_code ;get search text from input field
if (searchText <> "")
item = searchItemInCode(searchText, "next")
GuiControl, Choose, MyListBox, item
}
return
}
;----------------------------------------------------------------
; Launched in response to a right-click or press of the Apps key.
;----------------------------------------------------------------
GuiContextMenu:
{
if (A_GuiControl <> "MyTreeView") ; This check is optional. It displays the menu only for clicks inside the TreeView.
return
; Show the menu at the provided coordinates, A_GuiX and A_GuiY. These should be used
; because they provide correct coordinates even if the user pressed the Apps key:
Menu, MyContextMenu, Show, %A_GuiX%, %A_GuiY%
return
}
;-----------------------------------------------------------
; Handle menu bar actions
;-----------------------------------------------------------
MenuHandler:
if (A_ThisMenuItem = "&Open file") {
if (!fileSelector(path, "(*.txt)"))
return
Gui, 1:Destroy
mainProcess()
return
}
if (A_ThisMenuItem = "Export tree as...") {
showExport()
return
}
if (A_ThisMenuItem = "&Settings") {
showSettings()
return
}
if (A_ThisMenuItem = "&Help `tF1") {
showHelp()
return
}
if (A_ThisMenuItem = "&Exit") {
exitApplication()
}
return
Exit:
ExitApp
;-----------------------------------------------------------
; Handle context menu actions
;-----------------------------------------------------------
contextMenuHandler:
if (A_ThisMenuItem = "Show routine code `tLeft click") {
; doesn't work!!!
; TV_GetText(SelectedItemText, TV_GetSelection()) ; get item text
; msgbox, % SelectedItemText . "----" . TV_GetSelection()
; loadListbox(SelectedItemText) ; load routine code
}
if (A_ThisMenuItem = "Fold all (F3)")
processAll("-Expand")
if (A_ThisMenuItem = "Unfold all (F4)")
processAll("Expand")
if (A_ThisMenuItem = "Fold recursively (F5)")
processChildren(TV_GetSelection(), "-Expand")
if (A_ThisMenuItem = "Unfold recursively (F6)")
processChildren(TV_GetSelection(), "Expand")