forked from fischgeek/AHK-CodeSearch
-
Notifications
You must be signed in to change notification settings - Fork 4
/
CodeSearch.ahk
2077 lines (1679 loc) · 73.1 KB
/
CodeSearch.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
;------------------------------------------------------------------------------------------------------------------------------------------------------
;-------------------------------------------- Code Search - originally from fischgeek --------------------------------------------
;-------------------------------------------- https://github.com/fischgeek/AHK-CodeSearch --------------------------------------------
;-------------------------------------------- modified by Ixiko - look below for version --------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------------------
;
; A little promotion for Autohotkey:
; Autohotkey no longer enjoys my main attention, but I have yet to find anything better for finding program code
; on my computers than Fishgeek's codesearch program. Other programs certainly achieve greater speed, but the
; foundation Fishgeek has laid and the ease with which further code highlighting can be integrated are unique.
; The nicest thing is how few resources an AHK script consumes in contrast to e.g. Python, and just copying the
; entire Codesearch directory is enough to run the code.
;
;------------------------------------------------------------------------------------------------------------------------------------------------------
version:= "2023-08-29"
vnumber:= 1.5
/* VERSION HISTORY
V1.5
- Now you can enter a list of directories in which to search. The script determines the file endings contained in each directory.
This allows you to include or exclude certain directories for the search to speed up the search.
- Empty chars like a 'c' or 'D' without anything else will be interpreted as device letter
- Highlighting for Python language and .ini files added (with hope it will work)
- additional file types can be entered and will included in search
V1.45
- added area for displaying line numbers
- the colours of the rest of the gui have been adapted to the codestyle
- fixed incorrect behaviour when resizing the Treeview and RichCode controls
V1.44
- Search in files and/or file names
- Added an RichCode (/Edit)-Control to show your found code highlighted
- class_RichCode.ahk got additional functions
- Removed the ListView for a TreeView control
- Click on a sub-item in TreeView and it scrolls into view!
- Add a context menu to the TreeView control with the options to Edit, Execute and Open Script Folder.
- The width of TreeView and RichEdit-Control can be adjusted with a mouse drag in the gap between both controls.
- Window position, size and the sizes of TreeView and RichCode control will be stored after closing the Gui.
V1.3
- Gui Resize for ListView control is working
- Showing the last number of files in directory
- Change the code to the coding conventions of AHK_L V 1.1.30.0
- Ready to enter the search string right after the start
- Pressing Enter after entering the search string starts the search immediately
- The buttons R, W, C now show their long names
V1.2
- Stop/Resume Button is added - so the process can be interrupted even to start a new search
- a. from fischgeek Todo - Find an icon - i take yours and it looks great!
V1.1
- the window displays the number of files read so far and the number of digits found during the search process
- Font size and window size is adapted to 4k monitors (Size of Gui is huge - over 3000 pixel width) - at the moment, no resize or
any settings for the size of the contents is possible - i'm sorry for that
Fischgeeks TODO:
- Add ability to double-click open a file to that line number -> I can still do that
- Possibly add an extension manager?
- Add pre-search checks (extension selection, directory)
- Add auto saving of selected options and filters
*/
;{ script defaults ------------------------------------------------------------------------------------------------------------------------------------
#NoEnv
SetBatchLines , -1
CoordMode , Pixel, Screen
CoordMode , Mouse, Screen
CoordMode , Menu, Screen
SetTitleMatchMode , 2
#MaxThreads , 250
#MaxThreadsBuffer , On
#MaxThreadsPerHotkey , 4
#MaxHotkeysPerInterval , 99000000
#HotkeyInterval , 99000000
;#KeyHistory , Off
ListLines, Off
Menu, Tray, Icon, % A_ScriptDir "\CodeSearch.ico"
;}
;{ variables ------------------------------------------------------------------------------------------------------------------------------------------
global hCSGui, hTV, hTP, RC
global config, mFiles, TV, cbxCase, keyword, cbxWholeWord
global txtInitialDirectory, AHKPath, AHKEditor
global lastAdditionalExtensions, lastDirs
global hCursor1 := DllCall("LoadCursor", "Ptr", 0, "Ptr", 32644, "Ptr")
global hCursor2 := DllCall("LoadCursor", "Ptr", 0, "Ptr", 32512, "Ptr")
global SearchBuffer := Object()
global q := Chr(0x22)
global dbg := false
global ftypes := [{ "ext":"Ahk"
, "fExt":".ahk,.ah2"
, "checked":0}
, { "ext":"Html"
, "fExt":".html"
, "checked":0}
, { "ext":"Css"
, "fExt":".css"
, "checked":0}
, { "ext":"Js"
, "fExt":".js"
, "checked":0}
, { "ext":"Py"
, "fExt":".py,.pyw,.pyi,.pyx,.pyp"
, "checked":0}
, { "ext":"Ini"
, "fExt":".ini"
, "checked":0}
, { "ext":"Text"
, "fExt":".txt,.log,.cfg,.conf,.xml,.json,.csv,.md,.bat,.cmd,.yaml,.yml,.toml"
, "gopt":" HWNDhCBText gWarnFType "
, "checked":0}]
; get default Autohotkey files editor
RegRead, EditWith, HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command
RegExMatch(EditWith, "[A-Z]\:[A-Za-z\pL\s\-_.\\\(\)]+", path)
SplitPath, A_AhkPath,, AHKPath
AHKEditor := path
config := new Config()
;maybe later for Resizefeature
baserate := 1.8 ;(4k)
WinSizeBase := 3000
GroupBoxBaseW := 500
GroupBoxBaseH := 120
StaticTextBase := 400
MarginX := 10
MarginY := 10
StopIT := 0
icount := 0
maxCount := 0
;Column width's
wFile := 500
wLineText := 495
wLine := 100
wPosition := 100
; load last window position and size
gP := GetSavedGuiPos(MarginX, MarginY)
TVw := config.getValue("TV_Width", "Settings", 800)
TVw := TVw < 600 ? 600 : TVw
TPw := isObject(gP) ? gP.W-TVw-5-(2*MarginX) : 600
; for gui resize:
wF1 := TVw/gP.W
wF2 := 1-wF1
; load extensions settings
If !(txtAdditionalExtensions := lastAdditionalExtensions := config.getValue("additionalExtensions", "Settings"))
txtAdditionalExtensions := lastAdditionalExtensions := ""
for each, ftype in ftypes {
ftype.checked := config.getValue(ftype.ext "_checked", "Settings", (ftype.ext = "Ahk" ? 1 : 0))
ftypeExtensions .= (ftypeExtensions ? ",":"") ftype.fExt
}
; load last used search directories
lastdirs := GetLastDirs()
SciTEOutput(cJSON.Dump(lastDirs, 1))
; richedit settings
Settings :=
( LTrim Join Comments
{
"TabSize" : 4,
"Indent" : "`t",
"FGColor" : 0xEDEDCD,
"BGColor" : 0x3F3F3F,
"GuiBGColor1" : "555453",
"GuiBGColor2" : "B8B7B6",
"Font" : {"Typeface": "Futura Bk Bt", "Size": 9},
"WordWrap" : false,
"Gutter": {
;"Width" : 40,
"FGColor" : 0x9FAFAF,
"BGColor" : 0x262626
},
"UseHighlighter" : True,
"Highlighter" : "HighlightAHK",
"HighlightDelay" : 200,
"Colors": {
"Comments" : 0x9FBF9F,
"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
}
}
)
Settings2 :=
( LTrim Join Comments
{
"TabSize" : 4,
"Indent" : "`t",
"FGColor" : 0xEDEDCD,
"BGColor" : 0x3F3F3F,
"GuiBGColor1" : "555453",
"GuiBGColor2" : "B8B7B6",
"Font" : {"Typeface": "Futura Bk Bt", "Size": 9},
"WordWrap" : false,
"Gutter": {
"Width" : 40,
"FGColor" : 0x9FAFAF,
"BGColor" : 0x262626
},
"UseHighlighter" : True,
"Highlighter" : "HighlightAHK",
"HighlightDelay" : 200,
"Colors": {
"Comments" : 0x9FBF9F,
"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
}
}
)
Settings3 :=
( LTrim Join Comments
{
; When True, this setting may conflict with other instances of CQT
"GlobalRun" : False,
; Script options
"AhkPath" : A_AhkPath,
"Params" : "",
; Editor (colors are 0xBBGGRR)
"FGColor" : 0xEDEDCD,
"BGColor" : 0x3F3F3F,
"GuiBGColor1" : "555453",
"GuiBGColor2" : "D8D7D6",
"TabSize" : 4,
"Font" : {
"Typeface" : "Consolas",
"Size" : 11,
"Bold" : False
},
"Gutter" : {
"Width" : 75,
"FGColor" : 0x9FAFAF,
"BGColor" : 0x262626
},
; Highlighter (colors are 0xRRGGBB)
"UseHighlighter": True,
"Highlighter": "HighlightAHK",
"HighlightDelay": 200, ; Delay until the user is finished typing
"Colors": {
"Comments": 0x7F9F7F,
"Functions": 0x7CC8CF,
"Keywords": 0xE4EDED,
"Multiline": 0x7F9F7F,
"Numbers": 0xF79B57,
"Punctuation": 0x97C0EB,
"Strings": 0xCC9893,
"A_Builtins": 0xF79B57,
"Commands": 0xCDBFA3,
"Directives": 0x7CC8CF,
"Flow": 0xE4EDED,
"KeyNames": 0xCB8DD9
},
; Auto-Indenter
"Indent": "`t",
; Pastebin
"DefaultName": A_UserName,
"DefaultDesc": "Pasted with CodeQuickTester",
; AutoComplete
"UseAutoComplete": True,
"ACListRebuildDelay": 500 ; Delay until the user is finished typing
}
)
;}
;{ the Gui --------------------------------------------------------------------------------------------------------------------------------------------
bgt := " Backgroundtrans "
; context menu
funcEdit := Func("ContextMenu").Bind("Edit")
funcRun := Func("ContextMenu").Bind("Run")
funcExpl := Func("ContextMenu").Bind("Explorer")
SearchIn := ["Search in files and names", "Search only in files", "Search only filenames"]
InNum := 1
Menu, CM, Add, Open in your code editor , % funcEdit
Menu, CM, Add, Run code , % funcRun
Menu, CM, Add, open directory in explorer , % funcExpl
;gui begin
Gui, Color, % "c" StrReplace(Settings.GuiBGColor1, "0x"), % "c" StrReplace(Settings.GuiBGColor2, "0x")
Gui, -DPIScale +Resize +LastFound +MinSize1920x800 HwndhCSGui 0x91CF0000 ; +LastFound and all controls will be shown at start without any problems
Gui, Margin , % MarginX , % MarginY
; directories
Gui, Font, s9 q5 cWhite Bold , Segoe UI Light
Gui, Add, GroupBox , % "xm ym w580 h145 Center vGBSearchPaths hwndhGBSearchPaths" , % "Directories"
Gui, Font, cBlack Normal
Gui, Add, Edit , % "xp+5 yp+30 w450 h30 r1 Section -Wrap vtxtInitialDirectory gIDirectory hwndhtxtInitDir" , % "" ;txtInitialDirectory
Gui, Add, Button , % "x+5 h30 gbtnDirectoryBrowse_Click vbtnDirectoryBrowse " , % "+"
GuiControlGet, o, Pos, txtInitialDirectory
p := GetWIndowSpot(hGBSearchPaths)
Gui, Font, s8 cBlack Normal
Gui, Add, ListView , % "x" oX " y" oy+oH+3 " w" oW+40 " h" p.CH-6 " -Hdr Grid Checked vLVSearchDirs gIDirectory hwndhLVSearchDirs", % "Path|Files"
o := GetWindowSpot(hLVSearchDirs)
Gui, ListView, LVSearchDirs
LV_ModifyCol(1, Floor(o.CW*0.70))
LV_ModifyCol(2, Floor(o.CW*0.30))
LV_ModifyCol(3, 0)
o := GetWindowSpot(hLVSearchDirs)
GuiControl, Move, GBSearchPaths, % "h" (o.Y+o.H-p.Y+5) " w" (o.X+o.W-p.X+5)
ShowLastDirs()
;search field
x := o.X+o.W+10
Gui, Font, s9 q5 cWhite Bold , Segoe UI Light
Gui, Add, GroupBox , % "x" x " ym w500 h145 Center vGBFileSearch hwndhGBFileSearch", % "String to search for"
p := GetWIndowSpot(hGBFileSearch)
Gui, Font, cBlack Normal
opts := "HWNDhsearch vtxtSearchString gbtnSearch_Check"
Gui, Add, Edit , % "x" x+5 " yp+30 Section w420 " opts , % ""
o := GetWIndowSpot(hSearch)
Gui, Add, Button , % "x+5 ys h" o.H-2 " vbtnSearch gbtnSearch_Click" , % "Search"
Gui, Add, Checkbox , % "x" x+10 " y+10 Section checked h30 0x1000 vcbxRecurse" , % "RECURSE"
Gui, Add, Checkbox , % "x+3 hp 0x1000 vcbxWholeWord" , % "WHOLE WORD"
Gui, Add, Checkbox , % "x+3 hp 0x1000 vcbxCase" , % "CASESENSITIVE"
Gui, Add, Checkbox , % "x" x+10 " y+5 hp 0x1000 vcbxSearchWhat gcbxClick " , % SearchIn[InNum]
Gui, Add, Button , % "x+3 w200 hp 0x1000 Center vSearchStop gbtnSearchStop" , % "STOP SEARCHING"
;filetypes
Gui, Font, s9 cWhite Bold
x := p.X+p.W+10
Gui, Add, GroupBox , % "x" x " ym w580 h145 Center vGBFileTypes hwndhGBFileTypes" , % "File Types"
for ftypeNr, ftype in ftypes {
ftypepos := (ftypeNr=1 ? "yp+30 xp+15 Section hwndhftypes":"ys") " gbtnSearch_check "
Gui, Add, Checkbox, % ftypepos " vcbx" fType.ext " " (ftype.checked ? "checked":"") " " fType.gopt , % RegExReplace(ftype.ext, "\.")
}
GuiControlGet, p, Pos, cbxAhk
Gui, Add, Button , % "xs y+5 h" pH-10 " vbtnCheckAll gbtn_Click" , % "check/uncheck all"
Gui, Add, Text , xs y+5 , % "Additional extension (ex. xml,cs,aspx,rb)"
Gui, Font, cBlack Normal
Gui, Add, Edit , xs y+2 w550 vtxtAdditionalExtensions HWNDhaddExt , % txtAdditionalExtensions
o := GetWindowSpot(haddExt)
p := GetWindowSpot(hGBFileTypes)
GuiCOntrol, Move, GBFileTypes , % "h" (o.Y+o.H-p.Y+10) " w" (o.X+o.W-p.X+10)
GuiCOntrol, Move, GBFileSearch, % "h" (o.Y+o.H-p.Y+10)
;statics
Gui, Font, s9 cWhite, Segoe UI Light
GuiControlGet, p, Pos, GBFileTypes
x := pX+pW+10
colLeftW := 250
Gui, Add, GroupBox, % "x" x " ym w" colLeftW+280 " h" (o.Y+o.H-p.Y+10) " Center" , % "Statistics"
Gui, Font, s9 Normal, Consolas
Gui, Add, Text, % "yp+35 xp+15 w" colLeftW " Right Section " bgt , % "File counter:"
Gui, Font, s9 Bold
Gui, Add, Text, % "ys+0 w200 vStatCount " bgt , % SubStr("000000" icount, -3) . (StrLen(thisDirLastMaxCount) > 0 ? "/" SubStr("00000" thisDirLastMaxCount, -3) : "")
Gui, Font, s9 Normal, Consolas
Gui, Add, Text, % "xs y+5 w" colLeftW " Right Section " bgt , % "Path:"
Gui, Font, s8 Bold
Gui, Add, Text, % "ys+0 w300 vStatPath " bgt , % ""
Gui, Font, s9 Normal, Consolas
Gui, Add, Text, % "xs y+5 w" colLeftW " Right Section " bgt , % "Path counter:"
Gui, Font, s8 Bold
Gui, Add, Text, % "ys+0 w200 vStatPathCount " bgt , % ""
Gui, Font, s9 Normal
Gui, Add, Text, % "xs y+5 w" colLeftW " Right Section vTFiles " bgt , % "Files with search string:"
Gui, Font, Bold
Gui, Add, Text, % "ys+0 w200 vStatFiles " bgt , % ifiles
Gui, Font, s9 Normal
Gui, Add, Text, % "xs y+5 w" colLeftW " Right Section vTString " bgt , % "Searchstring found:"
Gui, Font, Bold
Gui, Add, Text, % "ys+0 w200 vStatFound " bgt , % isub
Gui, Font, s9 Normal
Gui, Add, Picture, x+180 ym w150 h140 gCSReload vCSReload hwndCShReload , % A_ScriptDir "\assets\4293840.png" ;w135 h130
Gui, Add, Picture, xp yp w150 h140 vCSReload1 hwndCShReload1 , % A_ScriptDir "\assets\4293840.png" ;w135 h130
Gui, Font, Bold
Gui, Add, Text, xp-120 yp+130 w400 Center BackgroundTrans , % "a script by Fishgeek"
Gui, Add, Text, yp+25 w400 Center BackgroundTrans , % "modified by Ixiko V" vnumber " (" version ")"
;debug
GuiControlGet, p, Pos, CSReload
Gui, Font, s8 q5 cBlack, Segoe UI Light
Gui, Add, Text, % "x" px+pW+30 " y20 w800 h120 Wrap vDebug1"
Gui, Add, Text, % "x" px+pW+840 " y20 w800 h120 Wrap vDebug2"
;treeview
;~ p := GetWIndowSpot(hGBSearchPaths)
GuiControlGet, p, Pos, GBSearchPaths
h := gP.H-pY-pH-10-MarginY
Gui, Font, s9 q5, Consolas
Gui, Add, Treeview, % "xm y" pY+pH+5 " w" TVw " h" h " AltSubmit gResultsTV vtvResults HWNDhTV Section"
;richcode
GuiControlGet, p, Pos, tvResults
RCPos := "x" pX+pW+5 " y" pY " w" TPw-10 " h" pH " "
RC := new RichCode(Settings3, RCPos, 1)
hTP := RC.hwnd
hGtr := RC.gutter.hwnd
DocObj := RC.GetTomObject("IID_ITextDocument")
;~ RC.AddMargins(5, 5, 5, 5)
RC.ShowScrollBar(0, False)
GuiControl, Disable , SearchStop
GuiControl, Disable , btnSearch
GuiControl, , txtInitialDirectory, % ""
GuiControl, Focus , txtSearchString
If (gP.X < -20) {
Gui, Show, , Code Search
Gui, Maximize
}
else {
Gui, Show, % "x" gP.X " y" gP.Y " w" gP.W " h" gP.H , Code Search
}
If gP.M
Gui, Maximize
;hope this will fix the empty gui effect
wp := GetWindowSpot(hCSGui)
SetWindowPos(hCSGui, wp.X, wp.Y, wp.W+2 , wp.H+2, 0, 0x40)
SetWindowPos(hCSGui, wp.X, wp.Y, wp.W , wp.H , 0, 0x40)
hTP := GetHex(hTP), hTV := GetHex(hTV)
OnMessage(0x200 , "OnWM_MOUSEMOVE")
OnMessage(0x020 , "OnWM_SETCURSOR")
GuiControlGet , TV, Pos, tvResults
SearchIsFocused:= Func("ControlIsFocused").Bind("Edit2")
Hotkey, If , % SearchIsFocused
Hotkey, ~Enter , btnSearch_Click
Hotkey, If
return
GuiSize: ;{
if (A_EventInfo = 1)
return
GuiSizePre:
GuiControl, -Redraw, % "tvResults"
GuiControl, -Redraw, % RC.gutter.hwnd
GuiControl, -Redraw, % RC.hwnd
wNew := A_GuiWidth , hNew := A_GuiHeight
TVw := Floor(wNew*wF1) , PrW := Floor(wNew*wF2)- RC.gutter.W - 1
Critical Off
Critical
GuiControl, Move, tvResults , % " h" hNew - TVy - 5 "w" TVw - 5
GuiControl, Move, % RC.gutter.hwnd , % " h" hNew - TVy - 5 "x" TVw + 1
GuiControl, Move, % RC.hwnd , % " h" hNew - TVy - 5 "x" TVw + RC.gutter.W + 1 " w" PrW
Critical Off
GuiControl, +Redraw, % "tvResults"
GuiControl, +Redraw, % RC.gutter.hwnd
GuiControl, +Redraw, % RC.hwnd
RedrawWindow(hCSGui)
return ;}
cbxClick: ;{
InNum := InNum+1 >3 ? 1 : InNum+1
GuiControl, Text , cbxSearchWhat, % SearchIn[InNum]
GuiControl, , cbxSearchWhat, 0
return ;}
TOff:
ToolTip,,,, 14
return
;}
;{ gui dialogs ----------------------------------------------------------------------------------------------------------------------------------------
btnDirectoryBrowse_Click: ;{
Gui, Submit, NoHide
Gui, ListView, LVSearchDirs
startingPathFound := false
if LV_GetCount()
Loop % LV_GetCount() {
LV_GetText(startingPath, LV_GetCount()-A_Index+1, 1)
if Instr(FileExist(startingPath), "D") {
startingPathFound := true
break
}
}
if startingPathFound {
SplitPath, startingPath,,,,, OutDrive
}
else
OutDrive := "C:"
If !IsObject(targetDir := SelectFolderEx(OutDrive "\", "Select a folder", hCSGui, "", "", 1)) {
MsgBox, 0x1000, % ScriptName, % " You have nothing selected."
return
}
targetDir := targetDir.SelectedDir
SciTEOutput("targetDir: " targetDir)
pathmatched := false
For searchPath, data in lastDirs {
if (searchPath = targetDir) {
MsgBox, 0x1000, % ScriptName , % "This path already exists!"
return
}
else if (Strlen(targetDir) < Strlen(searchPath)) && (targetDir ~= "i)^" searchPath) {
MsgBox, 4659, % ScriptName, % targetDir " is the parent path of " searchPath ".`n"
. "If you search the current directory recursively,`n"
. "the last named directory would be included. `n"
. "You can now discard (NO) the directory that was included anyway,`n"
. " keep it (YES) or cancel the process here."
IfMsgBox, Cancel
return
IfMsgBox, No
lastDirs.Remove(searchpath)
}
else if (Strlen(targetDir) > Strlen(searchPath)) && (searchPath ~= "i)^" targetDir) {
MsgBox, 4659, % ScriptName, % searchPath " is the parent path of " targetDir ".`n"
. "If you search the current directory recursively,`n"
. "the last named directory would be included. `n"
. "You can now discard (NO) the directory that was included anyway,`n"
. " keep it (YES) or cancel the process here."
IfMsgBox, Cancel
return
IfMsgBox, No
return
}
}
if !IsObject(lastDirs)
lastDirs := Object()
lastDirs[targetDir] := {"fTypes":{}, "active":1, "MaxCount":0}
SaveLastDirs()
GuiControl, Disable, SearchStop
ShowLastDirs()
return ;}
btn_Click: ;{
if (A_GuiControl = "btnCheckAll") {
check := (GetCheckedFileTypes() < ftypes.Count()//2) ? true : false
for each, ftype in ftypes
GuiControl,, % "cbx" ftype, % check
}
return ;}
btnSearchStop: ;{
If (StopIT = 0) {
StopIT := 1
WinSetTitle, % "ahk_id " hCSGui,, % "Code Search - searching ist stopped"
GuiControl,, SearchStop, % "RESUME SEARCHING"
DisEnable("Enable")
}
else if (StopIT = 1) {
StopIT := 0
WinSetTitle, % "ahk_id " hCSGui ,, Code Search - I am searching
GuiControl,, SearchStop, % "STOP SEARCHING"
DisEnable("Disable")
}
return ;}
btnSearch_Check: ;{ ; enables/disables the searchbutton
Gui, Submit, NoHide
ftypesChecked := GetCheckedFileTypes()
addExtensions := getAdditionalExtensions()
searchPaths := GetSearchPaths()
if (txtSearchString && (ftypeChecked || addExtensions) && searchPaths.Count())
GuiControl, Enable, btnSearch
else
GuiControl, Disable, btnSearch
return ;}
btnSearch_Click: ;{
global TV := Array()
global mFiles := Object()
global TVIndex1 := TVIndex2:= StopIT:= icount := ifiles := isub := StopIT := 0
PreviewFile_old := ""
Ballon_Tip := 0
Gui, Submit, NoHide
ftypesChecked := GetCheckedFileTypes()
addExtensions := getAdditionalExtensions()
allExtensions := StrReplace(ftypeExtensions (addExtensions ? "," addExtensions: ""), ",.", ",")
searchPaths := GetSearchPaths()
SciTEOutput("AllExtensions: " allExtensions)
if !searchPaths.Count() {
Ballon_Tip |= 1
Edit_BalloonTip(htxtInitDir, "Leave directory strings here!", "Every search needs a starting point.", true)
GuiControl, Focus, txtInitialDirectory
}
If (!ftypesChecked && !addExtensions) {
Edit_BalloonTip(hftypes, "File type!", "Please check a file type..." , true)
Edit_BalloonTip(haddExt, "File type!", "Leave some extensions here!", true)
Ballon_Tip |= 2
}
if (Ballon_tip > 0) {
GuiControl, Disable, BtnSearch
SetTimer, Ballon_Tip_off, -5000
return
}
; the search begins
TV_Delete()
WinSetTitle, % "ahk_id " hCSGui ,, Code Search - I am searching
GuiControl, , StatFiles , 0
GuiControl, , StatFound , 0
GuiControl, , SearchStop, % "STOP SEARCHING"
GuiControl, Enable , SearchStop
DisEnable("Disable")
extensions := getExtensions() (addExtensions ? "," addExtensions : "")
keyword := txtSearchString
If (last_txtSearchString != txtSearchString || last_extensions <> extensions) {
last_txtSearchString := txtSearchString
last_extensions := extensions
SearchBuffer := Object()
fullindexed := false
;config.setValue(txtInitialDirectory, "LastDir")
}
; search path after path
icount := scount := 0
allDirs := GetLastFilesCount()
fpathtypes := Object()
for each, searchpath in searchPaths {
SetWorkingDir, % searchpath
GuiControl,, StatPath, % searchpath
scount := 0
if allDirs.MaxCount
SetStatCount(0, allDirs.MaxCount, 0, allDirs.spath[searchPath].MaxCount)
fpathtypes[searchpath] := Object()
if (!SearchBuffer.Count() || !fullindexed)
gosub FilesSearch
else
gosub Buffersearch
SciTEOutput(cJSON.Dump(fpathtypes,1))
for fext, fextCount in fpathtypes[searchpath] {
if !IsObject(lastDirs[searchpath])
lastDirs[searchpath] := Object()
if !IsObject(lastDirs[searchpath].fTypes)
lastDirs[searchpath].fTypes := Object()
lastDirs[searchpath].fTypes[fext] += fextCount
}
}
fullindexed := true
SetStatCount(icount, allDirs.MaxCount, scount, allDirs.sPaths[searchPath].MaxCount)
; count all
lastDirs.MaxCount := 0
for each, searchpath in lastDirs {
searchpath.MaxCount := 0
for fExt, fextCount in searchpath.fTypes {
searchpath.MaxCount += fextCount
lastDirs.MaxCount += fextCount
}
}
; save paths
SaveLastDirs()
ShowLastDirs()
WinSetTitle, % "ahk_id " hCSGui,, Code Search - ready with searching
GuiControl, , SearchStop , % "STOP SEARCHING"
GuiControl, Disable , SearchStop
DisEnable("Enable")
return
Ballon_Tip_Off: ;{
if Ballon_Tip & 1 {
Edit_BalloonTip(hftypes, "File type!", "Please check a file type!" , false)
Edit_BalloonTip(haddExt, "File type!", "or leave some extensions here!" , false)
}
if (Ballon_Tip & 2 || Ballon_Tip & 4)
Edit_BalloonTip(htxtInitDir, "Leave directory strings here!", "Every search needs a starting point.", false)
if Ballon_Tip & 8
Edit_BalloonTip(hCBText, "Warning!", "Setting this checkbox leads to the examination of all possible text file sources (" fTypes.Text.fext "). "
. "This can take a very long time and use up considerable RAM.", false)
Ballon_Tip := 0
return ;}
;}
FilesSearch: ;{
fullindexed := false
Loop, Files, % searchpath "\*.*", % (cbxRecurse ? "R":"")
{
While (StopIT = 1)
loop 30
sleep 10
if A_LoopFileAttrib contains H,S,R
continue
if A_LoopFileExt in %allExtensions%
fpathtypes[searchpath][A_LoopFileExt] := !fpathtypes[searchpath][A_LoopFileExt] ? 1 : fpathtypes[searchpath][A_LoopFileExt]+1
if A_LoopFileExt not in %extensions%
continue
icount ++
scount ++
SetStatCount(icount, allDirs.MaxCount, scount, allDirs.sPaths[searchpath].MaxCount)
filePath := A_LoopFileFullPath
fileName := A_LoopFileName
try
txt := FileOpen(filepath, "r").Read()
catch
continue
SearchBuffer.Push({"path":filePath, "txt":txt})
FindAndShow(txt, filepath)
}
GuiControl,, StatFound, % isub
return ;}
BufferSearch: ;{
;~ Sciteoutput(SearchBuffer.Count() "`n" SearchBuffer[1].txt)
modDiv := StrLen(SearchBuffer.Count()) < 3 ? 1 : 100
For buffIndex, file in SearchBuffer {
While (StopIT = 1)
loop 30
sleep 10
FindAndShow(file.txt, file.path)
If (Round(Mod(buffIndex, modDiv)) = 0)
SetStatCount(buffIndex, SearchBuffer.Count(), 0, 0)
}
SetStatCount(buffIndex, SearchBuffer.Count(), 0, 0)
icount := buffIndex
return ;}
FindAndShow(txt, filepath) { ; search txt, filenames and show matches in TreeView
global ; cbxCase, keyword,cbxWholeWord
; Filename matching
; only search in filenames all things continues here, InNum holds the search mode: [1] is search in files and filenames, [2] only in files , [3] only in filenames
If (InNum ~= "^(1|3)$") {
RegExMatch(filename, getRegExOptions(cbxCase) getExpression(keyword, cbxWholeWord), obj)
If (obj.Len() > 0)
If !mFiles.HasKey(filepath) {
SplitPath, filepath, outFileName, OutDir
TVIndex1 ++
TV[TVIndex1] := Array()
TV[TVIndex1] := TV_Add(outFileName " [" OutDir "]" )
mFiles[filepath] := Object()
mFiles[filepath].Push({"line":lineNr, "linepos":obj.Pos(), "TVIndex1":TVIndex1})
}
; search only in filenames continues here
If (InNum = 3)
return
}
; search in file text
For lineNr, lineText in StrSplit(txt, "`n", "`r") {
RegExMatch(lineText, getRegExOptions(cbxCase) getExpression(keyword, cbxWholeWord), obj)
if (obj.Len() > 0) {
; file is always listed
If mFiles.HasKey(filepath) {
idx1 := mFiles[filepath][1].TVIndex1
idx2 := mFiles[filepath].MaxIndex() + 1
TV[idx1][idx2] := TV_Add("[l:" Substr("0000" lineNr, -4) " p:" SubStr("000" obj.pos(), -2) "] " truncate(lineText, 120), TV[idx1])
mFiles[filepath].Push({"line":lineNr, "linepos":obj.Pos()})
}
else {
SplitPath, filepath, outFileName, OutDir
TVIndex1 ++
TV[TVIndex1] := Array()
TV[TVIndex1] := TV_Add(outFileName " [" OutDir "]" )
TV[TVIndex1][1] := TV_Add("[l:" Substr("0000" lineNr, -4) " p:" SubStr("000" obj.pos(), -2) "] " truncate(lineText, 120), TV[TVIndex1])
mFiles[filepath] := Object()
mFiles[filepath].Push({"line":lineNr, "linepos":obj.Pos(), "TVIndex1":TVIndex1})
}
If (filePath <> filePath_old) {
ifiles ++
GuiControl,, StatFiles, % ifiles
filePath_old := filePath
}
isub++
If Mod(isub, 30) = 0
GuiControl,, StatFound, % isub
}
}
}
ResultsTV: ;{
Gui, Submit, NoHide
CrtLine1 := RC.GetCaretLine()
global EventInfo:= A_EventInfo
If RegExMatch(A_GuiEvent, "i)(Normal|S)$") && (A_EventInfo <> 0) {
TVText := TV_GetInfo(EventInfo)
RegExMatch(TVText.parent, "(.*)\s+\[(.*)\]", match)
PreviewFile := match2 "\" match1
If (PreviewFile != PreviewFile_old) {
RC.Settings.Highlighter := GetHighlighter(PreviewFile)
RC.Value := FileOpen(PreviewFile, "r").Read()
RC.UpdateGutter()
CurrentSel := RC.GetSel() ; get the current selection
CF2 := RC.GetCharFormat()
CF2.Mask := 0x40000001 ; set Mask (CFM_COLOR = 0x40000000, CFM_BOLD = 0x00000001)
CF2.Effects := 0x01 ; set Effects to bold (CFE_BOLD = 0x00000001)
CF2.TextColor := 0x006666
CF2.BackColor := 0xFFFF00
RC.SetFont({BkColor:"YELLOW", Color:"BLACK"})
;RC.SetSel(0,0)
;RC.SetScrollPos(0,CaretLine-1)
;RC.SetScrollPos(LineX+0,LineY+0)
;RC.FindText(txtSearchString, ["Down"])
;RC.SetScrollPos(0,0)
PreviewFile_old := PreviewFile
}
upOrWhat := 0
RegExMatch(TVText.child, "\[l\:(?<Y>\d+)\s+p\:(?<X>\d+)\]\s+(?<Text>.*)$", Line)
If !RC.FindText(lineText, ["Down"]) ; search down
RC.FindText(lineText), upOrWhat := 1 ; search up
RC.ScrollCaret()
RC.ScrollLines(upOrWhat ? "-40": "40")
RC.ScrollCaret()
RC.SyncGutter()
;DocObj.
CrtLine2 := RC.GetCaretLine()
If dbg
GuiControl,, Debug1, % "CaretLine1: " CrtLine1 "`nCaretLine2: " CrtLine2 "`nLine: x" LineX+0 " y" LineY+0 "`nScrollPos x" ScrollPos.X " y" ScrollPos.Y
}
else if InStr(A_GuiEvent, "RightClick") && (A_EventInfo <> 0) {
MouseGetPos, mx, my, mWin, mCtrl, 2
Menu, CM, Show, % mx - 20, % my + 10
}
return ;}
IDirectory: ;{
Gui, Submit, NoHide