forked from 7plus/7plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Explorer.ahk
848 lines (816 loc) · 29.1 KB
/
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
IsMouseOverDesktop()
{
MouseGetPos, , ,Window , UnderMouse
WinGetClass, winclass , ahk_id %Window%
if (winclass="WorkerW"||winclass="Progman")
return true
return false
}
InFileList()
{
if(WinVer >= WIN_7)
ControlGetFocus focussed, A
else
focussed:=XPGetFocussed()
if(WinActive("ahk_group ExplorerGroup"))
{
if((WinVer >= WIN_7 && focussed="DirectUIHWND3") || (WinVer < WIN_7 && focussed="SysListView321"))
return true
}
else if((x:=IsDialog())=1)
{
if((WinVer >= WIN_7 && focussed="DirectUIHWND2") || (WinVer < WIN_7 && focussed="SysListView321"))
return true
}
else if(x=2)
{
if(focussed="SysListView321")
return true
}
return false
}
IsMouseOverFileList()
{
CoordMode,Mouse,Relative
MouseGetPos, MouseX, MouseY,Window , UnderMouse
WinGetClass, winclass , ahk_id %Window%
if(WinVer >= WIN_7 && (winclass = "CabinetWClass" || winclass = "ExploreWClass")) ;Win7 Explorer
{
ControlGetPos , cX, cY, Width, Height, DirectUIHWND3, A
;Offsets are estimated values in my windows skin and don't need to be correct for everyone. They're used to prevent catching double clicks on the column headers.
if(IsInArea(MouseX, MouseY, cX, cY + 25,Width, Height - 25))
return true
}
else if((z := IsDialog(window)) = 1) ;New dialogs
{
ControlGetPos , cX, cY, Width, Height, DirectUIHWND2, A
;Offsets are estimated values in my windows skin and don't need to be correct for everyone. They're used to prevent catching double clicks on the column headers.
if(IsInArea(MouseX, MouseY, cX, cY + 25, Width, Height - 25)) ;Checking for area because rename might be in process and mouse might be over edit control
return true
}
else if(winclass="CabinetWClass" || winclass="ExploreWClass" || z = 2) ;Old dialogs or Vista/XP
{
ControlGetPos , cX, cY, Width, Height, SysListView321, A
if(IsInArea(MouseX, MouseY, cX, cY, Width, Height) && UnderMouse = "SysListView321") ;Additional check needed for XP because of header
return true
}
return false
}
InTree()
{
if(WinActive("ahk_group ExplorerGroup")||IsDialog()=1) ;Explorer or new dialog
{
if(WinVer >= WIN_7)
ControlGetFocus focussed, A
else
focussed := XPGetFocussed()
if(focussed = "SysTreeView321")
return true
}
return false
}
IsRenaming()
{
if(WinVer >= WIN_7)
ControlGetFocus focussed, A
else
focussed := XPGetFocussed()
if(WinActive("ahk_group ExplorerGroup")) ;Explorer
{
if(InStr(focussed, "Edit") = 1)
{
if(WinVer >= WIN_7)
ControlGetPos, X, Y, Width, Height, DirectUIHWND3, A
else
ControlGetPos , X, Y, Width, Height, SysListView321, A
ControlGetPos, X1, Y1, Width1, Height1, %focussed%, A
if(IsInArea(X1, Y1, X, Y, Width, Height)&&IsInArea(X1 + Width1, Y1, X, Y, Width, Height) && IsInArea(X1, Y1 + Height1, X, Y, Width, Height) && IsInArea(X1 + Width1, Y1 + Height1, X, Y, Width, Height))
return focussed
}
}
else if (WinActive("ahk_group DesktopGroup")) ;Desktop
{
if(focussed = "Edit1")
return focussed
}
else if((x := IsDialog())) ;FileDialogs
{
if(InStr(focussed, "Edit1") = 1)
{
;figure out if the the edit control is inside the DirectUIHWND2 or SysListView321
if(x = 1 && WinVer >= WIN_7) ;New Dialogs
ControlGetPos, X, Y, Width, Height, DirectUIHWND2, A
else ;Old Dialogs
ControlGetPos, X, Y, Width, Height, SysListView321, A
ControlGetPos, X1, Y1, Width1, Height1, %focussed%, A
if(IsInArea(X1, Y1, X, Y, Width, Height) && IsInArea(X1 + Width1, Y1, X, Y, Width, Height) && IsInArea(X1, Y1 + Height1, X, Y, Width, Height) && IsInArea(X1 + Width1, Y1 + Height1, X, Y, Width, Height))
return focussed
}
}
return false
}
IsInAddressBar()
{
if(WinVer >= WIN_7)
ControlGetFocus focussed, A
else
focussed := XPGetFocussed()
if(WinActive("ahk_group ExplorerGroup")) ;Explorer
{
if(focussed = "Edit1" && !IsRenaming()) ;Renaming Control can be Edit1 when rename is made before addressbar is focussed
return true
}
else if(IsDialog() = 1) ;New Dialogs
{
if(focussed = "Edit2") ;Seems to be Edit2 all the time...
return true
}
return false
}
SetFocusToFileView()
{
if(WinActive("ahk_group ExplorerGroup"))
{
if(WinVer >= WIN_7)
ControlFocus DirectUIHWND3, A
else ;XP, Vista
ControlFocus SysListView321, A
}
else if((x := IsDialog())=1) ;New Dialogs
{
if(WinVer >= WIN_7)
ControlFocus DirectUIHWND2, A
else
ControlFocus SysListView321, A
}
else if(x = 2) ;Old Dialogs
ControlFocus SysListView321, A
return
}
FixExplorerConfirmationDialogs()
{
;Check if a confirmation dialog is active, if it is -> check the checkbox!
hwnd := WinActive("ahk_class #32770")
hParent := GetParent(GetParent(hwnd))
if(hwnd && hParent && (InStr("ExploreWClass,CabinetWClass", WinGetClass("ahk_id " hParent)) || IsDialog(hParent)))
{
WinGet ctrlList, ControlList, A
; Find the checkbox!
Loop Parse, ctrlList, `n
{
ControlGet hwnd, Hwnd, , %A_LoopField%, A
if(InStr(WinGetClass("ahk_id " hwnd), "Button") = 1)
{
WinGet, style, style, ahk_id %hwnd%
WinGetTitle, title, ahk_id %hwnd%
WinGetPos, , , w, h, ahk_id %hwnd%
if(!title || w = 0 || h = 0)
continue
for i, s in [0x2,0x4]
if(style & s && style & 0x10000000) ;WS_VISIBLE
{
Control, Check , ,, ahk_id %hwnd%
return
}
}
}
}
}
;Enhanced renaming
#if Settings.Explorer.EnhancedRenaming && IsRenaming()
F2::EnhancedRenaming()
#if
;For tip only
#if InFileList() && !IsRenaming()
F2::
ShowTip(9)
Send {F2}
return
#if
EnhancedRenaming()
{
static EM_GETSEL:=0x00B0,EM_SETSEL:=0x00B1
EditControl := IsRenaming()
SendMessage, EM_GETSEL,,, %EditControl%, A
start := ErrorLevel & 0xFFFF
end := (ErrorLevel & 0xFFFF0000) >> 16
ControlGetText, Text, %EditControl%, A
SelectedText := SubStr(Text, start + 1, end - start)
if(!pos := InStr(Text, ".", 0, 0))
return
if(Text = SelectedText)
SendMessage, EM_SETSEL, 0, pos - 1, %EditControl%, A
else if(SelectedText = SubStr(Text, 1, pos - 1))
SendMessage, EM_SETSEL, pos, StrLen(Text), %EditControl%, A
else if(SelectedText = SubStr(Text, pos + 1))
SendMessage, EM_SETSEL, 0, StrLen(Text), %EditControl%, A
}
;Mouse "gestures" (hold left/right and click right/left)
#if Settings.Explorer.MouseGestures && GetKeyState("RButton") && (WinActive("ahk_group ExplorerGroup")||IsDialog()) && IsMouseOverFileList()
LButton::
SuppressRButtonUp := true
Navigation.GoBack()
return
#if
#if Settings.Explorer.MouseGestures && SuppressRButtonUp
~RButton UP::
SuppressRButtonUp := false
Send, {Esc}
Return
#if
#if Settings.Explorer.MouseGestures && GetKeyState("LButton","P") && (WinActive("ahk_group ExplorerGroup")||IsDialog()) && IsMouseOverFileList()
RButton::
Navigation.GoForward()
SuppressRButtonUp := true
Return
#if
;Enter:Execute focussed file
#if Settings.Explorer.ImproveEnter && WinActive("ahk_group ExplorerGroup") && InFileList() && !IsRenaming() && !IsContextMenuActive()
Enter::
NumpadEnter::
ExecuteFocusedFile()
SetTimerF("ExplorerPathChanged", -100)
return
#if
;Register path changes caused by pressing enter. This is done in addition to the shell message that gets sent when the path changes because it does not work for all paths.
;#if WinActive("ahk_group ExplorerGroup") && !IsRenaming()
;~LButton::
;~Enter::
;~NumpadEnter::
;~!Up::
;~!Left::
;~!Right::
;~Backspace::
; SetTimerF("ExplorerPathChanged", -100)
; return
;#if
ExecuteFocusedFile()
{
files := Navigation.GetSelectedFilePaths()
focused := Navigation.GetFocussedFilename()
if(!files && focused)
Send {Space}{Enter}
else
Send {Enter}
}
;Function(s) to align explorer windows side by side and to launch explorer with last used directory
#if (Settings.Explorer.RememberPath && Settings.Explorer.CurrentPath != "") || Settings.Explorer.AlignNewExplorer && WinActive("ahk_group ExplorerGroup")
#e::RunExplorer()
#if
RunExplorer()
{
active := WinActive("ahk_group ExplorerGroup")
if(active && Settings.Explorer.AlignNewExplorer)
{
WinRestore ahk_id %active%
if(WinVer >= WIN_7)
{
WinGetPos, x,y,w,h,ahk_id %active%
x++
WinMove, ahk_id %active%,, %x%, %y%
Send #{Left}
}
Else
{
GetActiveMonitorWorkspaceArea(x,y,w,h,active)
w := Round(w/2)
WinMove, ahk_id %active%,, %x%,%y%,%w%,%h%
}
}
if(active && Settings.Explorer.AlignNewExplorer)
Run, % "Explorer """ Navigation.GetPath() """"
else if(Settings.Explorer.RememberPath && Settings.Explorer.CurrentPath)
Run, % "Explorer """ Settings.Explorer.CurrentPath """"
else
run, % "Explorer C:"
if(Settings.Explorer.AlignNewExplorer && active)
{
WinWaitNotActive ahk_id %active%
Timeout := 10000
Start := A_TickCount
Loop ;Make sure new window is really active
{
Sleep 10
active2 := WinActive("ahk_group ExplorerGroup")
if((active2 && active2 != active) || A_TickCount - Start > Timeout)
Break
}
Start := A_TickCount
Loop ;Wait until new window is visible
{
Sleep 10
WinGet,visible,style, ahk_id %active2%
if(visible & 0x10000000 || A_TickCount - Start > Timeout)
break
}
if(WinVer >= WIN_7)
Send #{Right}
else
{
x += w
WinMove, ahk_id %active2%,, %x%,%y%,%w%,%h%
}
}
Return
}
;Scroll tree list with mouse wheel
#if (Settings.Explorer.ScrollTreeUnderMouse && ((IsWindowUnderCursor("#32770") && IsDialog()) || IsWindowUnderCursor("CabinetWClass") || IsWindowUnderCursor("ExploreWClass")) && !IsRenaming()) || (CAccessor.Instance.GUI.GUINum && IsWindowUnderCursor(CAccessor.Instance.GUI.hwnd))
WheelUp::
WheelDown::
Wheel()
return
Wheel()
{
WasCritical := A_IsCritical
Critical
CoordMode, Mouse, Screen
MouseGetPos, MouseX, MouseY
DllCall("SendMessage", "PTR", DllCall("WindowFromPoint", "INT64", MouseX | (MouseY << 32), "Ptr"), "UInt", 0x20A, "PTR", (120 * (A_ThisHotkey = "WheelUp" ? 1 : -1)) << 16, "PTR", (MouseY << 16) | MouseX)
if(!WasCritical)
Critical, Off
return
}
#if
InitExplorerWindows()
{
global ExplorerWindows, ExplorerHistory
ExplorerWindows := Array()
ExplorerHistory := new CExplorerHistory()
RegisterExplorerWindows()
TabContainerList := Array()
if(WinVer >= WIN_Vista)
TabContainerList.Font := "Segoe UI"
Else
TabContainerList.Font := "Tahoma"
TabContainerList.FontSize := 12
TabContainerList.hPadding := 4
TabContainerList.vPadding := 2
TabContainerList.height := 20
TabContainerList.TabWidth := 100
TabContainerList.InActiveHeightDifference := 2
TabContainerList.MinWidth := 40
ExplorerWindows.TabContainerList := TabContainerList
if(WinVer = WIN_7)
{
ExplorerWindows.InfoGUI_FreeText := TranslateMUI(shell32MUIpath,12336) ;Aquire a translated version of "free"
ExplorerWindows.InfoGUI_FreeText := SubStr(ExplorerWindows.InfoGUI_FreeText, InStr(ExplorerWindows.InfoGUI_FreeText, " ", 0, 0) + 1)
}
}
;Explorer history publically only displays the first 100 entries. The rest is used for collecting frequent entries
Class CExplorerHistory extends CQueue
{
MaxSize := 200
Unique := false
__new()
{
this.Load()
}
Load()
{
if(FileExist(Settings.ConfigPath "\ExplorerHistory.xml"))
{
FileRead, xml, % Settings.ConfigPath "\ExplorerHistory.xml"
XMLObject := XML_Read(xml)
;Convert empty and single arrays to real array
if(!XMLObject.List.MaxIndex())
XMLObject.List := IsObject(XMLObject.List) ? Array(XMLObject.List) : Array()
Loop % min(XMLObject.List.MaxIndex(), this.MaxSize)
{
XMLEntry := XMLObject.List[A_Index]
entry := RichObject()
for key, value in XMLEntry
entry[key] := value
this[A_Index] := entry
}
}
}
Save()
{
FileDelete, % Settings.ConfigPath "\ExplorerHistory.xml"
XMLObject := Object("List", Array())
Loop % min(this.MaxIndex(), this.MaxSize)
{
entry := this[A_Index]
XMLEntry := {}
for key, value in entry
XMLEntry[key] := value
XMLObject.List[A_Index] := XMLEntry
}
XML_Save(XMLObject, Settings.ConfigPath "\ExplorerHistory.xml")
return
}
__get(key)
{
if(key = "History")
{
History := Array()
Loop % min(this.MaxIndex(), this.MaxSize / 2)
History[A_Index] := {Path : this[A_Index].Path, Name : this[A_Index].Name}
return History
}
else if(key = "FrequentPaths")
{
FrequentIndices := ""
Loop % min(this.MaxIndex(), this.MaxSize)
FrequentIndices .= (A_Index = 1 ? "" : ",") A_Index
Sort, FrequentIndices, F ExplorerPathFrequencySort D`,
FrequentPaths := Array()
Loop, Parse, FrequentIndices, `,
FrequentPaths[A_Index] := {Path : this[A_LoopField].Path, Name : this[A_LoopField].Name}
return FrequentPaths
}
}
;Puts an item in the queue
Push(item)
{
Debug("Pusinhing item to Queue", item)
itemPosition := this.IndexOfEqual(item, 0, "Path")
if(!itemPosition)
{
this.Insert(1, item)
if(this.MaxIndex() = this.MaxSize + 1)
this.Remove()
}
else
this.Move(itemPosition, 1)
return this[1]
}
}
ExplorerPathFrequencySort(index1, index2)
{
global ExplorerHistory
return ExplorerHistory[index2].Usage - ExplorerHistory[index1].Usage
}
#if IsDialog()
~Enter::
~NumpadEnter::
~LButton::
SetTimer, CheckFileDialogFolder, -200
return
#if
CheckFileDialogFolder:
CheckFileDialogFolder()
return
CheckFileDialogFolder()
{
global ExplorerHistory
if(IsDialog())
if((Path := Navigation.GetPath()) != ExplorerHistory[1].Path)
{
entry := RichObject()
entry.Path := Path
SplitPath, Path, Name
entry.Name := Name
entry.Usage := 1
entry := ExplorerHistory.Push(entry)
entry.Usage++
}
}
;Find all explorer windows, register them in ExplorerWindows array and set up events and info gui
RegisterExplorerWindows()
{
global ExplorerWindows
; for item in ComObjCreate("Shell.Application").Windows
; ComObjConnect(item, "Explorer")
; ShellWindows := ComObjCreate("Shell.Application").Windows
; ComObjConnect(ShellWindows, "Explorer")
WinGet, hWndList, List, ahk_group ExplorerGroup
Loop % hwndList
{
if(!ExplorerWindows.FindKeyWithValue("hwnd", hWndList%A_Index%+0))
ExplorerWindows.Insert(new CExplorerWindow(hwndList%A_Index%+0))
}
SetTimer, WaitForClose, 1000
}
;Registers all explorer windows for SelectionChanged events. Called when explorer changes path
RegisterSelectionChangedEvents()
{
global ExplorerWindows
Loop % ExplorerWindows.MaxIndex()
ExplorerWindows[A_Index].RegisterSelectionChangedEvent()
}
/*
;Unregister an explorer window for SelectionChanged events
UnregisterSelectionChangedEvents(hwnd)
{
global RegisteredSelectionChangedWindows
i := RegisteredSelectionChangedWindows.FindKeyWithValue("hwnd", hwnd)
if(i > 0)
RegisteredSelectionChangedWindows.Delete(i)
}
*/
RestoreExplorerSelection()
{
global ExplorerWindows
hwnd := WinActive("ahk_group ExplorerGroup")+0
if(hwnd)
{
ExplorerWindow := ExplorerWindows.GetItemWithValue("hWnd",hwnd)
if(!IsObject(ExplorerWindow.Selection.History))
Debug("Explorer window " hwnd " is not registered!")
if(ExplorerWindow.Selection.History.MaxIndex() > 1)
{
Debug("Explorer window " hwnd "restore selecion")
Selection := ExplorerWindow.Selection.History[ExplorerWindow.Selection.History.MaxIndex() - 1]
; A SelectionChanged event will be fired 2 times that needs to be suppressed?
;Why is it fired 2 times instead of one time for each file? -> Probably because of timing
ExplorerWindow.Selection.IgnoreNextEvent := 2
Debug("Explorer window " hwnd " expecting " ExplorerWindow.Selection.IgnoreNextEvent " selection events.")
Navigation.SelectFiles(Selection, hwnd)
ExplorerWindow.Selection.History.Delete(ExplorerWindow.Selection.History.MaxIndex())
}
else
Debug("Explorer window " hwnd " is registered but has no history")
}
}
;===============;
;Explorer related Events;
;===============;
;Called when an explorer window is activated.
ExplorerActivated(hwnd)
{
global ExplorerWindows
if(!ExplorerWindows.FindKeyWithValue("hwnd",hwnd))
ExplorerWindows.Insert(new CExplorerWindow(hwnd))
RegisterSelectionChangedEvents() ;Is this needed? only as backup probably
}
;This routine polls the existance of explorer windows since they disappear rather randomly.
WaitForClose:
CheckForClosedExplorerWindows()
return
CheckForClosedExplorerWindows()
{
global ExplorerWindows, ToolWindows
DetectHiddenWindows, On
for index, ExplorerWindow in ExplorerWindows
{
if(!WinExist("ahk_id " ExplorerWindow.hwnd))
{
ExplorerDestroyed(ExplorerWindow.hwnd)
Loop % ToolWindows.MaxIndex() ;This code from Messagehooks.ahk is added here again since explorer close events don't work properly and need to be handled this way
{
if(ToolWindows[A_Index].hParent = ExplorerWindow.hwnd && ToolWindows[A_Index].AutoClose)
{
WinClose % "ahk_id " ToolWindows[A_Index].hGui
ToolWindows.Remove(A_Index)
break
}
}
SlideWindows.WindowClosed(ExplorerWindow.hwnd)
break
}
}
return
}
;Called when an explorer window gets deactivated.
ExplorerDeactivated(hwnd)
{
global ExplorerWindows
;Explicitly redraw the tab bar window when an explorer window gets deactivated.
;This is needed to make sure the window isn't visible anymore when an Explorer window is closed.
;Explorer window hides first so we check if all explorer windows from that tab container are hidden.
TabContainer := ExplorerWindows.GetItemWithValue("hwnd", hwnd + 0).TabContainer
for index, window in TabContainer.Tabs
{
WinGet, Style, Style, % "ahk_id " window.hwnd
if(!(Style & 0x10000000)) ;WS_VISIBLE
TabContainer.UpdateTabPosition()
}
}
;TODO: Continue here, implement delete method and check draw timer deactivation
;Called when an explorer window gets destroyed.
ExplorerDestroyed(hwnd)
{
global ExplorerWindows
TabContainer := ExplorerWindows.GetItemWithValue("hwnd", hwnd + 0).TabContainer
if(index := ExplorerWindows.FindKeyWithValue("hwnd", hwnd))
ExplorerWindows.Remove(index) ;This will destroy the info gui as well
if(ExplorerWindows.TabContainerList.TabCloseInProgress) ;If this is set, then this event was caused by a tab closing action and must not trigger further tab close functions
{
ExplorerWindows.TabContainerList.TabCloseInProgress := false
return
}
if(!TabContainer)
return
TabContainer.TabClosed(hwnd)
if(Settings.Explorer.Tabs.TabWindowClose = 1)
TabContainer.CloseAllTabs()
return
}
ExplorerMoved(hwnd)
{
global ExplorerWindows
if(!IsObject(ExplorerWindows))
return
ExplorerWindow := ExplorerWindows.GetItemWithValue("hwnd", hwnd)
if(IsObject(ExplorerWindow))
{
if(Settings.Explorer.Tabs.UseTabs && IsObject(ExplorerWindow.TabContainer) && IsObject(ExplorerWindows.TabContainerList) && !ExplorerWindows.TabContainerList.TabActivationInProgress)
ExplorerWindow.TabContainer.UpdatePosition()
if(Settings.Explorer.AdvancedStatusBarInfo && WinVer >= WIN_7)
ExplorerWindow.InfoGUI.UpdateInfoPosition()
}
}
;Called when active explorer changes its path.
ExplorerPathChanged(ExplorerWindow)
{
global ExplorerHistory, ExplorerWindows
if(!IsObject(ExplorerWindow))
{
ExplorerWindow := ExplorerWindows.GetItemWithValue("hwnd", WinExist("A"))
if(!ExplorerWindow)
return
}
Debug("path change")
OldPath := ExplorerWindow.Path
ExplorerWindow.RegisterSelectionChangedEvent() ;This will also refresh the path in ExplorerWindow
Path := ExplorerWindow.Path
if(OldPath = Path)
return
ExplorerWindow.DisplayName := Navigation.GetDisplayName(ExplorerWindow.hwnd)
Debug("change from " oldpath " to " path)
Entry := RichObject()
Entry.Path := Path
Entry.Usage := 0
Entry.Name := ExplorerWindow.DisplayName
Entry := ExplorerHistory.Push(Entry) ;This can return a different entry that already exists in the list!
Entry.Usage++
if(Settings.Explorer.Tabs.UseTabs && IsObject(ExplorerWindow.TabContainer))
ExplorerWindow.TabContainer.UpdateTabs()
;focus first file
if(Settings.Explorer.AutoSelectFirstFile)
{
SplitPath, Path, name, dir,,,drive
x := Navigation.GetSelectedFilepaths()
if(!x.MaxIndex() && dir && (WinVer < WIN_Vista || SubStr(Path, 1 ,40) != "::{26EE0668-A00A-44D7-9371-BEB064C98683}"))
{
if(WinVer >= WIN_7)
{
ControlGetFocus focussed, A
ControlFocus DirectUIHWND3, A
ControlSend DirectUIHWND3, {Home}{Space},A
}
else
{
focussed := XPGetFocussed()
ControlFocus SysListView321, A
ControlSend SysListView321, {Home},A
}
Sleep 50 ;Better wait some time
ControlFocus %focussed%, A
}
}
}
;Called when selection changes in an explorer window. If the shell is restarted, old windows won't be recognized anymore.
ExplorerSelectionChanged(ExplorerCOMObject)
{
global ExplorerWindows
Critical, Off
Loop % ExplorerWindows.MaxIndex()
{
if(ExplorerWindows[A_Index].Selection.COMObject = ExplorerCOMObject)
{
index := A_Index
break
}
}
if(!index)
return
if(ExplorerWindows[index].Selection.IgnoreNextEvent > 0)
{
ExplorerWindows[index].Selection.IgnoreNextEvent := ExplorerWindows[index].Selection.IgnoreNextEvent - 1
return
}
ShowTip({Min : 10, Max : 11}, 0.1)
ExplorerWindows[index].Selection.History.Insert(Navigation.GetSelectedFilenames(ExplorerWindows[index].hwnd))
if(ExplorerWindows[index].Selection.History.MaxIndex() > 10)
ExplorerWindows[index].Selection.History.Delete(1)
if(WinVer = WIN_7)
ExplorerWindows[index].InfoGUI.UpdateInfos(ExplorerWindows[index]) ;Update the info GUI to reflect selection change
}
;This class displays additional information in the status bar of explorer windows
Class InfoGUI
{
__New(hParent)
{
if(WinVer != WIN_7)
return 0
GuiNum := GetFreeGuiNum(1, this.__Class)
this.GuiNum := GuiNum
Gui, %GuiNum%: font, s9, Segoe UI
Gui, %GuiNum%: Add, Text, x60 y0 w70 h12, %A_Space%
Gui, %GuiNum%: Add, Text, x0 y0 w60 h12, %A_Space%
Gui, %GuiNum%: -Caption +LastFound +ToolWindow
Gui, %GuiNum%: Color, FFFFFF
Gui, %GuiNum%: +LastFound
WinSet, TransColor, FFFFFF
AttachToolWindow(hParent, GuiNum, true)
this.hWnd := WinExist() +0
this.hParent := hParent+0
}
__Delete()
{
Gui % this.GuiNum ":Destroy"
}
UpdateInfos(ExplorerWindow)
{
global ExplorerWindows
if(WinVer != WIN_7)
return
totalsize := 0
realfiles := false ;check if only folders are selected
History := ExplorerWindow.Selection.History[ExplorerWindow.Selection.History.MaxIndex()]
Loop % History.MaxIndex()
{
FileGetSize, size, % ExplorerWindow.Path "\" History[A_Index]
if(!realfiles)
realfiles := !InStr(FileExist(ExplorerWindow.Path "\" History[A_Index]), "D")
totalsize += size
}
DriveSpaceFree, free, % ExplorerWindow.Path
free := FormatFileSize(free * 1048576, free < 1000 ? 0 : 1)
GuiControl % this.GUINum ":Text", Static1, % free " " ExplorerWindows.InfoGUI_FreeText
if(realfiles)
{
totalsize := FormatFileSize(totalsize)
GuiControl % this.GUINum ":Text", Static2, %totalsize%
}
else
GuiControl % this.GUINum ":Text", Static2, %A_Space%
this.UpdateInfoPosition()
}
UpdateInfoPosition()
{
ControlGet, visible, visible, , msctls_statusbar321, % "ahk_id " this.hParent ;Check if status bar is visible
if(visible)
{
WinGetPos , X, Y, Width, Height, % "ahk_id " this.hParent
ControlGetPos , , cY, , cHeight, msctls_statusbar321, % "ahk_id " this.hParent
InfoX := X + Width - 370
InfoY := Round(Y + cY + cHeight / 2 - 6) ; +Height-26
if(Width > 540)
Gui, % this.GuiNum ":Show", AutoSize NA x%InfoX% y%InfoY%
}
else
{
Gui, % this.GuiNum ": Hide"
}
}
}
;TODO: Figure out how to receive explorer close event and proper path change
;This class represents an explorer window in 7plus and stores data about it.
Class CExplorerWindow
{
__New(hWnd, Path="")
{
this.hWnd := hWnd
this.Path := Path ? Path : Navigation.GetPath(hWnd)
this.DisplayName := Navigation.GetDisplayName(hWnd)
if(WinVer = WIN_7)
this.InfoGUI := new InfoGUI(hWnd)
this.Selection := Object()
this.RegisterSelectionChangedEvent()
}
RegisterSelectionChangedEvent()
{
global ExplorerWindows
if(Settings.General.DontRegisterSelectionChanged)
return
for Item in ComObjCreate("Shell.Application").Windows
{
try
{
if(Item.hWnd != this.hWnd)
continue
if(!this.Selection.COMObject) ;New explorer window
{
doc := Item.Document
if(!doc)
return 0
ComObjConnect(doc, "Explorer")
this.Selection.COMObject := doc
this.Selection.History := Array(Navigation.GetSelectedFilenames(this.hwnd))
}
else ;explorer window is already registered, lets see if its view changed
{
doc := Item.Document
if(!doc)
continue
Path := doc.Folder.Self.path
if(!Path)
continue
if(this.Path != Path) ;Compare by path since the COM wrapper objects are different
{
ComObjConnect(doc, "Explorer")
this.Selection.COMObject := doc
this.Selection.History := Array(Navigation.GetSelectedFilenames(this.hwnd)) ;Recreate array to remove selection history from previous folder
this.Path := Path
}
}
}
catch e
{
}
}
}
}