-
Notifications
You must be signed in to change notification settings - Fork 1
/
ahk_explorer.ahk
3627 lines (3281 loc) · 122 KB
/
ahk_explorer.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
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance, force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetBatchLines, -1
#KeyHistory 0
ListLines Off
SetWinDelay, -1
SetControlDelay, -1
#MaxThreads, 20
#MaxThreadsPerHotkey, 4
SetTitleMatchMode, 2
currentDirSearch=
;%appdata%\ahk_explorer_settings
FileRead, favoriteFolders, %A_AppData%\ahk_explorer_settings\favoriteFolders.txt
favoriteFolders:=StrSplit(favoriteFolders,"`n","`r")
loadSettings()
;gsettings
FOLDERID_Downloads := "{374DE290-123F-4565-9164-39C4925E467B}"
RegRead, v, HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders, % FOLDERID_Downloads
VarSetCapacity(downloads, (261 + !A_IsUnicode) << !!A_IsUnicode)
DllCall("ExpandEnvironmentStrings", Str, v, Str, downloads, UInt, 260)
EcurrentDir1:=downloads
; EcurrentDir1:="C:\Users\Public\AHK\notes\tests"
; EcurrentDir1:="C:\Users\Public\AHK\notes\tests\File Watcher"
; EcurrentDir2:="C:\Users\Public\AHK"
; EcurrentDir1:="C:\Users\Public\AHK\notes\tests\New Folder"
EcurrentDir2:="C:\Users\Public\AHK\notes\tests\New Folder 3"
whichSide:=1
lastDir1:="C:"
for n, param in A_Args ; For each parameter:
{
fileExist:=fileExist(param)
if (fileExist) {
if (InStr(fileExist, "D")) {
EcurrentDir%whichSide%:=param
} else {
SplitPath, param, OutFileName, OutDir
EcurrentDir%whichSide%:=OutDir
toFocus:=OutFileName
;select file
}
}
else {
p("the folder or file you are trying to open doesn't exist`nyou were trying to open:`n" param)
}
break
}
;vars
watching1:=["control"]
watching2:=["control"]
maxRows:=50
lastInputSearchCurrentDir:=false
dirHistory1:=[]
dirHistory2:=[]
undoHistory1:=[]
undoHistory2:=[]
global DROPEFFECT_NONE := 0
global DROPEFFECT_COPY := 1
global DROPEFFECT_MOVE := 2
global DROPEFFECT_LINK := 4
calculatefileSizes:=1
calculateDates:=1
doIcons:=1
global dropEffectFormat := DllCall("RegisterClipboardFormat", "Str", CFSTR_PREFERREDDROPEFFECT := "Preferred DropEffect", "UInt")
Gui, main:New, +hwndthisHwnd
thisUniqueWintitle:="ahk_id " thisHwnd
Gui, main:Default
Gui,Font, s10, Segoe UI
Gui, +LastFound
hw_gui := WinExist()
Gui, Margin, 0, 0
folderListViewWidth:=250
favoritesListViewWidth:=140
listViewWidth:=500
favoritesLenght:=favoriteFolders.Length()
Gui, Add, Button, w%favoritesListViewWidth% ggsettings y212,settings
Gui, Add, ListView, r%favoritesLenght% w%favoritesListViewWidth% x0 y+0 nosort vfavoritesListView ggfavoritesListView AltSubmit ,Favorites
Gui, Add, ListView, r10 w%folderListViewWidth% y0 x+0 vfolderListView1_1 gfolderlistViewEvents1_1 AltSubmit ,Name
Gui, Add, ListView, r10 w%folderListViewWidth% x+0 y0 vfolderlistView2_1 gfolderlistViewEvents2_1 AltSubmit ,Name
Gui, Add, Edit, hwndEdithwnd1 r1 w%listViewWidth% y+0 x+-500 vvcurrentDirEdit1 gcurrentDirEdit1Changed, %EcurrentDir1%
Gui, Add, ListView, NoSort HwndListviewHwnd1 Count5000 r25 -WantF2 w%listViewWidth% -ReadOnly vvlistView1 glistViewEvents1 AltSubmit ,type|Name|Date|sortableDate|Size|sortableSize
Gui, Add, ListView, r10 w%folderListViewWidth% y0 x+0 vfolderListView1_2 gfolderlistViewEvents1_2 AltSubmit ,Name
Gui, Add, ListView, r10 w%folderListViewWidth% x+0 y0 vfolderlistView2_2 gfolderlistViewEvents2_2 AltSubmit ,Name
Gui, Add, Edit, hwndEdithwnd2 r1 w%listViewWidth% y+0 x+-500 vvcurrentDirEdit2 gcurrentDirEdit2Changed, %EcurrentDir2%
Gui, Add, ListView, NoSort HwndListviewHwnd2 Count5000 r25 -WantF2 w%listViewWidth% -ReadOnly vvlistView2 glistViewEvents2 AltSubmit ,type|Name|Date|sortableDate|Size|sortableSize
OnMessage(0x4A, "WM_COPYDATA_READ")
OnMessage(0x111, "HandleMessage" )
initIconStuff()
Gui, Show,,ahk_explorer
Gui, ListView, favoritesListView
favoriteFoldersNames:=[]
for k, v in favoriteFolders {
SplitPath, v, OutFileName
favoriteFoldersNames.Push(OutFileName)
LV_Add(, OutFileName)
}
renderCurrentDir()
IServiceProvider := ComObjCreate("{C2F03A33-21F5-47FA-B4BB-156362A2F239}", "{6D5140C1-7436-11CE-8034-00AA006009FA}")
IVirtualDesktopManagerInternal := ComObjQuery(IServiceProvider, "{C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B}", "{F31574D6-B682-4CDC-BD56-1827860ABEC6}")
MoveViewToDesktop := vtable(IVirtualDesktopManagerInternal, 4) ; void MoveViewToDesktop(object pView, IVirtualDesktop desktop);
GetCurrentDesktop := vtable(IVirtualDesktopManagerInternal, 6) ; IVirtualDesktop GetCurrentDesktop();
ImmersiveShell := ComObjCreate("{C2F03A33-21F5-47FA-B4BB-156362A2F239}", "{00000000-0000-0000-C000-000000000046}")
if !(IApplicationViewCollection := ComObjQuery(ImmersiveShell,"{1841C6D7-4F9D-42C0-AF41-8747538F10E5}","{1841C6D7-4F9D-42C0-AF41-8747538F10E5}" ) ) ; 1607-1809
{
MsgBox IApplicationViewCollection interface not supported.
}
GetViewForHwnd := vtable(IApplicationViewCollection, 6) ; (IntPtr hwnd, out IApplicationView view);
return
; f3::
Process, Close, %PID_getFolderSizes%
Exitapp
return
;labels
;Ltrim new folder name since it's invalid
gcreateFolder:
GuiControlGet, createFolderName,, % folderCreationHwnd
newCreateFolderName:=LTrim(createFolderName)
if !(newCreateFolderName==createFolderName) {
GuiControl, Text, vcreateFolder, % newCreateFolderName
}
return
gsaveSettings:
gui, settingsGui:Default
gui, submit
FileRecycle, %A_AppData%\ahk_explorer_settings\settings.txt
FileAppend, %vsettings%, *%A_AppData%\ahk_explorer_settings\settings.txt
loadSettings()
return
gsettings:
Gui, settingsGui:Default
FileRead, settingsTxt, %A_AppData%\ahk_explorer_settings\settings.txt
if (!settingsGuiCreated)
{
settingsGuiCreated:=true
editSize:=[1000, 200]
textSize:=[190, editSize[2]]
editPos:=[textSize[1]+30, 50]
textPos:=[10, ZTrim(editPos[2]+1.5) ]
guiSize:=[editSize[1]+textSize[1]+20, editPos[2]+editSize[2]+10]
guiPos:=[A_ScreenWidth/2-guiSize[1]/2,A_ScreenHeight/2-guiSize[2]/2]
Gui,Font,s12 w500 q5, Consolas
Gui, add, button, ggsaveSettings,Save Settings
Gui,add,Text, % "x" textPos[1] " y" textPos[2] " w" textSize[1] " h" textSize[2], peazipPath`nvscodePath`nBGColorOfSelectedPane`nAhk2ExePath`nspekPath
Gui,add,Edit, % "x" editPos[1] " y" editPos[2] " w" editSize[1] " h" editSize[2] " vvsettings -wrap",%settingsTxt%
} else {
Guicontrol, text, vsettings,%settingsTxt%
}
Gui,show, % "x" guiPos[1] " y" guiPos[2] " w" guiSize[1] " h" guiSize[2] ,set_settings_GUI
return
gChangeDrive:
index:=SubStr(A_GuiControl, 0)
EcurrentDir%whichSide%:=drives[index] ":"
renderCurrentDir()
return
multiRenameGuiGuiClose:
Gui, Destroy
return
gmultiRenameApply:
multiRenameNames:=getMultiRenameNames()
multiRenameNamesBak:=multiRenameNames.Clone()
namesToMultiRenameBak:=namesToMultiRename.Clone()
for k, v in multiRenameNamesBak {
toRenamePath := multiRenameDir "\" namesToMultiRenameBak[k]
renamedPath := multiRenameDir "\" v
renamedPathExists:=fileExist(renamedPath)
if (renamedPathExists) {
p("name already taken", renamedPathExists)
break
}
toRenameExists:=fileExist(toRenamePath)
if (toRenameExists) {
if (InStr(toRenameExists, "D")) {
FileMoveDir, %toRenamePath%, %renamedPath%
} else {
FileMove, %toRenamePath%, %renamedPath%
}
if ErrorLevel {
p("file", toRenamePath "could not be renamed to", renamedPath)
break
}
namesToMultiRename.RemoveAt(1)
multiRenameNames.RemoveAt(1)
} else {
p("file to rename:", toRenamePath, "doesn't exist anymore")
break
}
}
multiRenamelength:=namesToMultiRename.Length()
if (multiRenamelength) {
Guicontrol, text, vmultiRenameTargets, % "|" array_ToVerticleBarString(namesToMultiRename)
Guicontrol, text, vmultiRenamePreview, % "|" array_ToVerticleBarString(multiRenameNames)
} else {
Gui, Destroy
setWhichSideFromDir(multiRenameDir)
renderCurrentDir() ;refresh
}
return
gmultiRenamePreview:
Guicontrol, text, vmultiRenamePreview, % "|" array_ToVerticleBarString(getMultiRenameNames())
return
RemoveToolTip:
ToolTip
return
TypingInRenameSimple:
Gui,Submit,NoHide
Size:=10
Gui,Fake:Font,s%Size%,Segoe UI
Gui,Fake:Add,Text, -Wrap vDummy,% RenamingSimple
GuiControlGet,Pos,Fake:Pos,Dummy
Gui,Fake:Destroy
if (posw+ 2 * Size>renameTextWidthLimit) {
renameTextWidthLimit:=(posw+ 2 * Size) + (8 * Size)
width:=renameTextWidthLimit
GuiControl Move,RenamingSimple, W%width%
Guiwidth:=width+2
Gui, Show, W%Guiwidth%
}
if (!firstRename) {
firstRename:=true
SplitPath, TextBeingRenamed,, , , OutNameNoExt
SendMessage,0xB1, 0, 0, , ahk_id %RenameHwnd%
fileExist:=fileExist(EcurrentDir%whichSide% "\" TextBeingRenamed)
if (InStr(fileExist, "D"))
SendMessage, 0xB1,0,% StrLen(TextBeingRenamed),, ahk_id %RenameHwnd% ;select all
else
SendMessage, 0xB1,0,% StrLen(OutNameNoExt),, ahk_id %RenameHwnd%
} else {
ControlGet, Outvar ,CurrentCol,, Edit1
Outvar -=1
Postmessage,0xB1, 0, 0, Edit1 ;move caret to front to pan
Postmessage,0xB1,%Outvar%,%Outvar%, Edit1 ;move caret back to end
}
return
;renameLabel
grenameFileLabel:
fromButton:=true
renameFileLabel:
if (canRename) {
gui, renameSimple:Default
gui, submit
gui, main:Default
noRenameError:=true
if not(TextBeingRenamed==RenamingSimple) { ;Case Sensitive
if (stuffByName[RenamingSimple].Count()) {
noRenameError:=false
p("file with same name")
} else {
SourcePath:=EcurrentDir%whichSide% "\" TextBeingRenamed
fileExist:=FileExist(SourcePath)
if (fileExist) {
DestPath:=EcurrentDir%whichSide% "\" RenamingSimple
if (TextBeingRenamed=RenamingSimple) { ;only different capitalization
randomPath:=generateRandomUniqueName(SourcePath,isDir)
if (isDir) {
FileMoveDir, %SourcePath%, %randomPath%
} else {
FileMove, %SourcePath%, %randomPath%
}
if ErrorLevel {
noRenameError:=false
p("file could not be renamed:illegal name or file in use")
}
SoundPlay, *-1
SourcePath:=randomPath
}
if (InStr(fileExist, "D")) {
FileMoveDir, %SourcePath%, %DestPath%
} else {
; p("FileMove")
FileMove, %SourcePath%, %DestPath%
}
if ErrorLevel {
noRenameError:=false
p("file could not be renamed:illegal name or file in use")
}
SoundPlay, *-1
}
}
}
if (noRenameError)
{
canRename:=false
gui, renameSimple:Default
gui, destroy
gui, main:Default
if (fromButton) {
ControlFocus,, % "ahk_id " ListviewHwnd%whichSide%
}
} else {
gui, main:Default
gui, show
gui, renameSimple:Default
gui, show,,renamingWinTitle
}
fromButton:=false
}
return
mainGuiClose:
if GetKeyState("Shift") {
Process, Close, %PID_getFolderSizes%
Exitapp
} else {
Process, Close, %PID_getFolderSizes%
windowHidden:=true
Gui, main:Default
Gui, hide
}
return
couldNotCreateFolder()
{
global
Gui, createFolder:Default
creatingNewFolder:=true
dontSearch:=true
ControlSetText,, %vcreateFolder%, ahk_id %folderCreationHwnd%
SendMessage, 0xB1, 0, -1,, % "ahk_id " folderCreationHwnd
gui, createFolder: show,, create_folder
dontSearch:=false
}
;new folder
;create folder
createLabel:
gui, createFolder: submit
toCreate:=EcurrentDir%whichSide% "\" vcreateFolder
if (!fileExist(toCreate)) {
FileCreateDir, %toCreate%
if (ErrorLevel) {
SoundPlay, *16
p("Could not create Folder, illegal name or idk")
couldNotCreateFolder()
} else {
Gui, main:Default
SoundPlay, *-1
}
} else {
SoundPlay, *16
p("folder already exists")
couldNotCreateFolder()
}
return
createAndOpenLabel:
gui, createFolder: submit
toCreate:=EcurrentDir%whichSide% "\" vcreateFolder
if (!fileExist(toCreate)) {
FileCreateDir, %toCreate%
if (ErrorLevel) {
SoundPlay, *16
p("Could not create Folder, illegal name or idk")
couldNotCreateFolder()
} else {
EcurrentDir%whichSide%:=toCreate
Gui, main:Default
renderCurrentDir()
SoundPlay, *-1
}
} else {
SoundPlay, *16
p("folder already exists")
couldNotCreateFolder()
}
return
gfavoritesListView:
if (A_GuiEvent = "DoubleClick") {
Gui, ListView, favoritesListView
doubleClickedFolderOrFile(favoriteFolders[A_EventInfo])
} else if (A_GuiEvent="ColClick") {
path=%A_AppData%\ahk_explorer_settings\favoriteFolders.txt
toRun:= """" vscodePath """ """ path """"
run, %toRun%
}
return
folderlistViewEvents1_1:
folderlistViewEvents2_1:
folderlistViewEvents1_2:
folderlistViewEvents2_2:
whichSide:=SubStr(A_GuiControl, 0)
num:=SubStr(A_GuiControl, 15, 1)
whichParent:=(num=1) ? 2 : 1
Gui, Show,NA,% EcurrentDir%whichSide% " - ahk_explorer"
if (A_GuiEvent="ColClick")
{
EcurrentDir%whichSide%:=parent%whichParent%Dir%whichSide%
renderCurrentDir()
} else if (A_GuiEvent = "DoubleClick") {
EcurrentDir%whichSide%:=parent%whichParent%DirDirs%whichSide%[A_EventInfo]
renderCurrentDir()
}
return
currentDirEdit1Changed:
currentDirEdit2Changed:
; SetTimer, currentDirEdit1ChangedTimer, -0
if (focused="searchCurrentDirEdit") {
EditOnInput()
}
return
EditOnInput() {
global EditSearchRunning, EditSearchSleep_tick
if (EditSearchRunning) {
EditSearchSleep_tick:=A_TickCount + 0
} else {
EditSearchRunning:=true
EditSearchSleep_tick:=A_TickCount + 0
GoSub, pleaseDoNotBlock
if (EditSearchRunning) {
SetTimer, pleaseDoNotBlock, 0
}
}
}
pleaseDoNotBlock:
if (A_TickCount < EditSearchSleep_tick) {
return
}
EditSearchRunning:=false
SetTimer, pleaseDoNotBlock, Off
; Retrieves the contents of the control.
GuiControlGet, currentDirEditText,, vcurrentDirEdit%whichSide%
searchString%whichSide%:=currentDirEditText
searchInCurrentDir()
return
currentDirEdit1ChangedTimer:
Gui, main:Default
gui, submit, nohide
if (focused="searchCurrentDirEdit")
{
if (vcurrentDirEdit%whichSide%!=lastEditText)
lastEditText:=vcurrentDirEdit%whichSide%
if (!submittingGui) {
searchString%whichSide%:=vcurrentDirEdit%whichSide%
searchInCurrentDir()
} else {
p(6456)
queueSubmitGui:=true
}
}
return
listViewEvents1:
listViewEvents2:
; whichSide:=SubStr(A_GuiControl, 0)
if (A_GuiEvent=="D") {
selectedPaths:=getSelectedPaths()
if (GetKeyState("Alt")) {
FileToClipboard(selectedPaths, "cut")
} else {
FileToClipboard(selectedPaths)
}
Cursors := []
Cursors[1] := DllCall("LoadCursor", "Ptr", 0, "Ptr", 32515, "UPtr") ; DROPEFFECT_COPY = IDC_CROSS
Cursors[2] := DllCall("LoadCursor", "Ptr", 0, "Ptr", 32516, "UPtr") ; DROPEFFECT_MOVE = IDC_UPARROW
Cursors[3] := DllCall("LoadCursor", "Ptr", 0, "Ptr", 32648, "UPtr") ; Copy or Move = IDC_NO
DoDragDrop(Cursors)
}
else if (A_GuiEvent=="F") {
whichSide:=SubStr(A_GuiControl, 0)
Gui, Show,NA,% EcurrentDir%whichSide% " - ahk_explorer"
}
else if (A_GuiEvent=="e") {
whichSide:=SubStr(A_GuiControl, 0)
focused:="flistView"
LV_GetText(OutputVar,A_EventInfo,2)
for k, v in stuffByName
{
if (v=renaming) {
SourcePath:=filePaths[k]
DestPath:=EcurrentDir%whichSide% "\" OutputVar
stuffByName[k]:=OutputVar
filePaths[k]:=DestPath
fileExist:=FileExist(SourcePath)
if (fileExist) {
if (InStr(fileExist, "D")) {
FileMoveDir, %SourcePath%, %DestPath%
} else {
FileMove, %SourcePath%, %DestPath%
}
}
}
}
} else if (A_GuiEvent=="E") {
focused:="renaming"
LV_GetText(OutputVar,A_EventInfo,2)
renaming:=OutputVar
SplitPath, OutputVar, , , OutExtension, OutNameNoExt
if (OutNameNoExt) {
Postmessage,0xB1, 0, % StrLen(OutNameNoExt), Edit2
} else {
Postmessage,0xB1, 1, % StrLen(OutExtension)+1, Edit2
}
} else if (A_GuiEvent = "DoubleClick")
{
if (!canRename)
doubleClickedNormal(A_EventInfo)
}
else if (A_GuiEvent=="K") ;key pressed
{
if (!dontSearch) {
whichSide:=SubStr(A_GuiControl, 0)
ControlFocus,, % "ahk_id " ListviewHwnd%whichSide%
Gui, ListView, vlistView%whichSide%
key := GetKeyName(Format("vk{:x}", A_EventInfo))
switch (key) {
case "Backspace":
case "Lwin":
case "NumpadRight":
case "NumpadLeft":
case "NumpadUp":
case "NumpadDown":
case "Alt":
case "Control":
case "Shift":
case "F1":
send, {f1}
case "F3":
send, {f3}
case "F4":
; send, {f4}
case "\":
case "NumpadEnd":
case "Numpad0":
case "NumpadHome":
case "NumpadPgDn":
case "NumpadPgUp":
case "]":
case "NumpadDel":
selectedNames:=getSelectedNames()
for k, v in getSelectedNames() {
finalStr:="""" A_AhkPath """ ""lib\fileRecycle_one.ahk"" """ EcurrentDir%whichSide% "\" v """"
run, %finalStr%
}
return
Default:
if (focused!="searchCurrentDirEdit")
{
ShiftIsDown := GetKeyState("Shift")
CtrlIsDown := GetKeyState("Ctrl")
if (CtrlIsDown and !ShiftIsDown) {
if (key="c") {
selectedPaths:=getSelectedPaths()
FileToClipboard(selectedPaths)
SoundPlay, *-1
}
else if (key="x") {
selectedPaths:=getSelectedPaths()
FileToClipboard(selectedPaths, "cut")
SoundPlay, *-1
} else if (key="v")
{
pasteFile()
} else if (key="a") {
loop % LV_GetCount()
{
LV_Modify(A_Index, "+Select") ; select
}
} else if (key="h") {
}
return
} else if (ShiftIsDown and !CtrlIsDown) {
if (key="F10") {
selectedNames:=getSelectedNames()
ShellContextMenu(EcurrentDir%whichSide%,selectedNames)
}
} else if (CtrlIsDown and ShiftIsDown) {
if (key="x") {
for k, v in getSelectedNames() ;extract using 7zip, 7-zip
{
SplitPath, v,,,, OutNameNoExt
runwait, % "lib\7z x """ EcurrentDir%whichSide% "\" v """ -o""" EcurrentDir%whichSide% "\" OutNameNoExt """ -spe",,Hide
; runwait, """" peazipPath """ -ext2folder """ EcurrentDir%whichSide% "\" v """"
}
soundplay, *-1
EcurrentDir%whichSide%:=EcurrentDir%whichSide% "\" OutNameNoExt
renderCurrentDir()
return
} else if (key="z") {
} else if (key="d") {
files:=array_ToSpacedString(getSelectedPaths())
runwait, "%peazipPath%" -add2archive %files%
soundplay, *-1
renderCurrentDir() ;refresh
return
} else if (key="v") {
if (DllCall("IsClipboardFormatAvailable", "UInt", CF_HDROP := 15)) { ; file being copied
if (DllCall("IsClipboardFormatAvailable", "UInt", dropEffectFormat)) {
if (DllCall("OpenClipboard", "Ptr", A_ScriptHwnd)) {
if (data := DllCall("GetClipboardData", "UInt", dropEffectFormat, "Ptr")) {
if (effect := DllCall("GlobalLock", "Ptr", data, "UInt*")) {
if (effect & DROPEFFECT_COPY) {
files:=StrSplit(clipboard, "`n","`r")
for k, v in files {
fileExist:=FileExist(v)
if (fileExist) {
SplitPath, v , OutFileName
dest:=EcurrentDir%whichSide%
Run, TeraCopy.exe Copy "%v%" "%dest%"
}
}
; renderCurrentDir()
SoundPlay, *-1
}
; action:="copy"
else if (effect & DROPEFFECT_MOVE) {
p("no move")
}
; action:="move"
DllCall("GlobalUnlock", "Ptr", data)
}
}
DllCall("CloseClipboard")
}
}
}
return
}
}
if (CtrlIsDown or ShiftIsDown)
return
focused=searchCurrentDirEdit
GuiControl, Focus, vcurrentDirEdit%whichSide%
; set text to key, append if there's already text
GuiControl, Text, vcurrentDirEdit%whichSide%, % searchString%whichSide% key
; move caret to end
SendMessage, 0xB1, -2, -1,, % "ahk_id " Edithwnd%whichSide%
}
}
}
}
else if (A_GuiEvent="RightClick") {
selectedNames:=getSelectedNames()
ShellContextMenu(EcurrentDir%whichSide%,selectedNames)
}
else if (A_GuiEvent="ColClick")
{
whichSide:=SubStr(A_GuiControl, 0)
columnsToSort:=[1,2,4,6]
if (A_EventInfo=1) {
if (!foldersFirst)
{
foldersFirst:=true
sortColumn(1, "SortDesc")
} else {
foldersFirst:=false
sortColumn(1, "Sort")
}
} else if (A_EventInfo=2) {
if (!A_ZSort%whichSide%)
{
A_ZSort%whichSide%:=true
sortColumn(2, "Sort")
} else {
A_ZSort%whichSide%:=false
sortColumn(2, "SortDesc")
}
} else if (A_EventInfo=3) {
if (!oldNew%whichSide%)
{
whichsort%whichSide%:="oldNew"
oldNew%whichSide%:=true
renderFunctionsToSort(sortedByDate%whichSide%, true)
} else {
whichsort%whichSide%:="newOld"
oldNew%whichSide%:=false
renderFunctionsToSort(sortedByDate%whichSide%)
}
} else if (A_EventInfo=5) {
; if (canSortBySize%whichSide%) {
if (!bigSmall%whichSide%)
{
whichsort%whichSide%:="bigSmall"
bigSmall%whichSide%:=true
renderFunctionsToSort(sortedBySize%whichSide%)
} else {
whichsort%whichSide%:="smallBig"
bigSmall%whichSide%:=false
renderFunctionsToSort(sortedBySize%whichSide%, true)
}
; }
}
}
return
;includes
#include <cMsgbox>
#include <WatchFolder2>
;Classes
; ======================================================================================================================
; Namespace: LV_Colors
; Function: Helper object and functions for ListView row and cell coloring
; Testted with: AHK 1.1.15.04 (A32/U32/U64)
; Tested on: Win 8.1 (x64)
; Changelog:
; 0.5.00.00/2014-08-13/just me - changed 'static mode' handling
; 0.4.01.00/2013-12-30/just me - minor bug fix
; 0.4.00.00/2013-12-30/just me - added static mode
; 0.3.00.00/2013-06-15/just me - added "Critical, 100" to avoid drawing issues
; 0.2.00.00/2013-01-12/just me - bugfixes and minor changes
; 0.1.00.00/2012-10-27/just me - initial release
; ======================================================================================================================
; CLASS LV_Colors
;
; The class provides seven public methods to register / unregister coloring for ListView controls, to set individual
; colors for rows and/or cells, to prevent/allow sorting and rezising dynamically, and to register / unregister the
; included message handler function for WM_NOTIFY -> NM_CUSTOMDRAW messages.
;
; If you want to use the included message handler you must call LV_Colors.OnMessage() once.
; Otherwise you should integrate the code within LV_Colors_WM_NOTIFY into your own notification handler.
; Without notification handling coloring won't work.
; ======================================================================================================================
Class LV_Colors {
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; PRIVATE PROPERTIES ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Static MessageHandler := "LV_Colors_WM_NOTIFY"
Static WM_NOTIFY := 0x4E
Static SubclassProc := RegisterCallback("LV_Colors_SubclassProc")
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; PUBLIC PROPERTIES ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Static Critical := 0
Static Critical := 100
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; META FUNCTIONS ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
__New(P*) {
Return False ; There is no reason to instantiate this class!
}
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; PRIVATE METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
On_NM_CUSTOMDRAW(H, L) {
Static CDDS_PREPAINT := 0x00000001
Static CDDS_ITEMPREPAINT := 0x00010001
Static CDDS_SUBITEMPREPAINT := 0x00030001
Static CDRF_DODEFAULT := 0x00000000
Static CDRF_NEWFONT := 0x00000002
Static CDRF_NOTIFYITEMDRAW := 0x00000020
Static CDRF_NOTIFYSUBITEMDRAW := 0x00000020
Static CLRDEFAULT := 0xFF000000
; Size off NMHDR structure
Static NMHDRSize := (2 * A_PtrSize) + 4 + (A_PtrSize - 4)
; Offset of dwItemSpec (NMCUSTOMDRAW)
Static ItemSpecP := NMHDRSize + (5 * 4) + A_PtrSize + (A_PtrSize - 4)
; Size of NMCUSTOMDRAW structure
Static NCDSize := NMHDRSize + (6 * 4) + (3 * A_PtrSize) + (2 * (A_PtrSize - 4))
; Offset of clrText (NMLVCUSTOMDRAW)
Static ClrTxP := NCDSize
; Offset of clrTextBk (NMLVCUSTOMDRAW)
Static ClrTxBkP := ClrTxP + 4
; Offset of iSubItem (NMLVCUSTOMDRAW)
Static SubItemP := ClrTxBkP + 4
; Offset of clrFace (NMLVCUSTOMDRAW)
Static ClrBkP := SubItemP + 8
DrawStage := NumGet(L + NMHDRSize, 0, "UInt")
, Row := NumGet(L + ItemSpecP, 0, "UPtr") + 1
, Col := NumGet(L + SubItemP, 0, "Int") + 1
If This[H].IsStatic
Row := This.MapIndexToID(H, Row)
; SubItemPrepaint ------------------------------------------------------------------------------------------------
If (DrawStage = CDDS_SUBITEMPREPAINT) {
NumPut(This[H].CurTX, L + ClrTxP, 0, "UInt"), NumPut(This[H].CurTB, L + ClrTxBkP, 0, "UInt")
, NumPut(This[H].CurBK, L + ClrBkP, 0, "UInt")
ClrTx := This[H].Cells[Row][Col].T, ClrBk := This[H].Cells[Row][Col].B
If (ClrTx <> "")
NumPut(ClrTX, L + ClrTxP, 0, "UInt")
If (ClrBk <> "")
NumPut(ClrBk, L + ClrTxBkP, 0, "UInt"), NumPut(ClrBk, L + ClrBkP, 0, "UInt")
If (Col > This[H].Cells[Row].MaxIndex()) && !This[H].HasKey(Row)
Return CDRF_DODEFAULT
Return CDRF_NOTIFYSUBITEMDRAW
}
; ItemPrepaint ---------------------------------------------------------------------------------------------------
If (DrawStage = CDDS_ITEMPREPAINT) {
This[H].CurTX := This[H].TX, This[H].CurTB := This[H].TB, This[H].CurBK := This[H].BK
ClrTx := ClrBk := ""
If This[H].Rows.HasKey(Row)
ClrTx := This[H].Rows[Row].T, ClrBk := This[H].Rows[Row].B
If (ClrTx <> "")
NumPut(ClrTx, L + ClrTxP, 0, "UInt"), This[H].CurTX := ClrTx
If (ClrBk <> "")
NumPut(ClrBk, L + ClrTxBkP, 0, "UInt") , NumPut(ClrBk, L + ClrBkP, 0, "UInt")
, This[H].CurTB := ClrBk, This[H].CurBk := ClrBk
If This[H].Cells.HasKey(Row)
Return CDRF_NOTIFYSUBITEMDRAW
Return CDRF_DODEFAULT
}
; Prepaint -------------------------------------------------------------------------------------------------------
If (DrawStage = CDDS_PREPAINT) {
Return CDRF_NOTIFYITEMDRAW
}
; Others ---------------------------------------------------------------------------------------------------------
Return CDRF_DODEFAULT
}
; -------------------------------------------------------------------------------------------------------------------
MapIndexToID(HWND, Row) {
; LVM_MAPINDEXTOID = 0x10B4 -> http://msdn.microsoft.com/en-us/library/bb761139(v=vs.85).aspx
SendMessage, 0x10B4, % (Row - 1), 0, , % "ahk_id " . HWND
Return ErrorLevel
}
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; PUBLIC METHODS ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; ===================================================================================================================
; Attach() Register ListView control for coloring
; Parameters: HWND - ListView's HWND.
; Optional ------------------------------------------------------------------------------------------
; StaticMode - Static color assignment, i.e. the colors will be assigned permanently to a row
; rather than to a row number.
; Values: True / False
; Default: False
; NoSort - Prevent sorting by click on a header item.
; Values: True / False
; Default: True
; NoSizing - Prevent resizing of columns.
; Values: True / False
; Default: True
; Return Values: True on success, otherwise false.
; ===================================================================================================================
Attach(HWND, StaticMode := False, NoSort := True, NoSizing := True) {
Static LVM_GETBKCOLOR := 0x1000
Static LVM_GETHEADER := 0x101F
Static LVM_GETTEXTBKCOLOR := 0x1025
Static LVM_GETTEXTCOLOR := 0x1023
Static LVM_SETEXTENDEDLISTVIEWSTYLE := 0x1036
Static LVS_EX_DOUBLEBUFFER := 0x00010000
If !DllCall("User32.dll\IsWindow", "Ptr", HWND, "UInt")
Return False
If This.HasKey(HWND)
Return False
; Set LVS_EX_DOUBLEBUFFER style to avoid drawing issues, if it isn't set as yet.
SendMessage, % LVM_SETEXTENDEDLISTVIEWSTYLE, % LVS_EX_DOUBLEBUFFER, % LVS_EX_DOUBLEBUFFER, , % "ahk_id " . HWND
If (ErrorLevel = "FAIL")
Return False
; Get the default colors
SendMessage, % LVM_GETBKCOLOR, 0, 0, , % "ahk_id " . HWND
BkClr := ErrorLevel
SendMessage, % LVM_GETTEXTBKCOLOR, 0, 0, , % "ahk_id " . HWND
TBClr := ErrorLevel
SendMessage, % LVM_GETTEXTCOLOR, 0, 0, , % "ahk_id " . HWND
TxClr := ErrorLevel
; Get the header control
SendMessage, % LVM_GETHEADER, 0, 0, , % "ahk_id " . HWND
Header := ErrorLevel
; Store the values in a new object
This[HWND] := {BK: BkClr, TB: TBClr, TX: TxClr, Header: Header, IsStatic: !!StaticMode}
If (NoSort)
This.NoSort(HWND)
If (NoSizing)
This.NoSizing(HWND)
Return True
}
; ===================================================================================================================
; Detach() Unregister ListView control
; Parameters: HWND - ListView's HWND
; Return Value: Always True
; ===================================================================================================================
Detach(HWND) {
; Remove the subclass, if any
Static LVM_GETITEMCOUNT := 0x1004
If (This[HWND].SC)
DllCall("Comctl32.dll\RemoveWindowSubclass", "Ptr", HWND, "Ptr", This.SubclassProc, "Ptr", HWND)
This.Remove(HWND, "")
WinSet, Redraw, , % "ahk_id " . HWND
Return True
}
; ===================================================================================================================
; Row() Set background and/or text color for the specified row
; Parameters: HWND - ListView's HWND
; Row - Row number
; Optional ------------------------------------------------------------------------------------------
; BkColor - Background color as RGB color integer (e.g. 0xFF0000 = red)
; Default: Empty -> default background color
; TxColor - Text color as RGB color integer (e.g. 0xFF0000 = red)
; Default: Empty -> default text color
; Return Value: True on success, otherwise false.
; ===================================================================================================================
Row(HWND, Row, BkColor := "", TxColor := "") {
If !This.HasKey(HWND)
Return False
If This[HWND].IsStatic
Row := This.MapIndexToID(HWND, Row)
If (BkColor = "") && (TxColor = "") {
This[HWND].Rows.Remove(Row, "")
Return True
}
BkBGR := TxBGR := ""
If BkColor Is Integer
BkBGR := ((BkColor & 0xFF0000) >> 16) | (BkColor & 0x00FF00) | ((BkColor & 0x0000FF) << 16)
If TxColor Is Integer
TxBGR := ((TxColor & 0xFF0000) >> 16) | (TxColor & 0x00FF00) | ((TxColor & 0x0000FF) << 16)
If (BkBGR = "") && (TxBGR = "")
Return False
If !This[HWND].HasKey("Rows")
This[HWND].Rows := {}
If !This[HWND].Rows.HasKey(Row)
This[HWND].Rows[Row] := {}
If (BkBGR <> "")
This[HWND].Rows[Row].Insert("B", BkBGR)
If (TxBGR <> "")
This[HWND].Rows[Row].Insert("T", TxBGR)
Return True
}
; ===================================================================================================================
; Cell() Set background and/or text color for the specified cell
; Parameters: HWND - ListView's HWND
; Row - Row number
; Col - Column number
; Optional ------------------------------------------------------------------------------------------
; BkColor - Background color as RGB color integer (e.g. 0xFF0000 = red)
; Default: Empty -> default background color
; TxColor - Text color as RGB color integer (e.g. 0xFF0000 = red)
; Default: Empty -> default text color
; Return Value: True on success, otherwise false.
; ===================================================================================================================
Cell(HWND, Row, Col, BkColor := "", TxColor := "") {
If !This.HasKey(HWND)
Return False
If This[HWND].IsStatic
Row := This.MapIndexToID(HWND, Row)
If (BkColor = "") && (TxColor = "") {
This[HWND].Cells.Remove(Row, "")
Return True
}
BkBGR := TxBGR := ""
If BkColor Is Integer
BkBGR := ((BkColor & 0xFF0000) >> 16) | (BkColor & 0x00FF00) | ((BkColor & 0x0000FF) << 16)
If TxColor Is Integer
TxBGR := ((TxColor & 0xFF0000) >> 16) | (TxColor & 0x00FF00) | ((TxColor & 0x0000FF) << 16)
If (BkBGR = "") && (TxBGR = "")
Return False
If !This[HWND].HasKey("Cells")
This[HWND].Cells := {}
If !This[HWND].Cells.HasKey(Row)
This[HWND].Cells[Row] := {}
This[HWND].Cells[Row, Col] := {}
If (BkBGR <> "")