AutoHotkey Community

It is currently May 27th, 2012, 11:15 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Favorite Folders
PostPosted: February 28th, 2006, 5:02 pm 
Offline

Joined: February 28th, 2006, 4:38 pm
Posts: 73
There is a new version of this.
http://www.autohotkey.com/forum/topic14641.html



This is the Favorite Folders by Savage.
I added some new functions to it.

- open the menu everywhere with hotkey2.
it will open a new explorer to the folder, and click on the tray icon will display the menu as well.

- open a file.
you can add files to the menu as well as folders.

- reload hotkey.
reload the settings quickly with a hotkey.

- save settings in ini file.

http://rexx26.t35.com/FavoriteFolders.7z

Code:
; Easy Access to Favorite Folders -- by Savage
; http://www.autohotkey.com
; When you click the middle mouse button while certain types of
; windows are active, this script displays a menu of your favorite
; folders.  Upon selecting a favorite, the script will instantly
; switch to that folder within the active window.  The following
; window types are supported: 1) Standard file=open or file=save
; dialogs; 2) Explorer windows; 3) Console (command prompt) windows.
; The menu can also be optionally shown for unsupported window
; types, in which case the chosen favorite will be opened as a new
; Explorer window.

; Note: In Windows Explorer, if "View > Toolbars > Address Bar" is
; not enabled, the menu will not be shown if the hotkey chosen below
; has a tilde.  If it does have a tilde, the menu will be shown
; but the favorite will be opened in a new Explorer window rather
; than switching the active Explorer window to that folder.

; Do not make changes below this point unless you want to change
; the basic functionality of the script.

; Modified by rexx

;=TODO==========================================================================
; * add to favorite ; get current dir
; * submenu
;===============================================================================

#SingleInstance, Force  ; Needed since the hotkey is dynamically created.

;============================================
; Read the menu items from an external file ;
;============================================
f_ConfigFile = %A_ScriptDir%\Config.ini

;============
; Tray Menu ;
;============
Menu, Tray, Tip, &Favorite Folders
Menu, Tray, NoStandard
Menu, Tray, Add, &Favorite Folders, f_DisplayMenu2
Menu, Tray, Add
Menu, Tray, Add, &Reload, Reload
Menu, Tray, Add, &Configuration, Config
Menu, Tray, Add
Menu, Tray, Add, E&xit, Exit
Menu, Tray, default, &Favorite Folders
Menu, Tray, click, 1
Menu, Favorites, Add
Gosub, ReadConfig
IfNotExist, %A_ScriptDir%\Config.ini ;if config file doesn't exist
{
   FileInstall, D:\Default.ini, %A_ScriptDir%\Config.ini
   Reload
}
return
;End of auto execute

;-----------------
; Tray Menu Items;
;-----------------
Config:
run,%A_ScriptDir%\Config.ini
return
Exit:
Exitapp
return
Reload:
Reload
return


;==============================
; Read the configuration file ;
;==============================
;----------
ReadConfig:
;----------
Gosub ReadHotkeys
f_ReadSection = 0
f_MenuItemCount = 0
Menu, Favorites, delete
Loop, Read, %f_ConfigFile%
{
   StringLeft, A_LoopReadLineFirstChar, A_LoopReadLine, 1 ; Skip comments
   if A_LoopReadLineFirstChar = `;
      continue
   if f_ReadSection = 0
   {
      IfInString, A_LoopReadLine, [Favorites] ; Favorites Section
         f_ReadSection = F
      else
         continue ; Start a new loop iteration.
   }
   else if f_ReadSection = F
      Gosub ReadFavorites
}
Menu, Favorites, Add
Menu, Favorites, Add, &Configuration, Config
return

;-----------
ReadHotkeys:
;-----------
IniRead, f_Hotkey1, %f_ConfigFile%, Hotkeys, Hotkey1
IniRead, f_Hotkey2, %f_ConfigFile%, Hotkeys, Hotkey2
IniRead, f_HotkeyR, %f_ConfigFile%, Hotkeys, Reload
Hotkey, %f_Hotkey1%, f_DisplayMenu, UseErrorLevel
if ErrorLevel in 2,3,4,5,6
   TrayTip, , No Hotkey1
Hotkey, %f_Hotkey2%, f_DisplayMenu2, UseErrorLevel
if ErrorLevel in 2,3,4,5,6
   TrayTip, , No Hotkey2
Hotkey, %f_HotkeyR%, Reload, UseErrorLevel
if ErrorLevel in 2,3,4,5,6
   TrayTip, , No Reload Hotkey
return

;-------------
ReadFavorites:
;-------------
; Menu separator lines must also be counted to be compatible with A_ThisMenuItemPos:
f_MenuItemCount++
if A_LoopReadLine =  ; Blank indicates a separator line.
   Menu, Favorites, Add
else
{
   StringSplit, f_line, A_LoopReadLine, `=
   f_line1 = %f_line1%  ; Trim leading and trailing spaces.
   f_line2 = %f_line2%  ; Trim leading and trailing spaces.
   ; Resolve any references to variables within either field, and
   ; create a new array element containing the path of this favorite:
   Transform, f_path%f_MenuItemCount%, deref, %f_line2%
   Transform, f_line1, deref, %f_line1%
   Menu, Favorites, Add, &%f_line1%, f_OpenFavorite
}
return

