-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathQuickSwitch.ahk
1201 lines (851 loc) · 27.4 KB
/
QuickSwitch.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
$ThisVersion := "0.5"
;@Ahk2Exe-SetVersion 0.5
;@Ahk2Exe-SetName QuickSwitch
;@Ahk2Exe-SetDescription Use opened file manager folders in File dialogs.
;@Ahk2Exe-SetCopyright NotNull
/*
By : NotNull
Info : https://www.voidtools.com/forum/viewtopic.php?f=2&t=9881
*/
;_____________________________________________________________________________
;
; SETTINGS
;_____________________________________________________________________________
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#singleinstance force
; Total Commander internal codes
global cm_CopySrcPathToClip := 2029
global cm_CopyTrgPathToClip := 2030
global $DEBUG := 0
FunctionShowMenu := Func("ShowMenu")
Hotkey, ^Q, %FunctionShowMenu%, Off
; INI file ( <program name without extension>.INI)
SplitPath, A_ScriptFullPath,,,, name_no_ext
$INI := name_no_ext . ".ini"
name_no_ext := ""
; Path to tempfilefor Directory Opus
EnvGet, _tempfolder, TEMP
_tempfile := _tempfolder . "\dopusinfo.xml"
FileDelete, %_tempfile%
;_____________________________________________________________________________
;
; ACTION!
;_____________________________________________________________________________
;
; Check if Win7 or higher; if not: exit
; If !(RegExMatch(A_OSVersion, "^10\."))
;WIN_7,WIN_8,WIN_8.1,WIN_VISTA,WIN_2003,WIN_XP,WIN_2000
If A_OSVersion in WIN_VISTA,WIN_2003,WIN_XP,WIN_2000
{
MsgBox %A_OSVersion% is not supported.
ExitApp
}
loop
{
WinWaitActive, ahk_class #32770
;_____________________________________________________________________________
;
; DIALOG ACTIVE
;_____________________________________________________________________________
;
; Get ID of dialog box
$WinID := WinExist("A")
$DialogType := SmellsLikeAFileDialog($WinID)
If $DialogType ; This is a supported dialog
{
; Get Windows title and process.exe of this dialog
WinGet, $ahk_exe, ProcessName, ahk_id %$WinID%
WinGetTitle, $window_title , ahk_id %$WinID%
$FingerPrint := $ahk_exe . "___" . $window_title
; Check if FingerPrint entry is already in INI, so we know what to do.
IniRead, $DialogAction, %$INI%, Dialogs, %$FingerPrint%
If ($DialogAction = 1 ) ; ======= AutoSwitch ==
{
$FolderPath := Get_Zfolder($WinID)
If ( ValidFolder( $FolderPath ))
{
; FeedDialog($WinID, $FolderPath)
FeedDialog%$DialogType%($WinID, $FolderPath)
}
}
Else If ($DialogAction = 0 ) ; ======= Never here ==
{
; Do nothing
}
Else ; ======= Show Menu ==
{
ShowMenu()
}
; If we end up here, we checked the INI for what to do in this supported dialog and did it
; We are still in this dialog and can now enable the hotkey for manual menu-activation
; Activate the CTR-Q hotkey. When pressed, start the ShowMenu routine
Hotkey, ^Q, On
} ; End of File Dialog routine
Else ; This is a NOT supported dialog
{
; Do nothing; Not a supported dialogtype
}
sleep, 100
WinWaitNotActive
;_____________________________________________________________________________
;
; DIALOG NOT ACTIVE
;_____________________________________________________________________________
;
Hotkey, ^Q, Off
; Clean up
$WinID := ""
$ahk_exe := ""
$window_title := ""
$ahk_exe := ""
$DialogAction := ""
$DialogType := ""
$FolderPath := ""
$DialogType := ""
;_____________________________________________________________________________
;
} ; End of continuous WinWaitActive / WinWaitNotActive loop
;_____________________________________________________________________________
MsgBox We never get here (and that's how it should be)
ExitApp
;=============================================================================
;=============================================================================
;=============================================================================
;
; SUBROUTINES AND FUNCTIONS
;
;=============================================================================
;=============================================================================
;=============================================================================
;_____________________________________________________________________________
;
SmellsLikeAFileDialog(_thisID )
;_____________________________________________________________________________
;
{
; Only consider this dialog a possible file-dialog when:
; (SysListView321 AND ToolbarWindow321) OR (DirectUIHWND1 AND ToolbarWindow321) controls detected
; First is for Notepad++; second for all other filedialogs
; That is our rough detection of a File dialog. Returns 1 or 0 (TRUE/FALSE)
WinGet, _controlList, ControlList, ahk_id %_thisID%
Loop, Parse, _controlList, `n
{
If ( A_LoopField = "SysListView321" )
_SysListView321 := 1
If ( A_LoopField = "ToolbarWindow321")
_ToolbarWindow321 := 1
If ( A_LoopField = "DirectUIHWND1" )
_DirectUIHWND1 := 1
If ( A_LoopField = "Edit1" )
_Edit1 := 1
}
If ( _DirectUIHWND1 and _ToolbarWindow321 and _Edit1 )
{
Return "GENERAL"
}
Else If ( _SysListView321 and _ToolbarWindow321 and _Edit1 )
{
Return "SYSLISTVIEW"
}
else
{
Return FALSE
}
}
;_____________________________________________________________________________
;
FeedDialogGENERAL( _thisID, _thisFOLDER )
;_____________________________________________________________________________
;
{
Global $DialogType
WinActivate, ahk_id %_thisID%
sleep 50
; Focus Edit1
ControlFocus Edit1, ahk_id %_thisID%
WinGet, ActivecontrolList, ControlList, ahk_id %_thisID%
Loop, Parse, ActivecontrolList, `n ; which addressbar and "Enter" controls to use
{
If InStr(A_LoopField, "ToolbarWindow32")
{
; ControlGetText _thisToolbarText , %A_LoopField%, ahk_id %_thisID%
ControlGet, _ctrlHandle, Hwnd,, %A_LoopField%, ahk_id %_thisID%
; Get handle of parent control
_parentHandle := DllCall("GetParent", "Ptr", _ctrlHandle)
; Get class of parent control
WinGetClass, _parentClass, ahk_id %_parentHandle%
If InStr( _parentClass, "Breadcrumb Parent" )
{
_UseToolbar := A_LoopField
}
If Instr( _parentClass, "msctls_progress32" )
{
_EnterToolbar := A_LoopField
}
}
; Start next round clean
_ctrlHandle := ""
_parentHandle := ""
_parentClass := ""
}
If ( _UseToolbar AND _EnterToolbar )
{
Loop, 5
{
SendInput ^l
sleep 100
; Check and insert folder
ControlGetFocus, _ctrlFocus,A
If ( InStr( _ctrlFocus, "Edit" ) AND ( _ctrlFocus != "Edit1" ) )
{
Control, EditPaste, %_thisFOLDER%, %_ctrlFocus%, A
ControlGetText, _editAddress, %_ctrlFocus%, ahk_id %_thisID%
If (_editAddress = _thisFOLDER )
{
_FolderSet := TRUE
}
}
; else: Try it in the next round
; Start next round clean
_ctrlFocus := ""
_editAddress := ""
} Until _FolderSet
If (_FolderSet)
{
; Click control to "execute" new folder
ControlClick, %_EnterToolbar%, ahk_id %_thisID%
; Focus file name
Sleep, 15
ControlFocus Edit1, ahk_id %_thisID%
}
Else
{
; What to do if folder is not set?
}
}
Else ; unsupported dialog. At least one of the needed controls is missing
{
MsgBox This type of dialog can not be handled (yet).`nPlease report it!
}
; Clean up; probably not needed
_UseToolbar := ""
_EnterToolbar := ""
_editAddress := ""
_FolderSet := ""
_ctrlFocus := ""
Return
}
;_____________________________________________________________________________
;
FeedDialogSYSLISTVIEW( _thisID, _thisFOLDER )
;_____________________________________________________________________________
;
{
Global $DialogType
WinActivate, ahk_id %_thisID%
; Sleep, 50
; Read the current text in the "File Name:" box (= $OldText)
ControlGetText _oldText, Edit1, ahk_id %_thisID%
Sleep, 20
; Make sure there exactly 1 \ at the end.
_thisFOLDER := RTrim( _thisFOLDER , "\")
_thisFOLDER := _thisFOLDER . "\"
Loop, 20
{
Sleep, 10
ControlSetText, Edit1, %_thisFOLDER%, ahk_id %_thisID%
ControlGetText, _Edit1, Edit1, ahk_id %_thisID%
If ( _Edit1 = _thisFOLDER )
_FolderSet := TRUE
} Until _FolderSet
If _FolderSet
{
Sleep, 20
ControlFocus Edit1, ahk_id %_thisID%
ControlSend Edit1, {Enter}, ahk_id %_thisID%
; Restore original filename / make empty in case of previous folder
Sleep, 15
ControlFocus Edit1, ahk_id %_thisID%
Sleep, 20
Loop, 5
{
ControlSetText, Edit1, %_oldText%, ahk_id %_thisID% ; set
Sleep, 15
ControlGetText, _2thisCONTROLTEXT, Edit1, ahk_id %_thisID% ; check
If ( _2thisCONTROLTEXT = _oldText )
Break
}
}
Return
}
;_____________________________________________________________________________
;
ShowMenu()
;_____________________________________________________________________________
;
{
Global $DialogType
Global $DialogAction
Global _tempfile
_showMenu := 0
; ---------------[ Title BAr ]--------------------------------------
Menu ContextMenu, Add, QuickSwitch Menu, Dummy
Menu ContextMenu, Default, QuickSwitch Menu
Menu ContextMenu, disable, QuickSwitch Menu
WinGet, _allWindows, list
Loop, %_allWindows%
{
_thisID := _allWindows%A_Index%
WinGetClass, _thisClass, ahk_id %_thisID%
;---------------[ Total Commander Folders]--------------------------------------
If ( _thisClass = "TTOTAL_CMD")
{
; Get Process information for TC icon
WinGet, _thisPID, PID, ahk_id %_thisID%
_TC_exe := GetModuleFileNameEx( _thisPID )
ClipSaved := ClipboardAll
Clipboard := ""
SendMessage 1075, %cm_CopySrcPathToClip%, 0, , ahk_id %_thisID%
; Check if valid folder first. Only add it if it is.
If (ErrorLevel = 0) AND ( ValidFolder( clipboard ) )
{
Menu ContextMenu, Add, %clipboard%, FolderChoice
Menu ContextMenu, Icon, %clipboard%, %_TC_exe%,0, 32
_showMenu := 1
}
SendMessage 1075, %cm_CopyTrgPathToClip%, 0, , ahk_id %_thisID%
If (ErrorLevel = 0) AND ( ValidFolder( clipboard ) )
{
Menu ContextMenu, Add, %clipboard%, FolderChoice
Menu ContextMenu, Icon, %clipboard%, %_TC_exe%,0,32
_showMenu := 1
}
Clipboard := ClipSaved
ClipSaved := ""
}
;---------------[ XYPlorer ]--------------------------------------
If ( _thisClass = "ThunderRT6FormDC")
{
; Get Process information for TC icon
WinGet, _thisPID, PID, ahk_id %_thisID%
_XYPlorer_exe := GetModuleFileNameEx( _thisPID )
ClipSaved := ClipboardAll
Clipboard := ""
Send_XYPlorer_Message(_thisID, "::copytext get('path', a);")
; Check if valid folder first. Only add it if it is.
If (ErrorLevel = 0) AND ( ValidFolder( clipboard ))
{
Menu ContextMenu, Add, %clipboard%, FolderChoice
Menu ContextMenu, Icon, %clipboard%, %_XYPlorer_exe%,0, 32
_showMenu := 1
}
Send_XYPlorer_Message(_thisID, "::copytext get('path', i);")
If (ErrorLevel = 0) AND ( ValidFolder( clipboard ))
{
Menu ContextMenu, Add, %clipboard%, FolderChoice
Menu ContextMenu, Icon, %clipboard%, %_XYPlorer_exe%,0,32
_showMenu := 1
}
Clipboard := ClipSaved
ClipSaved := ""
}
;---------------[ Directory Opus ]--------------------------------------
If ( _thisClass = "dopus.lister")
{
; Get Process information for Opus icon
WinGet, _thisPID, PID, ahk_id %_thisID%
_dopus_exe := GetModuleFileNameEx( _thisPID )
If !(OpusInfo)
{
; Comma needs escaping: `,
Run, "%_dopus_exe%\..\dopusrt.exe" /info "%_tempfile%"`,paths,,, $DUMMY
Sleep, 100
FileRead, OpusInfo, %_tempfile%
Sleep, 20
FileDelete, %_tempfile%
}
; Get active path of this lister (regex instead of XML library)
RegExMatch(OpusInfo, "mO)^.*lister=\""" . _thisID . "\"".*tab_state=\""1\"".*\>(.*)\<\/path\>$", out)
_thisFolder := out.Value(1)
; Check if valid folder first. Only add it if it is.
If ValidFolder( _thisFolder )
{
Menu ContextMenu, Add, %_thisFolder%, FolderChoice
Menu ContextMenu, Icon, %_thisFolder%, %_dopus_exe%,0, 32
_showMenu := 1
}
_thisFolder := ""
; Get passive path of this lister
RegExMatch(OpusInfo, "mO)^.*lister=\""" . _thisID . "\"".*tab_state=\""2\"".*\>(.*)\<\/path\>$", out)
_thisFolder := out.Value(1)
; Check if valid folder first. Only add it if it is.
If ValidFolder( _thisFolder )
{
Menu ContextMenu, Add, %_thisFolder%, FolderChoice
Menu ContextMenu, Icon, %_thisFolder%, %_dopus_exe%,0, 32
_showMenu := 1
}
_thisFolder := ""
}
;---------------[ File Explorer Folders ]----------------------------------------
If ( _thisClass = "CabinetWClass")
{
For _Exp in ComObjCreate("Shell.Application").Windows
{
try ; Attempts to execute code.
{
_checkID := _Exp.hwnd
}
catch e ; Handles the errors that Opus will generate.
{
; Do nothing. Just ignore error.
; Proceed to the next Explorer instance
}
If ( _thisID = _checkID )
{
_thisExplorerPath := _Exp.Document.Folder.Self.Path
; Check if valid folder first. Don't add it if not.
If ( ValidFolder(_thisExplorerPath))
{
Menu ContextMenu, Add, %_thisExplorerPath%, FolderChoice
Menu ContextMenu, Icon, %_thisExplorerPath%, shell32.dll, 5,32
_showMenu := 1
}
}
_checkID := ""
}
}
} ; end loop parsing all windows to find file manager folders
; All windows have been checked for valid File Manager folders
; Most recent used filemanager will be shown on top.
; If no folders found to be shown: no need to show menu ...
If ( _showMenu = 1 )
{
;---------------[ Settings ]----------------------------------------
Menu ContextMenu, Add,
Menu ContextMenu, Add, Settings for this dialog, Dummy
Menu ContextMenu, disable, Settings for this dialog
Menu ContextMenu, Add, Allow AutoSwitch, AutoSwitch, Radio
Menu ContextMenu, Add, Never here, Never, Radio
Menu ContextMenu, Add, Not now, ThisMenu, Radio
; Activate radiobutton for current setting (depends on INI setting)
; Only show AutoSwitchException if AutoSwitch is activated.
If ($DialogAction = 1)
{
Menu ContextMenu, Check, Allow AutoSwitch
Menu ContextMenu, Add, AutoSwitch exception, AutoSwitchException
}
Else If ($DialogAction = 0)
{
Menu ContextMenu, Check, Never here
}
Else
{
Menu ContextMenu, Check, Not now
}
Menu ContextMenu, Add, Debug this dialog, Debug_Controls
;---------------[ Show ]----------------------------------------
; Menu ContextMenu, Standard
; BAckup to prevent errors
Menu ContextMenu, UseErrorLevel
Menu ContextMenu, Color, C0C59C
Menu ContextMenu, Show, 100,100
Menu ContextMenu, Delete
}
else
{
Menu ContextMenu, Delete
}
; Delete _tempfile
Return
}
;_____________________________________________________________________________
;
FolderChoice:
;_____________________________________________________________________________
;
{
Global $DialogType
If ValidFolder( A_ThisMenuItem )
{
; FeedDialog($WinID, $FolderPath)
FeedDialog%$DialogType%($WinID, A_ThisMenuItem)
}
Return
}
;_____________________________________________________________________________
;
AutoSwitch:
;_____________________________________________________________________________
;
Global $DialogType
IniWrite, 1, %$INI%, Dialogs, %$FingerPrint%
$DialogAction := 1
$FolderPath := Get_Zfolder($WinID)
If ( ValidFolder( $FolderPath ))
{
; FeedDialog($WinID, $FolderPath)
FeedDialog%$DialogType%($WinID, $FolderPath)
}
$FolderPath := ""
Return
;_____________________________________________________________________________
;
Never:
;_____________________________________________________________________________
;
IniWrite, 0, %$INI%, Dialogs, %$FingerPrint%
$DialogAction := 0
Return
;_____________________________________________________________________________
;
ThisMenu:
;_____________________________________________________________________________
;
IniDelete, %$INI%, Dialogs, %$FingerPrint%
$DialogAction := ""
Return
;_____________________________________________________________________________
;
AutoSwitchException:
;_____________________________________________________________________________
;
Global $DialogType
MsgBox, 1, AutoSwitch Exceptions,
(
For AutoSwitch to work, typically a file manager is "2 windows away" :
File manager ==> Aapplication ==> Dialog.
AutoSwitch uses that fore deteceting when to switch folders.
If AutoSwitch doesn't work as expected, the application might have
created extra (possibly even hidden) windows
Example: File manager==> Task Manager ==> Run new task ==> Browse
==> Dialog .
To support these dialogs too:
- Click Cancel in this Dialog
- Alt-Tab to the file manager
- Alt-Tab back to the file dialog
- Press Control-Q
- Select AutoSwitch Exception
- Press OK
The correct number of "windows away" will be detected and shown
If these values are accepted, an exception will be added for this dialog.
- Press OK if all looks OK
(most common exception is 3; default is 2)
)
IfMsgBox OK
{
; Header for list
Gui, Add, ListView, r30 w1024, Nr|ID|Window Title|program|Class
WinGet, id, list
Loop, %id%
{
this_id := id%A_Index%
WinGetClass, this_class, ahk_id %this_id%
WinGet, this_exe, ProcessName, ahk_id %this_id%
WinGetTitle, this_title , ahk_id %this_id%
If ( this_id = $WinID )
{
$select := "select"
level_1 := A_Index
Z_exe := this_exe
Z_title := this_title
}
If (NOT level_2) AND ( ( this_class = "TTOTAL_CMD" ) OR ( this_class = "CabinetWClass" ) OR ( this_class = "ThunderRT6FormDC" ))
{
$select := "select"
level_2 := A_Index
}
LV_Add( $select, A_Index, This_id, this_title, this_exe, this_class )
$select := ""
}
Delta := level_2 - level_1
LV_ModifyCol() ; Auto-size each column to fit its contents.
LV_ModifyCol(1, "Integer") ; For sorting purposes, indicate that column 1 is an integer.
Gui, Show
; Handle case when no file manager found (no Level2)
MsgBox, 1, "File manager found ..", It looks like the filemanager is %Delta% levels away `n(default = 2)`n`nMAke this the new default for this specific dialog window?
IfMsgBox OK
{
If ( Delta = 2 )
{
IniDelete, %$INI%, AutoSwitchException, %$FingerPrint%
} Else
{
IniWrite, %Delta%, %$INI%, AutoSwitchException, %$FingerPrint%
}
; After INI was updated: try to AutoSwich straight away ..
$FolderPath := Get_Zfolder($WinID)
If ( ValidFolder( $FolderPath ))
{
; FeedDialog($WinID, $FolderPath)
FeedDialog%$DialogType%($WinID, $FolderPath)
}
}
GUI, Destroy
id := ""
this_class := ""
this_exe := ""
this_id := ""
this_title := ""
$select := ""
level_1 := ""
Z_exe := ""
Z_title := ""
level_2 := ""
Delta := ""
$select := ""
}
Return
;_____________________________________________________________________________
;
Dummy:
;_____________________________________________________________________________
;
Return
;_____________________________________________________________________________
;
ValidFolder(_thisPath_)
;_____________________________________________________________________________
;
{
; Prepared for extra checks
; If ( _thisPath_ != "") {
If ( _thisPath_ != "" AND (StrLen(_thisPath_) < 259 ))
{
If InStr(FileExist(_thisPath_), "D")
Return TRUE
Else
Return FALSE
}
Else
{
Return FALSE
}
}
;_____________________________________________________________________________
;
Get_Zfolder( _thisID_ )
;_____________________________________________________________________________
;
{
; Get z-order of all applicatiions.
; When "our" ID is found: save z-order of "the next one"
; Actualy: The next-next one as the next one is the parent-program that opens the dialog (e.g. notepad )
; if the next-next one is a file mananger (Explorer class = CabinetWClass ; TC = TTOTAL_CMD),
; read the active folder and browse to it in the dialog.
; Exceptions are in INI section [AutoSwitchException]
Global $FingerPrint
Global $INI
Global _tempfile
; Read Z-Order for this application (based on $Fingerprint)
; from INI section [AutoSwitchException]
; If not found, use default ( = 2)
IniRead, _zDelta, %$INI%, AutoSwitchException, %$FingerPrint%, 2
WinGet, id, list
Loop, %id%
{
this_id := id%A_Index%
If ( _thisID_ = this_id )
{
this_z := A_Index
Break
}
}
$next := this_z + _zDelta
next_id := id%$next%
WinGetClass, next_class, ahk_id %next_id%
If ( next_class = "TTOTAL_CMD" ) ; Total Commander
{
ClipSaved := ClipboardAll
Clipboard := ""
SendMessage 1075, %cm_CopySrcPathToClip%, 0, , ahk_id %next_id%
If (ErrorLevel = 0)
{
$ZFolder := clipboard
Clipboard := ClipSaved
}
}
If ( next_class = "ThunderRT6FormDC" ) ; XYPlorer
{
ClipSaved := ClipboardAll
Clipboard := ""
Send_XYPlorer_Message( next_id, "::copytext get('path', a);")
ClipWait,0
$ZFolder := clipboard
Clipboard := ClipSaved
}
If ( next_class = "CabinetWClass" ) ; File Explorer
{
For $Exp in ComObjCreate("Shell.Application").Windows
{
try ; Attempts to execute code.
{
_checkID := $Exp.hwnd
}
catch e ; Handles the errors that Opus will generate.
{
; Do nothing. Just ignore error.
; Proceed to the next Explorer instance
}
; if ( $Exp.hwnd = next_id )
if ( next_id = _checkID )
{
$ZFolder := $Exp.Document.Folder.Self.Path
Break
}
}
}
If ( next_class = "dopus.lister" ) ; Directory Opus
{
; Get dopus.exe loction
WinGet, _thisPID, PID, ahk_id %next_id%
_dopus_exe := GetModuleFileNameEx( _thisPID )
; Get lister info
Run, "%_dopus_exe%\..\dopusrt.exe" /info "%_tempfile%"`,paths,,, $DUMMY
Sleep, 100
FileRead, OpusInfo, %_tempfile%