-
Notifications
You must be signed in to change notification settings - Fork 0
/
TM1 tools in AHK.ahk
2549 lines (2231 loc) · 79.2 KB
/
TM1 tools in AHK.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
; ####################################################
; #
; # Author: Wim Gielis
; # Contact: [email protected]
; # URL: https://github.com/wimgielis?tab=repositories
; # Website: https://www.wimgielis.com
; # Date: January 30, 2021
; # Based on the TI helper AutoHotKey script: https://code.cubewise.com/ti-helper
; #
; ####################################################
; 1. in Turbo Integrator editor, Rules editor, Notepad++
; a) F10: create an additional menu next to the mouse pointer
; b) Ctrl-F10: reload the different menu's (used with F10)
; 2. in Turbo Integrator editor, Rules editor
; a) Ctrl-k: comment code
; b) Ctrl-Shift-k: uncomment code
; c) Ctrl-l: delete the currently selected line (multiple lines default to the first line)
; d) Ctrl-d: duplicate the currently selected line (multiple lines default to the first line)
#Persistent
#SingleInstance Force ; Only opens a single instance of the script so reopening won't cause multiple instances
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases
SendMode Input ; Recommended for new scripts due to its superior speed and reliability
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory
CoordMode, Mouse, Client
;~~~~~~~~~~~~~~~~~~~
; GLOBAL OBJECTS
;~~~~~~~~~~~~~~~~~~~
ToolsArray := Object()
;~~~~~~~~~~~~~~~~~~~
; INITIALISATION
;~~~~~~~~~~~~~~~~~~~
cPath_TM1_model_Main := "D:\path to my data directory with trailing backslash\"
GoSub, LoadMenu
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Additional shortcuts in TI and rules, mimicking Notepad++ shortcuts:
; - Ctrl-k: comment code
; - Ctrl-Shift-k: uncomment code
; - Ctrl-l: delete the currently selected line (multiple lines default to the first line)
; - Ctrl-d: duplicate the currently selected line (multiple lines default to the first line)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commenting:
#if WinActive("Turbo Integrator:") or WinActive("Rules Editor:")
^k:: ; <-- (TI, rules) indent code
{
NewClip =
clipboard =
Send ^c
ClipWait, 1
if ErrorLevel <> 0
return
AutoTrim, off
for each, Line in StrSplit(Clipboard, "`n", "`r")
{
if ( Line = "" )
NewClip .= Line "`r`n"
else
NewClip .= "# " Line "`r`n"
}
StringTrimRight, NewClip, NewClip, 2
clipboard = %NewClip%
Send ^v
Return
}
uncommenting:
^+k:: ; <-- (TI, rules) unindent code
{
NewClip =
clipboard =
Send ^c
ClipWait, 1
if ErrorLevel <> 0
return
WaitingForFirstCharOfLine = y
AutoTrim, off
for each, Line in StrSplit(Clipboard, "`n", "`r")
{
StringTrimLeft, Line, Line, 2
NewClip .= Line "`r`n"
}
StringTrimRight, NewClip, NewClip, 2
clipboard = %NewClip%
Send ^v
Return
}
^l:: ; <-- (TI, rules) delete the current line
{
SendInput, {Home}
SendInput, {Shift down}{End}{Shift up}
SendInput, {Delete}
SendInput, {Backspace}
return
}
^d:: ; <-- (TI, rules) duplicate the current line
{
SendInput, {Home}
SendInput, {Shift down}{End}{Shift up}
SendInput, ^c
SendInput, {Home}
SendInput, {Enter}
SendInput, {Up}
SendInput, ^v
SendInput, {Right}
return
}
;~~~~~~~~~~~~~~~~~~~
; HOTKEYS (Note: there are more hotkeys above)
;~~~~~~~~~~~~~~~~~~~
#IfWinActive ahk_class ExploreWClass
^F10:: ; <-- (Notepad++) reload
Reload
F10:: ;{ <-- ~ (Notepad++) Main menu ~
Menu,menu,show
Return
#IfWinActive ahk_class CabinetWClass
^F10:: ; <-- (Notepad++) reload
Reload
F10:: ;{ <-- ~ (Notepad++) Main menu ~
Menu,menu,show
Return
#IfWinActive, ahk_class Notepad++
^F10:: ; <-- (Notepad++) reload
Reload
F10:: ;{ <-- ~ (Notepad++) Main menu ~
Menu,menu,show
Return
#IfWinActive, ahk_class AfxFrameOrView100u
^F10:: ; <-- (TI) reload
Reload
; to resize the columns of the VARIABLES AND PARAMETERS window
F10:: ;{ <-- ~ (TI) Main menu ~
{
WinGet, hWnd, ID, A
SendMessage, 0x130B,,, SysTabControl327, % "ahk_id " hWnd ;TCM_GETCURSEL := 0x130B
vSelection := ErrorLevel+1
if (vSelection = 2)
{
; resize the columns
WinGetTitle, Window_Title, A
MouseClickDrag, L, 1335, 75, 1140, 75
MouseClickDrag, L, 1015, 75, 900, 75
MouseClickDrag, L, 700, 75, 470, 75
MouseClickDrag, L, 380, 75, 250, 75
return
}
else if (vSelection = 4)
{
; the Advanced tab
WinGet, hWnd, ID, A
SendMessage, 0x130B,,, SysTabControl321, % "ahk_id " hWnd ;TCM_GETCURSEL := 0x130B
vSelection := ErrorLevel+1
if (vSelection = 1)
{
; resize the columns
WinGetTitle, Window_Title, A
MouseClickDrag, L, 437, 100, 850, 100
MouseClickDrag, L, 337, 100, 380, 100
MouseClickDrag, L, 237, 100, 215, 100
MouseClickDrag, L, 137, 100, 210, 100
return
}
else
{
; Prolog - Metadata - Data - Epilog
Menu,menu,show
return
}
}
}
Return
#IfWinActive, ahk_class #32770
; to increase the size of the PARAMETERS window when you EXECUTE a process
F10:: ;{ <-- ~ (TI) run process, format the screen ~
{
WinGetTitle, Window_Title, A
WinMaximize
; resize the first column
MouseClickDrag, L, 160, 40, 800, 40
; a double click in the first parameter value
Click, 810, 55, 2
return
}
Return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; LoadMenu function
; This function loads menu items
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LoadMenu:
; tools
toolName:= "Code to Notepad"
ToolsArray.Insert([toolName])
Menu,ToolsSubmenu,add,%toolName%,menuHandler
toolName:= "Generate AsciiOutput"
ToolsArray.Insert([toolName])
Menu,ToolsSubmenu,add,%toolName%,menuHandler
toolName:= "Update PRO line numbers"
ToolsArray.Insert([toolName])
Menu,ToolsSubmenu,add,%toolName%,menuHandler
; a separator
toolName:=
Menu,ToolsSubmenu,add,%toolName%,menuHandler
toolName:= "Commenting"
ToolsArray.Insert([toolName])
Menu,ToolsSubmenu,add,%toolName%,menuHandler
toolName:= "Uncommenting"
ToolsArray.Insert([toolName])
Menu,ToolsSubmenu,add,%toolName%,menuHandler
; a separator
toolName:=
Menu,ToolsSubmenu,add,%toolName%,menuHandler
toolName:= "Convert to Expand"
ToolsArray.Insert([toolName])
Menu,ToolsSubmenu,add,%toolName%,menuHandler
toolName:= "Convert to | delimited"
ToolsArray.Insert([toolName])
Menu,ToolsSubmenu,add,%toolName%,menuHandler
; a separator
toolName:=
Menu,ToolsSubmenu,add,%toolName%,menuHandler
toolName:= "A new TM1 model (in File Explorer)"
ToolsArray.Insert([toolName])
Menu,ToolsSubmenu,add,%toolName%,menuHandler
toolName:= "Open the PRO file"
ToolsArray.Insert([toolName])
Menu,ToolsSubmenu,add,%toolName%,menuHandler
toolName:= "File backup with timestamp"
ToolsArray.Insert([toolName])
Menu,ToolsSubmenu,add,%toolName%,menuHandler
menuName:="Tools"
menuHandler:="ToolsSubmenu"
Menu,menu,add,%menuName%,:%menuHandler%
Return
menuHandler:
menuItem = %A_ThisMenuItem%
nFound:=0
if(menuItem = "Code to Notepad")
{
WinGetTitle, Window_Title, A
if InStr( Window_Title, "Turbo Integrator:", false ) = 0
{
msgbox Please activate Turbo Integrator
return
}
vText = % Get_TI_Code_Tab()
; get or create a Notepad++ session
IfWinExist ahk_class Notepad++
{
WinActivate
WinWaitActive
Sleep 300
WinMenuSelectItem, , , File, New ; open a new tab
}
Else
{
vValue_Setting_NPPlusPlus_Location := "C:\Program Files\Notepad++\notepad++.exe"
IfExist, %vValue_Setting_NPPlusPlus_Location%
{
Run, %vValue_Setting_NPPlusPlus_Location%
WinActivate ahk_class Notepad++
WinWaitActive ahk_class Notepad++
Sleep 300
WinMenuSelectItem, , , File, New ; open a new tab
}
Else
{
try
{
Run notepad++
WinActivate ahk_class Notepad++
WinWaitActive ahk_class Notepad++
Sleep 300
WinMenuSelectItem, , , File, New ; open a new tab
}
catch
{
Run notepad
}
}
}
Clipboard := vText
Send, ^v
; tab to space
WinMenuSelectItem, , , 2&, 16&, 6&
; remove trailing spaces
WinMenuSelectItem, , , 2&, 16&, 1&
; apply the TM1 language
WinMenuSelectItem, , , Language, TM1
Send ^{home}
if ErrorLevel ; i.e. it's not blank or zero.
MsgBox, ERROR
return
}
else if(menuItem = "Commenting")
{
Send {Esc 2}
Gosub commenting
return
}
else if(menuItem = "Uncommenting")
{
Send {Esc 2}
Gosub uncommenting
return
}
else if(menuItem = "Generate AsciiOutput")
{
; ####################################################
; # Purpose of the script:
; # - open up any (valid) PRO file in Notepad++ or TI process editor, or just a snippet of TI code without a regular PRO file
; # - launch the menu and the gui
; # - list all variables of a TI process
; # - allow to generate the TI code for selected variables
; # - it will be pasted at the cursor
; # - Order of the selected (clicked) variables could be respected and AsciiOutput in that order
; # - several other options are built-in
; #
; # To be added later:
; # - Order of the selected variables could be respected and AsciiOutput in that order
; # - A tab control on the gui containing a 'live' preview of what the code would create (with manual adjustment)
; # - Use the Windows registry to save to and load from for choices in the gui (not needed to redo everything)
; # - No REST API used and needed for now, I parse a text file and that's it
; # -
; ####################################################
inifile = GAO_settings.ini
vProcess := Get_Process_FullFileName( "", "___Current process" )
if vProcess =
vProcess := "No PRO file"
Gui, Destroy
Gui, Add, Text, x20 vFullFilename Disabled, %vProcess%
Gui, Add, Button, gAO_SelectALL x20, Select all
Gui, Add, Button, gAO_ReloadVars x+30, Reload variables
Gui, Add, Edit, vEdit_Select_Matching_Variables x+20 w80 r1 gSelect_Matching_Variables
Gui, Add, Button, gAO_RemoveDups x+55, Remove duplicates
Gui, Add, Button, gAO_ReIndex x+45, Re-index order
Gui, Add, ListView, x20 w400 h505 gMyListView AltSubmit, Variable Type|Variable Name|Data Type|Order
Gui, Add, ListBox, 8 x+10 w150 r9 Choose1 vShow_Which_Variables gShow_Which_Variables, All|Parameters|Data source variables|Data source new variables|Custom variables| in the Prolog tab| in the Metadata tab| in the Data tab| in the Epilog tab
Gui, Add, ListBox, AltSubmit ReadOnly y+30 w150 r3 vSwitch_Text_Number gSwitch_Text_Number, Text <--> Number|--> Text|--> Number
Gui, Add, Button, gAO_OK y+45 w150, Generate output
Gui, Add, Button, y+120 w150 vDefaultSettings gDefaultSettings, Use default settings
Gui, Add, Button, y+15 w150 vLoadSettings gLoadSettings, Load settings from file
Gui, Add, Button, y+8 w150 vSaveSettings gSaveSettings, Save settings to file
Gui, Add, Button, y+8 w150 vDeleteSettings gDeleteSettings, Delete settings file
Gui, Add, ListBox, x20 y+25 w100 Choose1 vMyListBox_OutputFunction, AsciiOutput|TextOutput|LogOutput
Gui, Add, ListBox, AltSubmit x+20 w100 Choose1 vMyListBox_OutputFolder, DataDir|LoggingDir|DebugDir
Gui, Add, Edit, vEdi1 x+20 w160 r1, test.txt
Gui, Add, CheckBox, y+10 Checked vVariable_Filename, Variable
Gui, Add, CheckBox, x20 y+25 Checked vOutput_in_Selected_Order gOutput_in_Selected_Order, Output variables in selected order
Gui, Add, CheckBox, x20 vAdd_Output_Settings, Add output settings
Gui, Add, CheckBox, x20 vNames_of_variables, Insert names of variables
Gui, Add, CheckBox, x20 vHeader, Add code for a header
Gui, Add, CheckBox, x20 vNumbers_NumberFormat, Numbers get a numberformat
Gui, Add, ListBox, AltSubmit Choose1 x20 y+25 w150 r3 vLine_Splitter, No split|Multiline output|Split long lines
Gui, Add, Edit, x250 y650 w50 Center
Gui, Add, UpDown, Left vUpDown_IF Range0-10, 0
Gui, Add, Text, x+5 yp+3, Add this many filters
Gui, Add, Edit, x250 y685 w50 Center
Gui, Add, UpDown, Left vUpDown_Repeat gUpDown_Repeat Range1-20, 1
Gui, Add, Text, x+5 yp+3, Repeat output this many times
Gui, Add, CheckBox, yp+20 vAdd_Area, Include area designation
Gosub Read_in_AO_vars
LV_ModifyCol() ; Auto-size each column to fit its contents
LV_ModifyCol(4, "45 Integer Center")
vCaption := "Output variables to a text file (c) Wim Gielis - " . A_Year
Gui, Show, w600 h835, %vCaption%
return
DefaultSettings:
GuiControl, Choose, MyListBox_OutputFunction, 1
GuiControl, Choose, MyListBox_OutputFolder, 1
GuiControl, , Edi1, test.txt
GuiControl, , Variable_Filename, 1
GuiControl, , Output_in_Selected_Order, 1
GuiControl, , Add_Output_Settings, 0
GuiControl, , Names_of_variables, 0
GuiControl, , Header, 0
GuiControl, , Numbers_NumberFormat, 0
GuiControl, Choose, Line_Splitter, 1
GuiControl, , UpDown_IF, 0
GuiControl, , UpDown_Repeat, 1
GuiControl, , Add_Area, 0
return
LoadSettings:
IfNotExist, %inifile%
{
Msgbox No settings file (%A_ScriptDir%\%inifile%) could be found.
Return
}
IniRead, MyListBox_OutputFunction, %inifile%, Generate_AsciiOutput, MyListBox_OutputFunction
GuiControl, Choose, MyListBox_OutputFunction, %MyListBox_OutputFunction%
IniRead, MyListBox_OutputFolder , %inifile%, Generate_AsciiOutput, MyListBox_OutputFolder
GuiControl, Choose, MyListBox_OutputFolder, %MyListBox_OutputFolder%
IniRead, Edi1 , %inifile%, Generate_AsciiOutput, Edi1
GuiControl, , Edi1, %Edi1%
IniRead, Variable_Filename , %inifile%, Generate_AsciiOutput, Variable_Filename
GuiControl,,Variable_Filename, %Variable_Filename%
IniRead, Output_in_Selected_Order, %inifile%, Generate_AsciiOutput, Output_in_Selected_Order
GuiControl,,Output_in_Selected_Order, %Output_in_Selected_Order%
IniRead, Add_Output_Settings , %inifile%, Generate_AsciiOutput, Add_Output_Settings
GuiControl,,Add_Output_Settings, %Add_Output_Settings%
IniRead, Names_of_variables , %inifile%, Generate_AsciiOutput, Names_of_variables
GuiControl,,Names_of_variables, %Names_of_variables%
IniRead, Header , %inifile%, Generate_AsciiOutput, Header
GuiControl,,Header, %Header%
IniRead, Numbers_NumberFormat , %inifile%, Generate_AsciiOutput, Numbers_NumberFormat
GuiControl,,Numbers_NumberFormat, %Numbers_NumberFormat%
IniRead, Line_Splitter , %inifile%, Generate_AsciiOutput, Line_Splitter
GuiControl, Choose, Line_Splitter, %Line_Splitter%
IniRead, UpDown_IF , %inifile%, Generate_AsciiOutput, UpDown_IF
GuiControl, , UpDown_IF, %UpDown_IF%
IniRead, UpDown_Repeat , %inifile%, Generate_AsciiOutput, UpDown_Repeat
GuiControl, , UpDown_Repeat, %UpDown_Repeat%
IniRead, Add_Area , %inifile%, Generate_AsciiOutput, Add_Area
GuiControl,,Add_Area, %Add_Area%
return
SaveSettings:
Gui, Submit, noHide
IniWrite, %MyListBox_OutputFunction%, %inifile%, Generate_AsciiOutput, MyListBox_OutputFunction
IniWrite, %MyListBox_OutputFolder% , %inifile%, Generate_AsciiOutput, MyListBox_OutputFolder
IniWrite, %Edi1% , %inifile%, Generate_AsciiOutput, Edi1
IniWrite, %Variable_Filename% , %inifile%, Generate_AsciiOutput, Variable_Filename
IniWrite, %Output_in_Selected_Order%, %inifile%, Generate_AsciiOutput, Output_in_Selected_Order
IniWrite, %Add_Output_Settings% , %inifile%, Generate_AsciiOutput, Add_Output_Settings
IniWrite, %Names_of_variables% , %inifile%, Generate_AsciiOutput, Names_of_variables
IniWrite, %Header% , %inifile%, Generate_AsciiOutput, Header
IniWrite, %Numbers_NumberFormat% , %inifile%, Generate_AsciiOutput, Numbers_NumberFormat
IniWrite, %Line_Splitter% , %inifile%, Generate_AsciiOutput, Line_Splitter
IniWrite, %UpDown_IF% , %inifile%, Generate_AsciiOutput, UpDown_IF
IniWrite, %UpDown_Repeat% , %inifile%, Generate_AsciiOutput, UpDown_Repeat
IniWrite, %Add_Area% , %inifile%, Generate_AsciiOutput, Add_Area
return
DeleteSettings:
IfNotExist, %inifile%
{
Msgbox No settings file (%A_ScriptDir%\%inifile%) could be found.
Return
}
FileDelete, %inifile%
return
UpDown_Repeat:
gui, Submit, noHide
If UpDown_Repeat > 1
GuiControl,,Add_Area, 1
else
GuiControl,,Add_Area, 0
return
Select_Matching_Variables:
GuiControlGet, Edit_Select_Matching_Variables
If( Edit_Select_Matching_Variables != "" )
{
LV_Modify(0, "-Select")
Loop % LV_GetCount()
{
LV_GetText(Text, A_Index, 2)
if ( Instr( Text, Edit_Select_Matching_Variables ) > 0 )
LV_Modify(A_Index, "+Select")
}
}
return
MyListView:
gui, Submit, noHide
if ( A_GuiEvent = "Normal" )
{
if ( Output_in_Selected_Order = True )
{
; find the highest order number and increment
Selected_Row = %A_EventInfo%
dMax := 0
Loop % LV_GetCount()
{
LV_GetText(Text, A_Index, 4)
Number := ("0" . Text), Number += 0
if ( Number > dMax )
dMax := Number
}
LV_GetText(Text, Selected_Row, 4)
Number := ("0" . Text), Number += 0
If ( Number < dMax Or Number = 0 )
{
n := dMax + 1
LV_Modify(Selected_Row, "Col4", n)
}
; how many have a number ?
If ( Number > 0 )
{
countof := 0
Loop % LV_GetCount()
{
LV_GetText(Text, A_Index, 4)
If ( Text != "" )
countof += 1
}
If ( n > countof )
{
Loop % LV_GetCount()
{
LV_GetText(Text, A_Index, 4)
If ( Text != "" )
{
Number2 := ("0" . Text), Number2 += 0
If ( Number2 > Number )
LV_Modify(A_Index, "Col4", Number2 - 1)
}
}
}
}
}
}
if ( A_GuiEvent = "RightClick" )
{
; clear the order for the selected row
LV_Modify(A_EventInfo, "Col4", "")
}
return
Show_Which_Variables:
gosub Read_in_AO_vars
return
Read_in_AO_vars:
Gui, Submit, NoHide
LV_Delete()
guiControlGet, sFullFilename,, FullFilename
if ( sFullFilename = "No PRO file" )
{
if ( sSaved_Title != "" )
Title := sSaved_Title
else
WinGetTitle, Title, A
WinGetText, text, %Title%
FileContents := text
if ( sSaved_Title = "" )
sSaved_Title := Title
}
else
FileRead, FileContents, %sFullFilename%
; make sure we have CRLF as the end of line character
If ( Instr( FileContents, "`r`n" ) = 0 )
If ( Instr( FileContents, "`n" ) > 0 )
FileContents := StrReplace(FileContents, "`n", "`r`n")
else if ( Instr( FileContents, "`r" ) > 0 )
FileContents := StrReplace(FileContents, "`r", "`r`n")
; 1. parameters
if InStr( Show_Which_Variables, "All", false ) = 1
Or InStr( Show_Which_Variables, "Parameters", false ) > 0
{
PRO_Text := StringBetween( FileContents, "560,", "590," )
Nr_of_vars := ( CountLines( PRO_Text ) - 3 ) / 2
If ( Nr_of_vars > 0 )
{
StringSplit, ParamArray, PRO_Text, `n
Loop, %ParamArray0%
{
if A_index = 1
Continue
Index_type := A_Index + ( Floor(Nr_of_vars) * 1 ) + 1
my_param_name := ParamArray%A_Index%
; remove the linebreak
StringTrimRight, my_param_name, my_param_name, 1
my_param_type := ParamArray%Index_type%
; remove the linebreak
StringTrimRight, my_param_type, my_param_type, 1
If ( my_param_type = 2 )
LV_Add("", "Parameter", my_param_name, "Text")
Else
LV_Add("", "Parameter", my_param_name, "Number")
if A_index > % Nr_of_vars
Break
}
}
}
; 2. data source variables
if InStr( Show_Which_Variables, "All", false ) = 1
Or InStr( Show_Which_Variables, "Data source variables", false ) > 0
{
PRO_Text := StringBetween( FileContents, "577,", "579," )
Nr_of_vars := ( CountLines( PRO_Text ) - 3 ) / 2
If ( Substr( StringBetween( FileContents, "562,", "586," ), 2, 4 ) = "VIEW" )
Nr_of_vars_without_builtin := Nr_of_vars - 3
Else
Nr_of_vars_without_builtin := Nr_of_vars
If ( Nr_of_vars > 0 )
{
StringSplit, ParamArray, PRO_Text, `n
Loop, %ParamArray0%
{
if A_index = 1
Continue
Index_type := A_Index + ( Floor(Nr_of_vars) * 1 ) + 1
my_param_name := ParamArray%A_Index%
; remove the linebreak
StringTrimRight, my_param_name, my_param_name, 1
my_param_type := ParamArray%Index_type%
; remove the linebreak
StringTrimRight, my_param_type, my_param_type, 1
If (( my_param_name = "NValue" ) Or ( my_param_name = "SValue" ) Or ( my_param_name = "value_is_STRING" ))
{
If ( my_param_type = 2 )
LV_Add("", "View var", my_param_name, "Text")
Else
LV_Add("", "View var", my_param_name, "Number")
}
Else
{
If ( my_param_type = 2 )
LV_Add("", "Data source var", my_param_name, "Text")
Else
LV_Add("", "Data source var", my_param_name, "Number")
}
if A_index > % Nr_of_vars
Break
}
}
}
; 3. data source variables: newly created by the developer
if InStr( Show_Which_Variables, "All", false ) = 1
Or InStr( Show_Which_Variables, "Data source new variables", false ) > 0
{
PRO_Text := StringBetween( FileContents, "582,", "603," )
Nr_of_vars := ( CountLines( PRO_Text ) - 2 ) / 1
If ( Nr_of_vars > Nr_of_vars_without_builtin )
{
VarArray := StrSplit(PRO_Text, "`r`n")
Loop % VarArray.MaxIndex()
{
if A_index - 1 <= Nr_of_vars_without_builtin
Continue
my_var_line := VarArray[A_Index]
if ( InStr( my_var_line, "VarName", false ) = 1 )
{
VarArray_FF := StrSplit(my_var_line, Chr(12))
my_var_name_full := VarArray_FF[1]
VarArray_EqualSign := StrSplit(my_var_name_full, "=")
my_var_name := VarArray_EqualSign[2]
my_var_type_full := VarArray_FF[2]
VarArray_EqualSign := StrSplit(my_var_type_full, "=")
my_var_type := VarArray_EqualSign[2]
my_var_coltype_full := VarArray_FF[3]
VarArray_EqualSign := StrSplit(my_var_coltype_full, "=")
my_var_coltype := VarArray_EqualSign[2]
If ( my_var_coltype <> 1165 )
{
If ( my_var_type = 32 )
LV_Add("", "Data source new var", my_var_name, "Text")
Else
LV_Add("", "Data source new var", my_var_name, "Number")
}
}
}
}
}
; 4. custom variables created by the developer anywhere in the process code
if InStr( Show_Which_Variables, "All", false ) = 1
Or InStr( Show_Which_Variables, "Custom variables", false ) > 0
Or InStr( Show_Which_Variables, " in the Prolog tab", false ) > 0
Or InStr( Show_Which_Variables, " in the Metadata tab", false ) > 0
Or InStr( Show_Which_Variables, " in the Data tab", false ) > 0
Or InStr( Show_Which_Variables, " in the Epilog tab", false ) > 0
{
Text_of_vars :=
if ( sFullFilename = "No PRO file" )
{
Text_of_vars_1234 := FileContents
Text_of_vars_1 :=
Text_of_vars_2 :=
Text_of_vars_3 :=
Text_of_vars_4 :=
}
else
{
Text_of_vars_1234 := StringBetween( FileContents, "572,", "576," )
Text_of_vars_1 := StringBetween( FileContents, "572,", "573," )
Text_of_vars_2 := StringBetween( FileContents, "573,", "574," )
Text_of_vars_3 := StringBetween( FileContents, "574,", "575," )
Text_of_vars_4 := StringBetween( FileContents, "575,", "576," )
}
if InStr( Show_Which_Variables, "All", false ) = 1
Or InStr( Show_Which_Variables, "Custom variables", false ) > 0
Text_of_vars := Text_of_vars_1234
if InStr( Show_Which_Variables, " in the Prolog tab", false ) > 0
Text_of_vars .= Text_of_vars_1
if InStr( Show_Which_Variables, " in the Metadata tab", false ) > 0
Text_of_vars .= Text_of_vars_2
if InStr( Show_Which_Variables, " in the Data tab", false ) > 0
Text_of_vars .= Text_of_vars_3
if InStr( Show_Which_Variables, " in the Epilog tab", false ) > 0
Text_of_vars .= Text_of_vars_4
; search for variables
allMatches := ""
out := ""
Pos = 1
While Pos := RegExMatch(Text_of_vars, "(?<=\v)\s*?\w+?\s*?=", m, Pos+StrLen(m))
{
m := StrReplace(m, "=", "")
m := StrReplace(m, A_Space, "")
m := StrReplace(m, A_Tab, "")
m := StrReplace(m, "`r`n", "")
allMatches .= (!allMatches ? "" : "`n") m
}
Loop, parse, allMatches, `n
If not RegExMatch(out, "\b" A_LoopField "\b") {
out .= out ? "`n" : ""
out .= A_LoopField
}
; to ease searching for the variable name in the code, then retrieve the following word/characters
Text_of_vars_no_whitespace := StrReplace(Text_of_vars, A_Space)
Text_of_vars_no_whitespace := StrReplace(Text_of_vars_no_whitespace, A_Tab)
e := "`r`n"
Lookup_VarType := ["2|'", "1|CellGetN", "2|CellGetS", "1|AttrN", "2|AttrS", "1|StringToNumber", "2|NumberToString", "2|SubsetGetElementName", "1|SubsetGetSize", "2|Trim", "2|Subst", "1|Scan", "1|ElparN", "2|Elpar", "1|ElIspar", "1|ElcompN", "2|ElComp", "1|ElIsComp", "2|Long", "1|Dimix", "1|Dimsiz", "2|Dimnm", "2|Dtype", "2|Expand", "2|Tabdim", "2|Delet", "2|Insrt", "2|Upper", "2|Lower", "2|Char", "2|DimensionElementPrincipalName", "2|GetProcessName", "2|TM1User", "2|Timst", "1|Dayno", "2|GetProcessErrorFileDirectory", "1|ExecuteProcess", "1|RunProcess" ]
VarArray := StrSplit(out, "`n")
Loop % VarArray.MaxIndex()
{
my_var_name := VarArray[A_Index]
StringLower, vmy_var_name, my_var_name
Found := 0
if( vmy_var_name = "datasourceasciidelimiter"
Or vmy_var_name = "datasourceasciiquotecharacter"
Or vmy_var_name = "datasourceasciidecimalseparator"
Or vmy_var_name = "datasourceasciithousandseparator"
Or vmy_var_name = "datasourceasciiheaderrecords"
Or vmy_var_name = "datasourcetype"
Or vmy_var_name = "datasourcenameforserver"
Or vmy_var_name = "datasourcenameforclient"
Or vmy_var_name = "datasourcecubeview"
Or vmy_var_name = "datasourcedimensionsubset"
Or vmy_var_name = "datasourceusername"
Or vmy_var_name = "datasourcepassword"
Or vmy_var_name = "datasourcequery"
Or vmy_var_name = "vmask"
Or vmy_var_name = "vdec"
Or vmy_var_name = "v1000" )
{
Found := 1
LV_Add("", "Custom variable", my_var_name, "Text")
}
If( Found = 0 )
{
for i, element in Lookup_VarType
{
Element_Type := SubStr(element, 1, InStr(element, "|") - 1)
If( Element_Type == "1" )
Element_Type_Full := "Number"
Else
Element_Type_Full := "Text"
Element_Function := SubStr(element, InStr(element, "|") + 1)
if( InStr(Text_of_vars_no_whitespace, e . my_var_name . "=" . Element_Function ) > 0 )
{
Found := 1
LV_Add("", "Custom variable", my_var_name, Element_Type_Full)
Break
}
}
}
If( Found = 0 )
{
Needle := e . my_var_name . "="
FoundPos := InStr(Text_of_vars_no_whitespace, Needle )
Following_Character := SubStr(Text_of_vars_no_whitespace, FoundPos + StrLen(Needle), 1)
if Following_Character Is Integer
{
Found := 1
LV_Add("", "Custom variable", my_var_name, "Number")
}
}
If( Found = 0 )
{
vFirst_Letter := Substr( my_var_name, 1, 1 )
StringLower, vFirst_Letter, vFirst_Letter
if( vFirst_Letter = "n" )
{
Found := 1
LV_Add("", "Custom variable", my_var_name, "Number")
}
else if( vFirst_Letter = "s" )
{
Found := 1
LV_Add("", "Custom variable", my_var_name, "Text")
}
}
If( Found = 0 )
LV_Add("", "Custom variable", my_var_name, "Text/Number")
}
}
return
Output_in_Selected_Order:
Gui, Submit, NoHide
if ( Output_in_Selected_Order = True )
{}
else
{
Loop % LV_GetCount()
LV_Modify(A_Index, "Col4", "")
}
AO_ReIndex:
; 1. read the order numbers and row numbers in an associative array
oArray := {}
Loop % LV_GetCount()
{
LV_GetText(my_order, A_Index, 4)
if ( my_order != "" )
oArray[A_Index] := my_order
}
; 2. sort the array on the order numbers
temp := {}
for key, val in oArray
temp[val] ? temp[val].Insert(key) : temp[val] := [key]
; 3. loop over the sorted array and populate the order for the row number in ascending manner
c := 0
for i, x in temp
for k, y in x
{
; msgbox %i% - %k% - %y%
c += 1
LV_Modify(y, "Col4", c)
}
return
AO_RemoveDups:
ControlList := "|"
DupesList :=
Loop % LV_GetCount()
{
LV_GetText(RowText, A_Index, 2)
IfInString, ControlList, |%RowText%|
DupesList = %A_Index%|%DupesList%
else
ControlList = |%RowText%%ControlList%
}
; DupesList .= A_Index . "|"
Loop, parse, DupesList, |
{
If A_LoopField is integer
LV_Delete(A_LoopField)
}
return
AO_SelectALL:
Gui, Submit, NoHide
LV_Modify(0, "Select")
if ( Output_in_Selected_Order = True )
Loop % LV_GetCount()
LV_Modify(A_Index, "Col4", A_Index)
return
Switch_Text_Number:
Gui, Submit, NoHide
selectedCount := LV_GetCount("Selected")
if not selectedCount
{
msgbox Please select 1 or more variables.
Return
}
RowNumber := 0
Loop
{
RowNumber := LV_GetNext(RowNumber)
if not RowNumber