;=============================
; Open the selected favorite ;
;=============================
f_OpenFavorite:
; Fetch the array element that corresponds to the selected menu item:
StringTrimLeft, f_path, f_path%A_ThisMenuItemPos%, 0
if f_path =
   return
if f_class = #32770    ; It's a dialog.
{
   if f_Edit1Pos <>   ; And it has an Edit1 control.
   {
      ; Activate the window so that if the user is middle=clicking
      ; outside the dialog, subsequent clicks will also work:
      WinActivate ahk_id %f_window_id%
      ; Retrieve any filename that might already be in the field so
      ; that it can be restored after the switch to the new folder:
      ControlGetText, f_text, Edit1, ahk_id %f_window_id%
      ControlSetText, Edit1, %f_path%, ahk_id %f_window_id%
      ControlSend, Edit1, {Enter}, ahk_id %f_window_id%
      Sleep, 100  ; It needs extra time on some dialogs or in some cases.
      ControlSetText, Edit1, %f_text%, ahk_id %f_window_id%
      return
   }
   ; else fall through to the bottom of the subroutine to take standard action.
}
else if f_class in ExploreWClass,CabinetWClass  ; In Explorer, switch folders.
{
   if f_Edit1Pos <>   ; And it has an Edit1 control.
   {
      ControlSetText, Edit1, %f_path%, ahk_id %f_window_id%
      ; Tekl reported the following: "If I want to change to Folder L:\folder
      ; then the addressbar shows http://www.L:\folder.com. To solve this,
      ; I added a {right} before {Enter}":
      ControlSend, Edit1, {Right}{Enter}, ahk_id %f_window_id%
      return
   }
   ; else fall through to the bottom of the subroutine to take standard action.
}
else if f_class = ConsoleWindowClass ; In a console window, CD to that directory
{
   WinActivate, ahk_id %f_window_id% ; Because sometimes the mclick deactivates it.
   SetKeyDelay, 0  ; This will be in effect only for the duration of this thread.
   IfInString, f_path, :  ; It contains a drive letter
   {
      StringLeft, f_path_drive, f_path, 1
      Send %f_path_drive%:{enter}
   }
   Send, cd %f_path%{Enter}
   return
}
; Since the above didn't return, one of the following is true:
; 1) It's an unsupported window type but f_AlwaysShowMenu is y (yes).
; 2) It's a supported type but it lacks an Edit1 control to facilitate the custom
;    action, so instead do the default action below.
Run, explore %f_path%, , UseErrorLevel ; Might work on more systems without double quotes.
if ErrorLevel
   Run, %f_path%, , UseErrorLevel ;open a file if the path is not a dir
   if ErrorLevel
      TrayTip, , Error
return

;===================
; Display the menu ;
;===================
f_DisplayMenu:
; These first few variables are set here and used by f_OpenFavorite:
WinGet, f_window_id, ID, A
WinGetClass, f_class, ahk_id %f_window_id%
if f_class in #32770,ExploreWClass,CabinetWClass  ; Dialog or Explorer.
   ControlGetPos, f_Edit1Pos,,,, Edit1, ahk_id %f_window_id%
; The menu should be shown only selectively.
if f_class in #32770,ExploreWClass,CabinetWClass  ; Dialog or Explorer.
{
   if f_Edit1Pos =  ; The control doesn't exist, so don't display the menu
      return
}
else if f_class <> ConsoleWindowClass
   return ; Since it's some other window type, don't display menu.
; Otherwise, the menu should be presented for this type of window:
Menu, Favorites, show
return

f_DisplayMenu2:
; Always show the menu
f_class = ;clear the win class to open in a new explorer
Menu, Favorites, show
return

and..
anyone have ideas about how to get the dir current in use?


Last edited by rexx on April 13th, 2007, 9:40 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Favorite Folders
PostPosted: February 28th, 2006, 5:10 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
If the script is standalone (one file) and small enough, you don't need to compress it, even less to a format that is efficient, but may not be opened by all Zip managers (7-zip).
rexx wrote:
anyone have ideas about how to get the dir current in use?

Various methods, perhaps none working in all cases.
On my system, I have set the option to display the current path as title of Windows Explorer, so I just do a WinGetActiveTitle currentPath...

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2006, 7:01 pm 
Offline

Joined: December 18th, 2005, 5:40 pm
Posts: 234
Location: Italy - Galatro(RC)
your script is simple and usefull.
if you are looking for a way to enanche your mouse more, try my radialM: it makes you do millions of operations with the use of mouse only

_________________
____________________
______________________
kiu - www.romeosa.com


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], nomissenrojb, Rajat and 53 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group