-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathAHKRareTheGui.ahk
1628 lines (1394 loc) · 306 KB
/
AHKRareTheGui.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
; ===============================================================
; *** AHK-RARE the GUI *** -- !SEARCH COMFORTABLE! -- V0.80 November 24, 2019 by Ixiko
; ===============================================================
; ------------------------------------------------------------------------------------------------------------
; MISSING THINGS:
; ------------------------------------------------------------------------------------------------------------
;
; 1. Highlighting the search term(s) in the RichEdit controls
; 2. Keywords should be displayed in the description with a larger font
; ------------------------------------------------------------------------------------------------------------
;{01. script parameters
#NoEnv
#Persistent
#SingleInstance, Force
#InstallKeybdHook
#MaxThreads, 250
#MaxThreadsBuffer, On
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 1
;ListLines Off
SetTitleMatchMode , 2
SetTitleMatchMode , Fast
DetectHiddenWindows , Off
CoordMode , Mouse, Screen
CoordMode , Pixel, Screen
CoordMode , ToolTip, Screen
CoordMode , Caret, Screen
CoordMode , Menu, Screen
SetKeyDelay , -1, -1
SetBatchLines , -1
SetWinDelay , -1
SetControlDelay , -1
SendMode , Input
AutoTrim , On
FileEncoding , UTF-8
OnExit("TheEnd")
Menu, Tray, Icon , % "hIcon: " Create_GemSmall_png(true)
;---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
; Script Prozess ID
;---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
scriptPID:= DllCall("GetCurrentProcessId")
;}
;{02. variables
ARFile := Array() ; indexed array of AHKRare.ahk file, index is corresponding to line number
RC := Object()
GuiW := 1200 ; base width of gui on first start
SR1Width := 250
highlight := false ; flag to highlight search results
global ARData := Object() ; contains data from AHKRare.ahk
global FoundIndex := 0 ; a flag
global currentFuncNr ; contains the currently selected function nr
global fdecr1, fdecr2
; ------------------------------------------------------------------------------------------------------------------------------------------------------------
; loading AHK-Rare.txt
; ------------------------------------------------------------------------------------------------------------------------------------------------------------;{
If FileExist(A_ScriptDir . "\AHK-Rare.txt")
ARFile:= RareLoad(A_ScriptDir "\AHK-Rare.txt")
else
{
IniRead, filepattern, % A_ScriptDir "\AHK-Rare_TheGui.ini", Properties, RareFolder
If Instr(filepattern, "ERROR")
{
FileSelectFile, filepattern,, % A_ScriptDir, % "Please enter the location of the AHK-Rare.txt file here!", % "AHK-Rare.txt"
If (filepattern = "") || !FileExist(filepattern)
ExitApp
IniWrite, % filepattern, % A_ScriptDir "\AHK-Rare_TheGui.ini", Properties, RareFolder
}
ARFile:= RareLoad(filepattern)
}
;}
; ------------------------------------------------------------------------------------------------------------------------------------------------------------
; get the last gui size
; ------------------------------------------------------------------------------------------------------------------------------------------------------------;{
IniRead, GuiOptions, % A_ScriptDir "\AHK-Rare.ini", Properties, GuiOptions
If !Instr(GuiOptions, "Error") && !(GuiOptions = "")
{
GuiOptions := StrSplit(GuiOptions, "|")
GuiW := GuiOptions.3
}
IniRead, SearchMode, % A_ScriptDir "\AHK-Rare.ini", Properties, SearchMode
If Instr(SearchMode, "Error") || (SearchMode = "")
SearchMode:= "Basic"
;}
; ------------------------------------------------------------------------------------------------------------------------------------------------------------
; Settings array for the RichCode control (code & examples)
; ------------------------------------------------------------------------------------------------------------------------------------------------------------;{
Settings :=
( LTrim Join Comments
{
"TabSize" : 4,
"Indent" : "`t",
"FGColor" : 0xEDEDCD,
"BGColor" : 0x172842,
"Font" : {"Typeface": "Bitstream Vera Sans Mono", "Size": 10},
"WordWrap" : False,
"UseHighlighter" : True,
"HighlightDelay" : 200,
"Colors": {
"Comments" : 0x7F9F7F,
"Functions" : 0x7CC8CF,
"Keywords" : 0xE4EDED,
"Multiline" : 0x7F9F7F,
"Numbers" : 0xF79B57,
"Punctuation" : 0x97C0EB,
"Strings" : 0xCC9893,
; AHK
"A_Builtins" : 0xF79B57,
"Commands" : 0xCDBFA3,
"Directives" : 0x7CC8CF,
"Flow" : 0xE4EDED,
"KeyNames" : 0xCB8DD9,
"Descriptions" : 0xF0DD82,
"Link" : 0x47B856,
; PLAIN-TEXT
"PlainText" : 0x7F9F7F
}
}
)
;}
;}
;{03. draw primary gui
If (A_ScreenWidth>1920) && (A_ScreenHeight>1080)
{
fdecr1:= 0, fdecr2:=0, YPlus:= 0
Logo:= Create_AHKRareGuiLogo4k_png(true)
}
else
{
fdecr1:= 1, fdec2:=4, YPlus:= 10
Logo:= Create_AHKRareGuiLogo2k_png(true)
Logo.height += 20
}
global hArg, ARG, hSearch, hTabs
Gui, ARG: NEW
Gui, ARG: +LastFound +HwndhARG +Resize -DPIScale
Gui, ARG: Margin, 0, 0
;Gui, ARG: Color, 172842
;-: --------------------------------------
;-: Logo and Backgroundcolouring
;-: --------------------------------------
Gui, ARG: Add, Progress , % "x0 y0 w" (GuiW) " h" (Logo.height + 5) " c172842 Disabled vBGColorLogo" , 100
Gui, ARG: Add, Pic , % "x10 y" 10+YPlus " BackgroundTrans" , % "HBITMAP: " logo.hBitmap
Gui, ARG: Add, Progress , % "x" (logo.width + 10) " y0 w2 h" (Logo.height + 5) , 100
Gui, ARG: Font, % "S" 7-fdecr1 " CWhite q5"
Gui, ARG: Add, Text , % "x" (Logo.width - 201) " y6 w200 Right vStats2 BackgroundTrans" , % ""
Gui, ARG: Font, % "S" 7-fdecr1 " c9090FF q5"
Gui, ARG: Add, Text , % "x" (Logo.width - 201) " y+0 w200 Right vStats1 BackgroundTrans" , % ""
;-: --------------------------------------
;-: temp. text controls
;-: --------------------------------------
Gui, ARG: Font, % "S" 12-fdecr2 " Normal CWhite q5"
Gui, ARG: Add, Text , % "x" (Logo.width + 30) " y20 vField1 BackgroundTrans" , % " . . . . . create index: "
GuiControlGet, Field_, ARG: Pos, Field1
Gui, ARG: Add, Text , % "x" (Field_X + Field_W + 3) " y20 w300 vField2 Center BackgroundTrans " , % "00.00.000001"
;-: --------------------------------------
;-: Edit control for search patterns
;-: --------------------------------------
SW:= Logo.width + 20
Gui, ARG: Font, % "S" 10-fdecr2 " Normal CBlack q5"
Gui, ARG: Add, DDL , % "x" (SW) " y50 vSMode HWNDhSAlgo E0x4000" , % "Basic|RegEx" ;E0x4000
GuiControl, ChooseString, SMode, % SearchMode
Gui, ARG: Font, % "S" 11-fdecr2 " Italic CAAAAAA q5"
GuiControlGet, SA_, ARG: Pos, SMode
Gui, ARG: Add, Edit , % "x" (SW+SA_W+5) " y50 w500 r1 vLVExpression HWNDhSearch -Theme" , % "type your search pattern here"
GuiControlGet, LVExpression_, ARG: Pos, LVExpression
PostMessage, 0x153, -1, % LVExpression_H - 5,, ahk_id %hSAlgo% ; sets the height of DDL
Gui, ARG: Font, % "S" 16-fdecr2*2 " Normal CWhite q5"
Gui, ARG: Add, Text , % "x" (SW) " y5 w300 vGB1 HWNDhGB1 Border BackgroundTrans" , % ""
Gui, ARG: Add, Text , % "x" (SW + 10) " y12 w300 vField3 HWNDhField3 -Wrap BackgroundTrans" , % ""
Edit_SetMargins(hField3, 40, 20)
Edit_SetMargins(hSearch, 20, 20)
;CTLCOLORS.Attach(hSAlgo, "677892")
;-: --------------------------------------
;-: Functions Listview
;-: --------------------------------------
Gui, ARG: Font, % "S" 9-fdecr1 " Normal CDefault q5"
Gui, ARG: Add, Listview , % "xm y" (Logo.height + 15) " w" GuiW+5 " r15 HWNDhLVFunc vLVFunc gShowFunction AltSubmit Section", main section|function name|short description|function nr.
Gui, ARG: Font, % "S" 8-fdecr1 " CDefault q5"
GuiControlGet, LV_, ARG: Pos, LVFunc
;-: --------------------------------------
;-: Short description section
;-: --------------------------------------
Gui, ARG: Add, Edit , % "xm y" (LV_Y + LV_H + 10) " w" SR1Width " r20 t8 HWNDhShowRoom1 vShowRoom1"
GuiControlGet, SR_, ARG: Pos, ShowRoom1
;-: --------------------------------------
;-: Code highlighted RichEdit control
;-: --------------------------------------
Gui, ARG: Add, Tab , % "x" (SR1Width+5) " y" (LV_Y+LV_H+10) " w" (GuiW-SR1Width-5) " h" SR_H-10 " HWNDhTabs vShowRoom2", FUNCTION CODE|EXAMPLE(s)|DESCRIPTION
Gui, ARG: Tab, 1
RC[1] := new RichCode(Settings, "ARG", "x" (SR1Width+5) " y" (LV_Y+LV_H+40) " w" (GuiW-SR1Width-5) " h" SR_H-30, 0)
Gui, ARG: Tab, 2
RC[2] := new RichCode(Settings, "ARG", "x" (SR1Width+5) " y" (LV_Y+LV_H+40) " w" (GuiW-SR1Width-5) " h" SR_H-30, 0)
Gui, ARG: Tab, 3
RC[3] := new RichCode(Settings, "ARG", "x" (SR1Width+5) " y" (LV_Y+LV_H+40) " w" (GuiW-SR1Width-5) " h" SR_H-30, 0)
Gui, ARG: Tab
WinRC := GetWindowInfo(RC[1].Hwnd)
;-: --------------------------------------
;-: Create a Statusbar - on Win 10 this Gui looks weird without a border
;-: --------------------------------------
Gui, ARG: Add, StatusBar, % "x0 y" WinRC.WindowY + 2 " vSB", % "clipboard is empty or does not contain a function"
GuiControlGet, SB_, ARG: Pos, SB
;-: --------------------------------------
;-: Create a ToolTip control
;-: --------------------------------------
TT := New GuiControlTips(HARG)
TT.SetDelayTimes(500, 3000, -1)
Loop, 3
TT.Attach(RC[A_Index].Hwnd, "Press the right`nmouse button`nto copy the text.", True)
;-: --------------------------------------
;-: Show the gui
;-: --------------------------------------
If !Instr(GuiOptions, "Error") && !(GuiOptions = "")
{
DPIFactor:= screenDims().DPI / 96
If ((GuiOptions.1 + GuiOptions.3)> A_ScreenWidth) || ((GuiOptions.2 + GuiOptions.4) > A_ScreenHeight)
Gui, ARG: Show, AutoSize xCenter yCenter, AHK-Rare_TheGui
else
Gui, ARG: Show, % "x" GuiOptions.1 " y" GuiOptions.2 " w" (GuiOptions.3) " h" (GuiOptions.4), AHK-Rare_TheGui
}
else
Gui, ARG: Show, AutoSize xCenter yCenter, AHK-Rare_TheGui
OnMessage(0x200 , "OnMouseHover")
OnMessage(0x03 , "ChangeStats")
OnClipboardChange("RareClipChanged")
SetTimer, ShowStats, -500
;}
;{04. generate and fill listview with data
; indexing AHK-Rare
ARData:= RareIndexer(ARFile)
; remove text controls
GuiControl, ARG: Hide , Field1
GuiControl, ARG: Hide , Field2
GuiControl, ARG: Show , Field3
; populate listview with data from AHK-Rare.txt
GuiControl, +Default, ARG: LVFunc
For i, function in ARData
LV_Add("", function.mainsection, function.name, function.short, function.FnHash), fc:= A_Index
; show's the sum of functions
GuiControl, Text, Field3, % "displayed functions: " fc
;}
;{05. Hotkey(s)
; RButton for getting text to clipboard
Hotkey, IfWinActive, % "ahk_id " hARG
Hotkey, ~RButton , CopyTextToClipboard
Hotkey, ^f , FocusSearchField
Hotkey, ^s , FocusSearchField
; Listview Hotkey's
ListviewIsFocused:= Func("ControlIsFocused").Bind("SysListview321")
Hotkey, If , % ListviewIsFocused
Hotkey, ~Up , ListViewUp
Hotkey, ~Down , ListViewDown
; Edit Hotkey's
SearchIsFocused:= Func("ControlIsFocused").Bind("Edit1")
Hotkey, If , % SearchIsFocused
Hotkey, ~Enter , GoSearch
Hotkey, If
Hotkey, ^#!r , ReloadScript
return
;}
;--------------------------------------------------------------------------------------------------------------
;{06. Gui-Labels
;--------------------------------------------------------------------------------------------------------------
ShowFunction: ;{
toshow := []
selRow:= LV_GetNext(0)
ShowFunctionsOnUpDown:
LV_GetText(fnr, selRow , 4)
For i, function in ARData
If Instr(function.FnHash, fnr)
break
currentFuncNr:= i
; adding informations to Edit-Control (ShowRoom1)
toshow[1]:= "FUNCTION:`n" ARData[i].name
toshow[1].= "`n-----------------------------------------`n"
toshow[1].= "SHORT DESCRIPTION:`n" ARData[i].short
toshow[1].= "`n-----------------------------------------`n"
toshow[1].= "MAIN SECTION:`n" ARData[i].mainsection
toshow[1].= "`n-----------------------------------------`n"
toshow[1].= "MAIN SECTION DESC.:`n" ARData[i].mainsectionDescription
toshow[1].= "`n-----------------------------------------`n"
toshow[1].= "SUB SECTION:`n" ARData[i].subsection
toshow[1].= "`n-----------------------------------------`n"
GuiControl, ARG:, ShowRoom1, % toshow[1]
; populate function code tab and examples tab
RC[1].Settings.Highlighter := "HighlightAHK"
RC[1].Value := ARData[i].code
If StrLen(ARData[i].examples) > 0
{
HighlightTab(hTabs, 1, 1)
RC[2].Settings.Highlighter := "HighlightAHK"
RC[2].Value := ARData[i].examples
}
else
{
HighlightTab(hTabs, 1, 0)
RC[2].Value := ""
}
; reading data from the function included description section
toshow[2]:=""
If IsObject(ARData[i]["Description"])
{
For descKey, Text in ARData[i]["Description"]
{
If descKey
toshow[2].= Format("{:U}", Trim(descKey)) ":`n"
else
continue
Text:= StrReplace(Text, "`n`r`n`r", "`n")
Text:= StrReplace(Text, "`r`n`r`n", "`n")
Loop, 5
Text := StrReplace(Text, SubStr("`t`t`t`t`t`t`t`t", 7 - A_Index) , A_Tab)
Loop, Parse, Text, `n
toshow[2].= Rtrim(A_LoopField, ",") "`n"
;toshow[2].= "-----------------------------------------------------------------`n`n"
}
If StrLen(toshow[2])> 0
{
HighlightTab(hTabs, 2, 1)
; populate the description Tab
RC[3].Value := toshow[2]
RC[3].Settings.Highlighter := "HighlightAHK"
}
else
{
HighlightTab(hTabs, 2, 0)
RC[3].Value := ""
}
}
; highlight search terms
If highlight
{
RE_FindTextAndSelect(RC[1].Hwnd, LVExpression, {1:"Down"})
}
return
;}
;--------------------------------------------------------------------------------------------------------------
GoSearch: ;{
Gui, Arg: Submit, NoHide
If StrLen(LVExpression) = 0
return
foundIndex:= 0
GuiControl, ARG:Focus, LVFunc
results:= RareSearch(LVExpression, ARData, ARFile, SMode)
If results.MaxIndex() > 0
{
; fill listview with collection
highlight:= true ; flag to highlight searchtearms in RichEdit code
Gui, ARG: Default
LV_Delete()
GuiControl, ARG: -Redraw, LVFunc
Loop, % results.MaxIndex()
{
foundIndex:= Results[A_Index]
For i, function in ARData
If Instr(function.FnHash, foundIndex)
LV_Add("", function.mainsection, function.name, function.short, function.FnHash)
}
GuiControl, ARG: +Redraw, LVFunc
GuiControl, Text, Field3, % "Search result: " results.MaxIndex() " functions"
}
else
{
highlight:= false
GuiControl, Text, Field3, % "Search result: nothing matched"
}
return ;}
;--------------------------------------------------------------------------------------------------------------
ARGGuiSize: ;{
Critical, Off
Critical
GuiControl, ARG: Move, BGColorLogo , % "w" (A_GuiWidth)
GuiControl, ARG: Move, LVExpression , % "w" (A_GuiWidth - Logo.width - 32 - SA_W)
GuiControl, ARG: Move, GB1 , % "w" (A_GuiWidth - Logo.width - 30) " h40 y5"
GuiControl, ARG: Move, Field3 , % "w" (A_GuiWidth - Logo.width - 40) " h30"
GuiControl, ARG: Move, LVFunc , % "w" (A_GuiWidth) ;" h"(A_GuiHeight//3)
GuiControlGet, LV_, ARG: Pos, LVFunc
LV_AutoColumSizer(hLVFunc, "10% 15% 60%")
GuiControl, ARG: Move, ShowRoom1 , % "y" (LV_Y+LV_H+10) " h" (A_GuiHeight-LV_Y-LV_H-10-SB_H)
GuiControl, ARG: Move, ShowRoom2 , % "x" (SR1Width+5) " y" (LV_Y+LV_H+10) " w" (A_GuiWidth-SR1Width-5) " h" (A_GuiHeight-LV_Y-LV_H-10-SB_H)
GuiControl, ARG: Move, % RC[1].hwnd , % "x" (SR1Width+5) " y" (LV_Y+LV_H+40) " w" (A_GuiWidth-SR1Width-5) " h" (A_GuiHeight-LV_Y-LV_H-30-SB_H)
GuiControl, ARG: Move, % RC[2].hwnd , % "x" (SR1Width+5) " y" (LV_Y+LV_H+40) " w" (A_GuiWidth-SR1Width-5) " h" (A_GuiHeight-LV_Y-LV_H-30-SB_H)
GuiControl, ARG: Move, % RC[3].hwnd , % "x" (SR1Width+5) " y" (LV_Y+LV_H+40) " w" (A_GuiWidth-SR1Width-5) " h" (A_GuiHeight-LV_Y-LV_H-30-SB_H)
GuiControl, ARG: Move, SB , % "x" 0 " y" (A_GuiHeight - SB_H) " w" (A_GuiWidth)
Critical, Off
SetTimer, ShowStats, -200
return ;}
;--------------------------------------------------------------------------------------------------------------
ARGGuiClose: ;{
ARGEscape:
Gui, Arg: Submit, NoHide
win := GetWindowInfo(hARG)
IniWrite, % SMode, % A_ScriptDir "\AHK-Rare.ini", Properties, SearchMode
;IniWrite, % win.WindowX "|" win.WindowY "|" (win.ClientW) "|" (win.ClientH), % A_ScriptDir "\AHK-Rare.ini", Properties, GuiOptions
IniWrite, % win.WindowX "|" win.WindowY "|" (win.WindowW) "|" (win.WindowH), % A_ScriptDir "\AHK-Rare.ini", Properties, GuiOptions
ExitApp ;}
;--------------------------------------------------------------------------------------------------------------
ShowStats: ;{
WinGetPos, wx, wy, ww, wh, % "ahk_id " hARG
GuiControl, ARG:, Stats2, % "x" wx " y" wy " w" ww " h" wh
return
ChangeStats() {
WinGetPos, wx, wy, ww, wh, % "ahk_id " hARG
GuiControl, ARG:, Stats2, % "x" wx " y" wy " w" ww " h" wh
}
;}
;--------------------------------------------------------------------------------------------------------------
CopyTextToClipboard: ;{
toCopy := ""
MouseGetPos, mx, my,, hControlOver, 2
RichEditControls:= RC.1.hwnd "," RC.2.hwnd "," RC.3.hwnd
If Instr(hControlOver, hTabs) || hControlOver in %RichtEditControls%
{
Loop, % (ARData[currentFuncNr].end - ARData[currentFuncNr].start) + 1
tocopy .= ARFile[ARData[currentFuncNr].start + A_Index - 1] "`n"
Clipboard := tocopy
ToolTip, % "copied to clipboard...", % mx -10, % my + 10, 2
SetTimer, TTOff, -2000
}
return
TTOff:
ToolTip,,,, 2
return ;}
;--------------------------------------------------------------------------------------------------------------
FocusSearchField: ;{
GuiControl, ARG: Focus, LVExpression
return ;}
;--------------------------------------------------------------------------------------------------------------
ListViewUp:
ListViewDown: ;{
If !WinActive("AHK-Rare_TheGui ahk_class AutoHotkeyGUI")
return
If Instr(A_ThisLabel, "ListViewUp")
Send, {Up}
else
Send, {Down}
selRow:= LV_GetNext("F")
gosub ShowFunctionsOnUpDown
return ;}
;--------------------------------------------------------------------------------------------------------------
ReloadScript: ;{ only for reloading the script after hotkey press (development purposes)
Gui, Arg: Submit, NoHide
win := GetWindowInfo(hARG)
IniWrite, % SMode, % A_ScriptDir "\AHK-Rare.ini", Properties, SearchMode
IniWrite, % win.WindowX "|" win.WindowY "|" (win.ClientW) "|" (win.ClientH), % A_ScriptDir "\AHK-Rare.ini", Properties, GuiOptions
Reload
return ;}
;}
;{07. AHK Rare Gui Functions
RareSearch(LVExpression, ARData, ARFile, mode:="RegEx") { ;-- search all AHK Rare functions
results:= Array()
; collecting all results
Loop, % ARFile.MaxIndex()
{
If RegExMatch(ARFile[A_Index], "(;\s*\<\d\d\.\d\d\.\d\d\d\d\d)|(;\s*\<\d\d\.\d\d\.\d\d.\d\d\d\d\d)")
{
RegExMatch(ARFile[A_Index], "[\d\.]+", FnHash)
found:= 0
continue
}
If (found = 0)
If Instr(mode, "RegEx") && RegExMatch(ARFile[A_Index], LVExpression)
results.Push(FnHash), found:= 1
else if Instr(mode, "Basic") && Instr(ARFile[A_Index], LVExpression)
results.Push(FnHash), found:= 1
}
return results
}
RareLoad(FileFullPath) { ;-- loads AHK Rare as an indexed array
ARFile:= Array()
FileRead, filestring, % FileFullPath
Loop, Parse, filestring, `n, `r
ARFile[A_Index]:= A_LoopField, i:= A_Index
ARFile[i+1]:= FileFullPath
return ARFile
}
RareSave(ARFile) { ;-- save back changes to AHK Rare
filepath:= ARFile[ARFile.MaxIndex()]
File:= FileOpen(filepath, "w")
Loop, % ARFile.MaxIndex() - 1
File.WriteLine(ARFile[A_Index])
File.Close()
return Errorlevel
}
RareIndexer(ARFile) { ;-- list all functions inside AHK RARE script
; defining some variables
ARData:= Object(), ARData.DescriptionKeys := Object()
s:=fI:=descFlag:=descKeyFlag:=descKeyFlagO :=0
Brackets := 0 ; counter to find the end of a function
DoBracketCount := 0 ; flag
FirstBracket := 0 ; flag
originchange := 0 ; counter for changed lines in AHKRare.ahk - Autosyntax correcting functionality
; parsing algorithm for AHK-Rare
Loop, % ARFile.MaxIndex() - 1
{
line:= ARFile[A_Index]
If (DoBracketCount = 1) && !descflag && !exampleFlag ; to find the last bracket of a function
{
Brackets += BracketCount(line)
If (Brackets > 0) && (FirstBracket = 0)
FirstBracket:= 1
}
If RegExMatch(line, "(?<=\{\s;)[\w\s-\+\/\(\)]+(?=\(\d+\))") ; name of mainsection
{
RegExMatch(line, "(?<=\{\s;)[\w\s-\+\/\(\)]+(?=\(\d+\))", mainsection)
mainsection := Trim(mainsection)
subsection := ""
RegExMatch(line, "(?<=--\s)[\w\s]+(?=\s--)", MainSectionDescription)
descFlag:=descKeyFlag:=descKeyFlagO:=TrailingSpacesO:=TrailingSpaces := 0
continue
}
else If RegExMatch(line, "(?<=\{\s;)\<\d\d\.\d\d[\d\.]*\>\:\s[\w\-\_\+\/\(\)]+") ; name of subsection
{
RegExMatch(line, "(?<=\>\:\s)[\w\-\_\s\+\/]+", subsection)
subsection:= Trim(subsection)
continue
}
else If RegExMatch(line, "(;\s*\<\d\d\.\d\d\.\d\d\d\d\d)|(;\s*\<\d\d\.\d\d\.\d\d.\d\d\d\d\d\d)") ; new function
{
; ---------------------------------------------------------------------------------------------------------------------------------------------------------
; last data from previous function will be stored
; --------------------------------------------------------------------------------------------------------------------------------------------------------- ;{
; if function boundaries are not set proper, e.g. missing function index at the end of a function or mispellings between start index and end index
/*
If (ARData[(fI)].end = "")
{
i:= A_Index
While, (i > 0)
If RegExMatch(ARFile[i:= i - 1], "^\s*\}")
{
ARData[(fI)].end := i
RegExMatch(ARFile[i], "^\s*\}", prepend)
RegExMatch(ARFile[i], "\s*\}\s*[;<\d./>]*\s*(.*)", append)
ARFile[i] := prepend " `;<`/" ARData[(fI)].FnHash ">" (StrLen(append1) > 0 ? " " append1 : "")
originchange ++
break
}
}
*/
RegExmatch(ARFile[(ARData[(fI)].start)-1],"[\d\.]+", startIndex)
RegExmatch(ARFile[(ARData[(fI)].end)], "[\d\.]+", endIndex)
If (startIndex <> endIndex)
{
i:= ARData[(fI)].end
RegExMatch(ARFile[i], "^\s*\}", prepend)
RegExMatch(ARFile[i], "\s*\}\s*[;<\d./>]*\s*(.*)", append)
ARFile[i] := prepend " `;<`/" ARData[(fI)].FnHash ">" (StrLen(append1) > 0 ? " " append1 : "")
originchange ++
origin .= i "(" A_Index "), "
}
; close the last function code to have a right syntax
ARData[(fI)].code := Trim(ARData[(fI)].code, "`n")
ARData[(fI)].code := Trim(ARData[(fI)].code, "`r")
If !RegExMatch(ARData[(fI)].code, "m)\}\s*\;\<\/[\d\.]+\>\s*") && !RegExMatch(ARData[(fI)].code, "m)\n\s*\}\s*$")
ARData[(fI)].code .= "`n}"
; shorten example code
ARData[(fI)].examples := Trim(ARData[(fI)].examples, "`n`r")
Loop, 5 ; deletes up 2 empty lines
{
ARData[(fI)].examples := StrReplace(ARData[(fI)].examples , SubStr("`n`n`n`n`n`n`n`n`n", 1, 8 - A_Index), "`n")
ARData[(fI)].code := StrReplace(ARData[(fI)].code , SubStr("`n`n`n`n`n`n`n`n`n", 1, 8 - A_Index), "`n")
}
ARData[(fi)]["description"][(descKey)] := RTrim(ARData[(fi)]["description"][(descKey)], "`n")
;}
; ---------------------------------------------------------------------------------------------------------------------------------------------------------
; data collecting for a new function starts here
; --------------------------------------------------------------------------------------------------------------------------------------------------------- ;{
FirstBracket:= descFlag:=descKeyFlag:=descKeyFlagO:=TrailingSpacesO:=TrailingSpaces:=NoCode:= 0 ; re-initialize flags
RegExMatch(line, "[\d\.]+", FnHash) ; gets the function hash
fi ++ ; function index (fi) enumerator
ARData[(fI)] := Object()
ARData[(fi)].description := Object()
ARData[(fI)].FnHash := FnHash
ARData[(fI)].start := A_Index+1
ARData[(fI)].mainsection := mainsection
ARData[(fI)].mainsectionDescription := mainsectionDescription
ARData[(fI)].subsection := subsection
GuiControl, Text, Field2, % fI ", " fname "`)"
continue
;}
}
else If RegExMatch(line, "^\s*\}\s*\;\s*\<\/") || ((DoBracketCount = 1) && (FirstBracket = 1) && (Brackets = 0)) ; function end
{
ARData[(fI)].end := A_Index
descFlag := 0
NoCode := 1
Brackets := 0
FirstBracket := 0
DoBracketCount := 0
}
else If RegExMatch(line, "[\w\_-]+\([\w\d\s\,\=\.\*#-|\:\""""]*\)\s*\{\s+;--.*") || RegExMatch(line, "[\w\_-]+\([\w\d\s\,\=\.\*#-|\:\""""]*\s*;--.*") ; find function
{
;TrailingSpaces:= countTrailingSpaces(line)
RegExMatch(line, "^\s*", trailing)
RegExMatch(line, "[\w\_-\d]+\(", fname)
RegExMatch(line, "(?<=;--).*", fshort)
ARData[(fI)].name := Trim(fname) "`)"
ARData[(fI)].short := Trim(fshort)
ARData[(fI)].subsection := subsection
ARData[(fI)].code := RegExReplace(line, "^" trailing) "`n"
Brackets := BracketCount(line)
DoBracketCount := 1
}
else if RegExMatch(line, "i).*DESCRIPTION\s") ; description section
{
exampleFlag:= 0
descFlag:= 1
descKey:= Text:= ""
continue
}
else if RegExMatch(line, ".*(EXAMPLE\(s\))|(EXAMPLES)|(\/\*\s*Example)") ; example section
{
exampleFlag:= 1
descFlag:= 0
descKey:= Text:= ""
continue
}
else if ( descFlag = 1 || exampleFlag = 1) && (Instr(line, "--------------") || Instr(line, "========================")) ; ignores specific internal layout lines
continue
else if ( descFlag = 1 || exampleFlag = 1) && RegExMatch(line, "\*\/") ; end of descriptions or examples section
{
exampleFlag:= descFlag:= descKeyFlag:= exampleIndent := 0
descKey:=""
continue
}
else if (descFlag = 1) && RegExMatch( line, "^\s+[\w\(\)-\s]+(?=\s+\:\s+|\N)" ) ; description key is found
{
; ---------------------------------------------------------------------------------------------------------------------------------------------------------
; the formatting of the AHK-Rare.txt file creates difficulties in distinguishing the description key from the associated text
; ---------------------------------------------------------------------------------------------------------------------------------------------------------
TrailingSpaces:= countTrailingSpaces(line)
If TrailingSpacesO && (TrailingSpaces >= (TrailingSpacesO + 1))
{
ARData[(fi)]["description"][(descKey)] .= LTrim(line) "`n"
continue
}
descKeyFlagO := descKeyFlag
descKeyFlag ++
RegExMatch(line, "^\s+[\w\(\)-\s]+(?=\s+:\s+)", descKey) ; determines the description key
descKey:= Trim(descKey)
If !ARData.DescriptionKeys.HasKey(descKey) ; collecting available keys for search function
ARData.DescriptionKeys[(descKey)].Push(FnHash "|")
RegExMatch(line, "(?<=\:).*", Text) ; determines the corresponding text of the description
ARData[(fi)]["description"][(descKey)] := LTrim(Trim(Text), "`n`r") "`n"
TrailingSpacesO := TrailingSpaces
}
else if (descFlag = 1) && (descKeyFlag > descKeyFlagO) ; adding descriptions
ARData[(fi)]["description"][(descKey)] .= LTrim(line) "`n"
else if (exampleFlag = 1) ; parsing example section
{
If !exampleIndent && StrLen(line) >= 2
exampleIndent := countTrailingSpaces(line)
If (StrLen(line) <= 2 && StrLen(ARData[(fI)].examples) <= 2) || (StrLen(line) >= 2)
ARData[(fI)].examples .= SubStr(line, exampleIndent +1, StrLen(line) - exampleIndent) "`n"
}
else if (NoCode = 0) ; if nothing fits it is program code
{
ARData[(fI)].code .= RegExReplace(line, "^" trailing) "`n"
}
}
; this function save's correction made to AHK-Rare code from parsing algorithm before
If (originchange > 0)
{
GuiControl, ARG:, Stats1, % originchange " lines of code corrected"
RareSave(ARFile)
}
return ARData
}
RareGetFunctionObject(hash) { ;-- returns the data object to one function
For i, function in ARData
If Instr(function.FnHash, fnr)
break
return ARData[i]
}
RareClipChanged(Type) {
Gui, ARG: Default
If Type = 0
SB_SetText("clipboard is empty" )
else If Type = 1
{
clip:= Clipboard
;ToolTip, % "funcNr: " currentFuncNR "`nType: " Type "`nfName: " StrReplace(ARData[currentFuncNr].name, "()") "`nFunc in clipboard?: " Instr(clip, StrReplace(ARData[currentFuncNr].name, "()"))
If Instr(clip, StrReplace(ARData[currentFuncNr].name, "()"))
SB_SetText("clipboard contains " ARData[currentFuncNr].name " to clipboard" )
else
SB_SetText("clipboard contains something that is not from AHK-Rare" )
}
else if Type = 2
SB_SetText("clipboard contains something that is not from AHK-Rare" )
}
BracketCount(str, brackets:="{}") { ;-- helps to find the last bracket of a function
RegExReplace(str, SubStr(brackets, 1, 1), "", open)
RegExReplace(str, SubStr(brackets, 2, 1), "", closed)
return open - closed
}
countTrailingSpaces(str) { ;-- counts all leading spaces of a string
Loop, % StrLen(str)
If Instr(A_Space "`t", SubStr(str, A_Index, 1))
TrailingSpaces ++
else
Break
return TrailingSpaces
}
;}
;{08. all the other functions
HighlightAHK(Settings, ByRef Code) {
static Flow := "break|byref|catch|class|continue|else|exit|exitapp|finally|for|global|gosub|goto|if|ifequal|ifexist|ifgreater|ifgreaterorequal|ifinstring|ifless|iflessorequal|ifmsgbox|ifnotequal|ifnotexist|ifnotinstring|ifwinactive|ifwinexist|ifwinnotactive|ifwinnotexist|local|loop|onexit|pause|return|settimer|sleep|static|suspend|throw|try|until|var|while"
, Commands := "autotrim|blockinput|clipwait|control|controlclick|controlfocus|controlget|controlgetfocus|controlgetpos|controlgettext|controlmove|controlsend|controlsendraw|controlsettext|coordmode|critical|detecthiddentext|detecthiddenwindows|drive|driveget|drivespacefree|edit|envadd|envdiv|envget|envmult|envset|envsub|envupdate|fileappend|filecopy|filecopydir|filecreatedir|filecreateshortcut|filedelete|fileencoding|filegetattrib|filegetshortcut|filegetsize|filegettime|filegetversion|fileinstall|filemove|filemovedir|fileread|filereadline|filerecycle|filerecycleempty|fileremovedir|fileselectfile|fileselectfolder|filesetattrib|filesettime|formattime|getkeystate|groupactivate|groupadd|groupclose|groupdeactivate|gui|guicontrol|guicontrolget|hotkey|imagesearch|inidelete|iniread|iniwrite|input|inputbox|keyhistory|keywait|listhotkeys|listlines|listvars|menu|mouseclick|mouseclickdrag|mousegetpos|mousemove|msgbox|outputdebug|pixelgetcolor|pixelsearch|postmessage|process|progress|random|regdelete|regread|regwrite|reload|run|runas|runwait|send|sendevent|sendinput|sendlevel|sendmessage|sendmode|sendplay|sendraw|setbatchlines|setcapslockstate|setcontroldelay|setdefaultmousespeed|setenv|setformat|setkeydelay|setmousedelay|setnumlockstate|setregview|setscrolllockstate|setstorecapslockmode|settitlematchmode|setwindelay|setworkingdir|shutdown|sort|soundbeep|soundget|soundgetwavevolume|soundplay|soundset|soundsetwavevolume|splashimage|splashtextoff|splashtexton|splitpath|statusbargettext|statusbarwait|stringcasesense|stringgetpos|stringleft|stringlen|stringlower|stringmid|stringreplace|stringright|stringsplit|stringtrimleft|stringtrimright|stringupper|sysget|thread|tooltip|transform|traytip|urldownloadtofile|winactivate|winactivatebottom|winclose|winget|wingetactivestats|wingetactivetitle|wingetclass|wingetpos|wingettext|wingettitle|winhide|winkill|winmaximize|winmenuselectitem|winminimize|winminimizeall|winminimizeallundo|winmove|winrestore|winset|winsettitle|winshow|winwait|winwaitactive|winwaitclose|winwaitnotactive"
, Functions := "abs|acos|array|asc|asin|atan|ceil|chr|comobjactive|comobjarray|comobjconnect|comobjcreate|comobject|comobjenwrap|comobjerror|comobjflags|comobjget|comobjmissing|comobjparameter|comobjquery|comobjtype|comobjunwrap|comobjvalue|cos|dllcall|exception|exp|fileexist|fileopen|floor|func|getkeyname|getkeysc|getkeystate|getkeyvk|il_add|il_create|il_destroy|instr|isbyref|isfunc|islabel|isobject|isoptional|ln|log|ltrim|lv_add|lv_delete|lv_deletecol|lv_getcount|lv_getnext|lv_gettext|lv_insert|lv_insertcol|lv_modify|lv_modifycol|lv_setimagelist|mod|numget|numput|objaddref|objclone|object|objgetaddress|objgetcapacity|objhaskey|objinsert|objinsertat|objlength|objmaxindex|objminindex|objnewenum|objpop|objpush|objrawset|objrelease|objremove|objremoveat|objsetcapacity|onmessage|ord|regexmatch|regexreplace|registercallback|round|rtrim|sb_seticon|sb_setparts|sb_settext|sin|sqrt|strget|strlen|strput|strsplit|substr|tan|trim|tv_add|tv_delete|tv_get|tv_getchild|tv_getcount|tv_getnext|tv_getparent|tv_getprev|tv_getselection|tv_gettext|tv_modify|tv_setimagelist|varsetcapacity|winactive|winexist|_addref|_clone|_getaddress|_getcapacity|_haskey|_insert|_maxindex|_minindex|_newenum|_release|_remove|_setcapacity"
, Keynames := "alt|altdown|altup|appskey|backspace|blind|browser_back|browser_favorites|browser_forward|browser_home|browser_refresh|browser_search|browser_stop|bs|capslock|click|control|ctrl|ctrlbreak|ctrldown|ctrlup|del|delete|down|end|enter|esc|escape|f1|f10|f11|f12|f13|f14|f15|f16|f17|f18|f19|f2|f20|f21|f22|f23|f24|f3|f4|f5|f6|f7|f8|f9|home|ins|insert|joy1|joy10|joy11|joy12|joy13|joy14|joy15|joy16|joy17|joy18|joy19|joy2|joy20|joy21|joy22|joy23|joy24|joy25|joy26|joy27|joy28|joy29|joy3|joy30|joy31|joy32|joy4|joy5|joy6|joy7|joy8|joy9|joyaxes|joybuttons|joyinfo|joyname|joypov|joyr|joyu|joyv|joyx|joyy|joyz|lalt|launch_app1|launch_app2|launch_mail|launch_media|lbutton|lcontrol|lctrl|left|lshift|lwin|lwindown|lwinup|mbutton|media_next|media_play_pause|media_prev|media_stop|numlock|numpad0|numpad1|numpad2|numpad3|numpad4|numpad5|numpad6|numpad7|numpad8|numpad9|numpadadd|numpadclear|numpaddel|numpaddiv|numpaddot|numpaddown|numpadend|numpadenter|numpadhome|numpadins|numpadleft|numpadmult|numpadpgdn|numpadpgup|numpadright|numpadsub|numpadup|pause|pgdn|pgup|printscreen|ralt|raw|rbutton|rcontrol|rctrl|right|rshift|rwin|rwindown|rwinup|scrolllock|shift|shiftdown|shiftup|space|tab|up|volume_down|volume_mute|volume_up|wheeldown|wheelleft|wheelright|wheelup|xbutton1|xbutton2"
, Builtins := "base|clipboard|clipboardall|comspec|errorlevel|false|programfiles|true"
, Keywords := "abort|abovenormal|activex|add|ahk_class|ahk_exe|ahk_group|ahk_id|ahk_pid|all|alnum|alpha|altsubmit|alttab|alttabandmenu|alttabmenu|alttabmenudismiss|alwaysontop|and|autosize|background|backgroundtrans|base|belownormal|between|bitand|bitnot|bitor|bitshiftleft|bitshiftright|bitxor|bold|border|bottom|button|buttons|cancel|capacity|caption|center|check|check3|checkbox|checked|checkedgray|choose|choosestring|click|clone|close|color|combobox|contains|controllist|controllisthwnd|count|custom|date|datetime|days|ddl|default|delete|deleteall|delimiter|deref|destroy|digit|disable|disabled|dpiscale|dropdownlist|edit|eject|enable|enabled|error|exit|expand|exstyle|extends|filesystem|first|flash|float|floatfast|focus|font|force|fromcodepage|getaddress|getcapacity|grid|group|groupbox|guiclose|guicontextmenu|guidropfiles|guiescape|guisize|haskey|hdr|hidden|hide|high|hkcc|hkcr|hkcu|hkey_classes_root|hkey_current_config|hkey_current_user|hkey_local_machine|hkey_users|hklm|hku|hotkey|hours|hscroll|hwnd|icon|iconsmall|id|idlast|ignore|imagelist|in|insert|integer|integerfast|interrupt|is|italic|join|label|lastfound|lastfoundexist|left|limit|lines|link|list|listbox|listview|localsameasglobal|lock|logoff|low|lower|lowercase|ltrim|mainwindow|margin|maximize|maximizebox|maxindex|menu|minimize|minimizebox|minmax|minutes|monitorcount|monitorname|monitorprimary|monitorworkarea|monthcal|mouse|mousemove|mousemoveoff|move|multi|na|new|no|noactivate|nodefault|nohide|noicon|nomainwindow|norm|normal|nosort|nosorthdr|nostandard|not|notab|notimers|number|off|ok|on|or|owndialogs|owner|parse|password|pic|picture|pid|pixel|pos|pow|priority|processname|processpath|progress|radio|range|rawread|rawwrite|read|readchar|readdouble|readfloat|readint|readint64|readline|readnum|readonly|readshort|readuchar|readuint|readushort|realtime|redraw|regex|region|reg_binary|reg_dword|reg_dword_big_endian|reg_expand_sz|reg_full_resource_descriptor|reg_link|reg_multi_sz|reg_qword|reg_resource_list|reg_resource_requirements_list|reg_sz|relative|reload|remove|rename|report|resize|restore|retry|rgb|right|rtrim|screen|seconds|section|seek|send|sendandmouse|serial|setcapacity|setlabel|shiftalttab|show|shutdown|single|slider|sortdesc|standard|status|statusbar|statuscd|strike|style|submit|sysmenu|tab|tab2|tabstop|tell|text|theme|this|tile|time|tip|tocodepage|togglecheck|toggleenable|toolwindow|top|topmost|transcolor|transparent|tray|treeview|type|uncheck|underline|unicode|unlock|updown|upper|uppercase|useenv|useerrorlevel|useunsetglobal|useunsetlocal|vis|visfirst|visible|vscroll|waitclose|wantctrla|wantf2|wantreturn|wanttab|wrap|write|writechar|writedouble|writefloat|writeint|writeint64|writeline|writenum|writeshort|writeuchar|writeuint|writeushort|xdigit|xm|xp|xs|yes|ym|yp|ys|__call|__delete|__get|__handle|__new|__set"
, Needle :="
(LTrim Join Comments
ODims)
((?:^|\s);[^\n]+) ; Comments
|(^\s*\/\*.+?\n\s*\*\/) ; Multiline comments
|((?:^|\s)#[^ \t\r\n,]+) ; Directives
|([+*!~&\/\\<>^|=?:
,().```%{}\[\]\-]+) ; Punctuation
|\b(0x[0-9a-fA-F]+|[0-9]+) ; Numbers
|(""[^""\r\n]*"") ; Strings
|\b(A_\w*|" Builtins ")\b ; A_Builtins
|\b(" Flow ")\b ; Flow
|\b(" Commands ")\b ; Commands
|\b(" Functions ")\b ; Functions (builtin)
|\b(" Keynames ")\b ; Keynames
|\b(" Keywords ")\b ; Other keywords
|(([a-zA-Z_$]+)(?=\()) ; Functions
|(^\s*[A-Z()-\s]+\:\N) ; Descriptions
)"
GenHighlighterCache(Settings)
Map := Settings.Cache.ColorMap
Pos := 1
while (FoundPos := RegExMatch(Code, Needle, Match, Pos))
{
RTF .= "\cf" Map.Plain " "
RTF .= EscapeRTF(SubStr(Code, Pos, FoundPos-Pos))
; Flat block of if statements for performance
if (Match.Value(1) != "")
RTF .= "\cf" Map.Comments
else if (Match.Value(2) != "")
RTF .= "\cf" Map.Multiline
else if (Match.Value(3) != "")
RTF .= "\cf" Map.Directives
else if (Match.Value(4) != "")
RTF .= "\cf" Map.Punctuation
else if (Match.Value(5) != "")
RTF .= "\cf" Map.Numbers
else if (Match.Value(6) != "")
RTF .= "\cf" Map.Strings
else if (Match.Value(7) != "")
RTF .= "\cf" Map.A_Builtins
else if (Match.Value(8) != "")
RTF .= "\cf" Map.Flow
else if (Match.Value(9) != "")
RTF .= "\cf" Map.Commands
else if (Match.Value(10) != "")
RTF .= "\cf" Map.Functions
else if (Match.Value(11) != "")
RTF .= "\cf" Map.Keynames
else if (Match.Value(12) != "")
RTF .= "\cf" Map.Keywords
else if (Match.Value(13) != "")
RTF .= "\cf" Map.Functions
else If (Match.Value(14) != "")
RTF .= "\cf" Map.Descriptions
else
RTF .= "\cf" Map.Plain
RTF .= " " EscapeRTF(Match.Value())
Pos := FoundPos + Match.Len()
}
return Settings.Cache.RTFHeader . RTF . "\cf" Map.Plain " " EscapeRTF(SubStr(Code, Pos)) "\`n}"
}
GenHighlighterCache(Settings) {
if Settings.HasKey("Cache")
return
Cache := Settings.Cache := {}
; --- Process Colors ---
Cache.Colors := Settings.Colors.Clone()
; Inherit from the Settings array's base
BaseSettings := Settings
while (BaseSettings := BaseSettings.Base)
for Name, Color in BaseSettings.Colors
if !Cache.Colors.HasKey(Name)
Cache.Colors[Name] := Color
; Include the color of plain text
if !Cache.Colors.HasKey("Plain")
Cache.Colors.Plain := Settings.FGColor
; Create a Name->Index map of the colors
Cache.ColorMap := {}
for Name, Color in Cache.Colors
Cache.ColorMap[Name] := A_Index
; --- Generate the RTF headers ---
RTF := "{\urtf"
; Color Table
RTF .= "{\colortbl;"
for Name, Color in Cache.Colors
{
RTF .= "\red" Color>>16 & 0xFF
RTF .= "\green" Color>>8 & 0xFF
RTF .= "\blue" Color & 0xFF ";"
}
RTF .= "}"
; Font Table
if Settings.Font
{
FontTable .= "{\fonttbl{\f0\fmodern\fcharset0 "
FontTable .= Settings.Font.Typeface
FontTable .= ";}}"
RTF .= "\fs" Settings.Font.Size * 2 ; Font size (half-points)
if Settings.Font.Bold
RTF .= "\b"
}
; Tab size (twips)
RTF .= "\deftab" GetCharWidthTwips(Settings.Font) * Settings.TabSize
Cache.RTFHeader := RTF
}
GetCharWidthTwips(Font) {
static Cache := {}
if Cache.HasKey(Font.Typeface "_" Font.Size "_" Font.Bold)
return Cache[Font.Typeface "_" font.Size "_" Font.Bold]
; Calculate parameters of CreateFont
Height := -Round(Font.Size*A_ScreenDPI/72)
Weight := 400+300*(!!Font.Bold)
Face := Font.Typeface
; Get the width of "x"
hDC := DllCall("GetDC", "UPtr", 0)
hFont := DllCall("CreateFont"
, "Int", Height ; _In_ int nHeight,
, "Int", 0 ; _In_ int nWidth,
, "Int", 0 ; _In_ int nEscapement,
, "Int", 0 ; _In_ int nOrientation,
, "Int", Weight ; _In_ int fnWeight,
, "UInt", 0 ; _In_ DWORD fdwItalic,
, "UInt", 0 ; _In_ DWORD fdwUnderline,
, "UInt", 0 ; _In_ DWORD fdwStrikeOut,
, "UInt", 0 ; _In_ DWORD fdwCharSet, (ANSI_CHARSET)
, "UInt", 0 ; _In_ DWORD fdwOutputPrecision, (OUT_DEFAULT_PRECIS)
, "UInt", 0 ; _In_ DWORD fdwClipPrecision, (CLIP_DEFAULT_PRECIS)
, "UInt", 0 ; _In_ DWORD fdwQuality, (DEFAULT_QUALITY)
, "UInt", 0 ; _In_ DWORD fdwPitchAndFamily, (FF_DONTCARE|DEFAULT_PITCH)
, "Str", Face ; _In_ LPCTSTR lpszFace
, "UPtr")
hObj := DllCall("SelectObject", "UPtr", hDC, "UPtr", hFont, "UPtr")
VarSetCapacity(SIZE, 8, 0)
DllCall("GetTextExtentPoint32", "UPtr", hDC, "Str", "x", "Int", 1, "UPtr", &SIZE)
DllCall("SelectObject", "UPtr", hDC, "UPtr", hObj, "UPtr")
DllCall("DeleteObject", "UPtr", hFont)
DllCall("ReleaseDC", "UPtr", 0, "UPtr", hDC)
; Convert to twpis
Twips := Round(NumGet(SIZE, 0, "UInt")*1440/A_ScreenDPI)
Cache[Font.Typeface "_" Font.Size "_" Font.Bold] := Twips
return Twips
}
EscapeRTF(Code) {
for each, Char in ["\", "{", "}", "`n"]
Code := StrReplace(Code, Char, "\" Char)
return StrReplace(StrReplace(Code, "`t", "\tab "), "`r")
}