|
| 1 | +; Easy Access to Currently Opened Folders |
| 2 | +; Original author: Savage |
| 3 | +; - Fork by Leeroy |
| 4 | +; -- Fork by Valentin |
| 5 | +; Invoke a menu of currently opened folders when you click |
| 6 | +; the middle mouse button inside Open / Save as dialogs or |
| 7 | +; Console (command prompt) windows. Select one of these |
| 8 | +; locations and the script will navigate there. |
| 9 | + |
| 10 | +; CONFIG: CHOOSE A DIFFERENT HOTKEY |
| 11 | +; You could also use a modified mouse button (such as ^MButton) or |
| 12 | +; a keyboard hotkey. In the case of MButton, the tilde (~) prefix |
| 13 | +; is used so that MButton's normal functionality is not lost when |
| 14 | +; you click in other window types, such as a browser. |
| 15 | + |
| 16 | +; Middle-click like original script by Savage |
| 17 | +f_Hotkey = ~MButton |
| 18 | +; Ctrl+G like in Listary |
| 19 | +f_HotkeyCombo = ~^g |
| 20 | + |
| 21 | +; END OF CONFIGURATION SECTION |
| 22 | +; Do not make changes below this point unless you want to change |
| 23 | +; the basic functionality of the script. |
| 24 | + |
| 25 | +#NoTrayIcon |
| 26 | +#SingleInstance, force ; Needed since the hotkey is dynamically created. |
| 27 | + |
| 28 | +global currentPathExplorer |
| 29 | + |
| 30 | +; Auto-execute section. |
| 31 | +Hotkey, %f_Hotkey%, f_DisplayMenu |
| 32 | +Hotkey, %f_HotkeyCombo%, f_DisplayMenu |
| 33 | +return |
| 34 | + |
| 35 | +GetActiveExplorer() { |
| 36 | + static objShell := ComObjCreate("Shell.Application") |
| 37 | + WinHWND := WinActive("A") ; Active window |
| 38 | + for Item in objShell.Windows |
| 39 | + if (Item.HWND = WinHWND) |
| 40 | + return Item ; Return active window object |
| 41 | + return -1 ; No explorer windows match active window |
| 42 | +} |
| 43 | + |
| 44 | +NavRun(Path) { |
| 45 | + if (-1 != objIE := GetActiveExplorer()) |
| 46 | + objIE.Navigate(Path) |
| 47 | + ;else |
| 48 | + ;Run, % Path |
| 49 | +} |
| 50 | + |
| 51 | +; Navigate to the chosen path |
| 52 | +f_Navigate: |
| 53 | +; Set destination path to be the selected menu item |
| 54 | +f_path = %A_ThisMenuItem% |
| 55 | + |
| 56 | +if f_path = |
| 57 | + return |
| 58 | + |
| 59 | +if f_class = #32770 ; It's a dialog. |
| 60 | +{ |
| 61 | + ; Activate the window so that if the user is middle-clicking |
| 62 | + ; outside the dialog, subsequent clicks will also work: |
| 63 | + WinActivate ahk_id %f_window_id% |
| 64 | + ; Ctrl+L to convert Address bar from breadcrumbs to editbox |
| 65 | + Send ^{l} |
| 66 | + ; Wait for focus |
| 67 | + Sleep 50 |
| 68 | + ; The control that's focused after Alt+D is thus the address bar |
| 69 | + ControlGetFocus, addressbar, a |
| 70 | + ; Put in the chosen path |
| 71 | + ControlSetText %addressbar%, % f_path, a |
| 72 | + ; Go there |
| 73 | + ControlSend %addressbar%, {Enter}, a |
| 74 | + ; Return focus to filename field |
| 75 | + ControlFocus Edit1, a |
| 76 | + return |
| 77 | +} |
| 78 | + |
| 79 | +if f_class = CabinetWClass |
| 80 | +{ |
| 81 | + NavRun(f_path) |
| 82 | + return |
| 83 | +} |
| 84 | + |
| 85 | +; In a console window, pushd to that directory |
| 86 | +else if f_class = ConsoleWindowClass |
| 87 | +{ |
| 88 | + ; Because sometimes the mclick deactivates it. |
| 89 | + WinActivate, ahk_id %f_window_id% |
| 90 | + ; This will be in effect only for the duration of this thread. |
| 91 | + SetKeyDelay, 0 |
| 92 | + ; Clear existing text from prompt and send pushd command |
| 93 | + Send, {Esc}pushd "%f_path%"{Enter} |
| 94 | + return |
| 95 | +} |
| 96 | + |
| 97 | +else if f_class = VirtualConsoleClass ; Support cmder |
| 98 | +{ |
| 99 | + ; Because sometimes the mclick deactivates it. |
| 100 | + WinActivate, ahk_id %f_window_id% |
| 101 | + ; This will be in effect only for the duration of this thread. |
| 102 | + SetKeyDelay, 0 |
| 103 | + ; Clear existing text from prompt and send pushd command |
| 104 | + Send, {Esc}pushd "%f_path%"{Enter} |
| 105 | + return |
| 106 | +} |
| 107 | +return |
| 108 | + |
| 109 | + |
| 110 | +RemoveToolTip: |
| 111 | +SetTimer, RemoveToolTip, Off |
| 112 | +ToolTip |
| 113 | +return |
| 114 | + |
| 115 | +; Display the menu |
| 116 | +f_DisplayMenu: |
| 117 | +; Get active window identifiers for use in f_Navigate |
| 118 | +WinGet, f_window_id, ID, a |
| 119 | +WinGetClass, f_class, a |
| 120 | + |
| 121 | +; Don't display menu unless it's a dialog or console window |
| 122 | +if f_class not in #32770,ConsoleWindowClass,VirtualConsoleClass,CabinetWClass |
| 123 | + return |
| 124 | +; Otherwise, put together the menu |
| 125 | +WinGetTitle, currentPathExplorer, ahk_class %f_class% |
| 126 | +;msgbox, % "test " . currentPathExplorer |
| 127 | + |
| 128 | +GetCurrentPaths() { |
| 129 | + For pwb in ComObjCreate("Shell.Application").Windows |
| 130 | + ; Exclude special locations like Computer, Recycle Bin, Search Results |
| 131 | + If InStr(pwb.FullName, "explorer.exe") && InStr(pwb.LocationURL, "file:///") && pwb.document.folder.self.path != currentPathExplorer |
| 132 | + { |
| 133 | + ;msgbox, % "path: " . pwb.document.folder.self.path . " active: " . currentPathExplorer |
| 134 | + ; Get paths of currently opened Explorer windows |
| 135 | + Menu, CurrentLocations, Add, % pwb.document.folder.self.path, f_Navigate |
| 136 | + IniRead, iconpath, % pwb.document.folder.self.path . "\desktop.ini", .ShellClassInfo, IconResource |
| 137 | + |
| 138 | + ; Not same default folder icon for all (modif Val) |
| 139 | + if % iconpath != "ERROR" { |
| 140 | + icontab := StrSplit(iconpath, ",") |
| 141 | + if % icontab[2] > 0 { |
| 142 | + icontab[2] := icontab[2]+1 ; Pour contrer bug décalage icon |
| 143 | + } |
| 144 | + |
| 145 | + if StrSplit(icontab[1], ":").MaxIndex() < 2 && StrSplit(icontab[1], "%").MaxIndex() < 3 { ; Pas de ":" et de "%...%" dans le path vers l'icone |
| 146 | + ;MsgBox, % "Path local au dossier " . pwb.document.folder.self.path |
| 147 | + icontab[1] := pwb.document.folder.self.path . "\" . icontab[1] |
| 148 | + } |
| 149 | + |
| 150 | + icontab[1] := StrReplace(icontab[1], "%userprofile%", USERPROFILE) ; %userprofile% non géré par autohotkey |
| 151 | + |
| 152 | + ;MsgBox, % "path " . pwb.document.folder.self.path . " " . icontab[1] . " OK " . icontab[2] . " OK " . testtt |
| 153 | + Menu, CurrentLocations, Icon, % pwb.document.folder.self.path, % icontab[1], % icontab[2] |
| 154 | + } |
| 155 | + else { |
| 156 | + Menu, CurrentLocations, Icon, % pwb.document.folder.self.path, %A_WinDir%\system32\imageres.dll, 4 |
| 157 | + } |
| 158 | + } |
| 159 | +} |
| 160 | +; Get current paths and build menu with them |
| 161 | +GetCurrentPaths() |
| 162 | +; Don't halt the show if there are no paths and the menu is empty |
| 163 | +Menu, CurrentLocations, UseErrorLevel |
| 164 | +; Present the menu |
| 165 | +Menu, CurrentLocations, Show |
| 166 | +; If it doesn't exist show reassuring tooltip |
| 167 | +If ErrorLevel |
| 168 | +{ |
| 169 | + ; Oh! Look at that taskbar. It's empty. |
| 170 | + ToolTip, No folders open |
| 171 | + SetTimer, RemoveToolTip, 1000 |
| 172 | +} |
| 173 | +; Destroy the menu so it doesn't remember previously opened windows |
| 174 | +Menu, CurrentLocations, Delete |
| 175 | +return |
0 commit comments