AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Favorite Folders Gui

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Simpleton



Joined: 02 Nov 2004
Posts: 14

PostPosted: Sat Dec 11, 2004 4:44 am    Post subject: Favorite Folders Gui Reply with quote

EDIT: thought I'd add a screenshot of the actual gui so you know what I'm talking about



I made this gui for changing Favorite Folders on the fly awhile ago.
Since there seems to be a lot of interest in Favorite Folders, and a very large number of different versions, I went ahead and packaged it all up to make it easy to integrate into any Favorite Folders variation.

The script is a set of subroutines in a file called FavoriteFoldersGui.ahk (you can change it if you want, but the name is important, so remember it). You then #include it at the bottom of your script and then call a sub to start it.

A more complete readme is in the comments at the top of the file.

Anyways, here it is:

Code:

; FavoriteFoldersGui.ahk
; AutoHotkey Version: 1.0.24 or latest 1.0.23
; Language:       English
; Platform:       Windows XP for sure, nothing else tested.
; Author:         Matt (Simpleton) Edlefsen <medlefsen@hotmail.com>
;
; Script Function:
;   Gui to change Favorite Folders on the fly
;
; Script Use:
; #include this somewhere after the autoexec part.
; Personally I would reccomend the very end of your script for safety.
;
; Your favorite folders list must be stored in variables with the following format:
; <Path Prefix>1 = <favorite folder path>
; <Label Prefix>1 = <favorite folder label>
;
; <Path Prefix>2 = <favorite folder path>
; <Label Prefix>2 = <favorite folder label>
;
; <Path Prefix>3 = <favorite folder path>
; <label Prefix>3 = <favorite folder label>
;
; ...
; <Path Prefix>X = <favorite folder path>
; <Label Prefix>X = <favorite folder label>
;
; <Length Variable> = X
;
; Then to load the Gui just set f_GuiPathSource to whatever <Path Prefix>,
; f_GuiLableSource to <Lable Prefix>, and call f_GuiLoad ( GoSub, f_GuiLoad ).
;
; Example:
;
; path1 = C:\
; label1 = C:
;
; path2 = C:\Program Files\
; label2 = Program Files
;
; MenuSize = 2
;
; f_GuiPathSource = path
; f_GuiLabelSource = label
; f_GuiSizeSource = MenuSize
; GoSub, f_GuiLoad
;
; f_GuiLoad will not return until the gui is closed!
; This means that anything after GoSub, f_GuiLoad will not be run until
; the gui has been closed.
;
; When the Gui is Submitted (Clicked OK) your variables will be updated with
; the new values.
; Your variables will NOT be altered if the dialog is canceled or killed in
; any other way besides hitting the OK button.
;
;
; If you run into any bugs in the Gui just email me or reply to a board message
; of mine. At the very least I'll update this documentation with those bug reports
; even if they don't get fixed.
;

f_GuiCreate:
  f_GuiCreated = 1
  f_GuiX =
  f_GuiY =
  f_GuiH = 320
  f_GuiW = 550
  f_GuiButtonXBuffer = 108
  f_GuiButtonYBuffer = 37
  f_GuiAddXBuffer = 27
  f_GuiGroupBoxX = 8
  f_GuiGroupBoxY = 8
  f_GuiButtonY = %f_GuiH%
  f_GuiButtonY -= %f_GuiButtonYBuffer%
  f_GuiListBoxX = 10
  f_GuiListBoxY = 30
  f_GuiListBoxW = 200
  f_GuiListBoxH = %f_GuiButtonY%
  f_GuiListBoxH -= %f_GuiListBoxY%
  f_GuiAddButtonW = 100
  f_GuiCancelX = %f_GuiW%
  f_GuiCancelX -= %f_GuiButtonXBuffer%
  f_GuiOkX = %f_GuiCancelX%
  f_GuiOkX -= %f_GuiButtonXBuffer%
  f_GuiFolderWidth = 26
  f_GuiLabelWidth = %f_GuiAddButtonW%
  f_GuiLabelWidth *= 2
  f_GuiLabelWidth += %f_GuiAddXBuffer%
  f_GuiUpButtonH = 28
  f_GuiUpButtonW = 50
  f_GuiUpButtonBuffer = 2
  f_GuiUpButtonY = %f_GuiListBoxH%
  f_GuiUpButtonY /= 2
  f_GuiUpButtonY -= %f_GuiUpButtonH%
  f_GuiUpButtonY -= %f_GuiUpButtonBuffer%
  f_GuiUpButtonBuffer *= 2
  Gui, Add, Text, y10,Favorites Menu:
  Gui, Add, ListBox, x%f_GuiListBoxX% y%f_GuiListBoxY% w%f_GuiListBoxW% h280 vf_GuiListBox Gf_GuiListBoxSelect AltSubmit, |
  Gui, Add, Button, x+0 yp+%f_GuiUpButtonY% h%f_GuiUpButtonH% w%f_GuiUpButtonW% Gf_GuiUpPush, Up
  Gui, Add, Button, xp+0 y+%f_GuiUpButtonBuffer%  h%f_GuiUpButtonH% w%f_GuiUpButtonW% Gf_GuiDownPush, Down
  Gui, Add, Button, Section x+%f_GuiAddXBuffer% y%f_GuiListBoxY% w%f_GuiAddButtonW% h28 Gf_GuiAddPush, Add Entry
  Gui, Add, Button, x+%f_GuiAddXBuffer% y%f_GuiListBoxY% w%f_GuiAddButtonW% h28 Gf_GuiRemovePush, Remove Entry
  Gui, Add, Text, xs0 ys+60, Label:
  Gui, Add, Edit, xs0 w%f_GuiLabelWidth% vf_GuiLabel
  Gui, Add, Text, xs0 y+20, Path:
  Gui, Add, Edit, xs0 w%f_GuiLabelWidth% vf_GuiPath
  Gui, Add, Button, x+6 yp0 w%f_GuiFolderWidth% h24 Gf_GuiFolderSelect, ...
  Gui, Add, Button, xs0 y+10 h28 Gf_GuiResetPush, Reset
  Gui, Add, Button, x%f_GuiOkX% y%f_GuiButtonY% w100 h28 Gf_GuiOkPush, OK
  Gui, Add, Button, x%f_GuiCancelX% y%f_GuiButtonY% w100 h28 Gf_GuiCancelPush, Cancel
return

f_GuiLoad:
  if f_GuiCreated <> 1
  {
    GoSub, f_GuiCreate
  }
  Transform, f_GuiListBoxNumber, deref, `%%f_GuiSizeSource%`%
  loop, %f_GuiListBoxNumber%
  {
    Transform, f_GuiListBoxLabel%A_Index%, deref, `%%f_GuiLabelSource%%A_Index%`%
    Transform, f_GuiListBoxPath%A_Index%, deref, `%%f_GuiPathSource%%A_Index%`%
  }
  Gui, Show, x%f_GuiX% y%f_GuiY% h%f_GuiH% w%f_GuiW%, FavoriteFolders Settings
  GoSub, f_GuiUpdateListBox
  f_GuiDone = 0
  loop
  {
    if f_GuiDone = 1
    {
      break
    }
  }
return

f_GuiSave:
  GoSub, f_GuiGetText
  loop, %f_GuiListBoxNumber%
  {
    Transform, %f_GuiLabelSource%%A_Index%, deref, `%f_GuiListBoxLabel%A_Index%`%
    Transform, %f_GuiPathSource%%A_Index%, deref, `%f_GuiListBoxPath%A_Index%`%
  }
  %f_GuiSizeSource% = %f_GuiListBoxNumber%
return

f_GuiResetPush:
  GuiControlGet, f_GuiListBoxSelected,,f_GuiListBox
  GoSub, f_GuiUpdateListBox
  GoSub, f_GuiListBoxLoad
return

f_GuiFolderSelect:
  if f_GuiListBoxSelected <>
  {
    GuiControlGet, f_GuiLabel,, f_GuiLabel
    GuiControlGet, f_GuiPath,, f_GuiPath
    if f_GuiLabel <>
    {
      Transform, f_GuiPathAbs, Deref, %f_GuiPath%
      FileSelectFolder, f_GuiPathNew,, 3, Select FavoriteFolder for Label %f_GuiLabel%
      if f_GuiPathNew <>
      {
        GuiControl,, f_GuiPath, %f_GuiPathNew%
      }
    }
  }
return

f_GuiListBoxSelect:
GoSub, f_GuiGetText
GuiControlGet, f_GuiListBoxSelected,,f_GuiListBox
GoSub, f_GuiUpdateListBox
GoSub, f_GuiListBoxLoad
return

f_GuiListBoxLoad:
  Transform, f_GuiListBoxLabelSelected, Deref, `%f_GuiListBoxLabel%f_GuiListBoxSelected%`%
  Transform, f_GuiListBoxPathSelected, Deref, `%f_GuiListBoxPath%f_GuiListBoxSelected%`%
  GuiControl,, f_GuiLabel, %f_GuiListBoxLabelSelected%
  GuiControl,, f_GuiPath, %f_GuiListBoxPathSelected%
  GuiControl, Focus, f_GuiLabel
return

f_GuiAddPush:
  GoSub, f_GuiGetText
  GuiControlGet, f_GuiListBoxSelected,,f_GuiListBox
  if f_GuiListBoxSelected <>
  {
    f_GuiListBoxNumber++
    f_GuiListBoxNumberloop = %f_GuiListBoxNumber%
    f_GuiListBoxNumberloop -= %f_GuiListBoxSelected%
    loop, %f_GuiListBoxNumberloop%
    {
      f_GuiNewListBoxNumber = %f_GuiListBoxNumber%
      f_GuiNewListBoxNumber -= %A_Index%
      Transform, f_GuiListBoxLabelCurrent, Deref, `%f_GuiListBoxLabel%f_GuiNewListBoxNumber%`%
      Transform, f_GuiListBoxPathCurrent, Deref, `%f_GuiListBoxPath%f_GuiNewListBoxNumber%`%
      f_GuiListBoxLabelCurrent = %f_GuiListBoxLabelCurrent%
      f_GuiNewListBoxNumber++
      f_GuiListBoxLabel%f_GuiNewListBoxNumber% = %f_GuiListBoxLabelCurrent%
      f_GuiListBoxPath%f_GuiNewListBoxNumber% = %f_GuiListBoxPathCurrent%
    }
  }
  else
  {
    f_GuiListBoxNumber++
    f_GuiListBoxSelected = %f_GuiListBoxNumber%
  }
  f_GuiListBoxLabel%f_GuiListBoxSelected% = New Label
  f_GuiListBoxPath%f_GuiListBoxSelected% =
  GoSub, f_GuiUpdateListBox
  GuiControl, Choose, f_GuiListBox, %f_GuiListBoxSelected%
  GoSub, f_GuiListBoxLoad
return

f_GuiRemovePush:
  GoSub, f_GuiGetText

  GuiControlGet, f_GuiListBoxSelected,,f_GuiListBox
  if f_GuiListBoxSelected <>
  {
    f_GuiListBoxNumberloop = %f_GuiListBoxNumber%
    f_GuiListBoxNumberloop -= %f_GuiListBoxSelected%
    loop, %f_GuiListBoxNumberloop%
    {
      f_GuiNewListBoxNumber = %f_GuiListBoxSelected%
      f_GuiNewListBoxNumber += %A_Index%
      Transform, f_GuiListBoxLabelCurrent, Deref, `%f_GuiListBoxLabel%f_GuiNewListBoxNumber%`%
      Transform, f_GuiListBoxPathCurrent, Deref, `%f_GuiListBoxPath%f_GuiNewListBoxNumber%`%
      f_GuiListBoxLabelCurrent = %f_GuiListBoxLabelCurrent%
      f_GuiNewListBoxNumber--
      f_GuiListBoxLabel%f_GuiNewListBoxNumber% = %f_GuiListBoxLabelCurrent%
      f_GuiListBoxPath%f_GuiNewListBoxNumber% = %f_GuiListBoxPathCurrent%
    }
    if f_GuiListBox > 0
    {
      f_GuiListBoxNumber--
    }
    GoSub, f_GuiUpdateListBox
    GuiControlGet, f_GuiListBoxSelected,,f_GuiListBox
    GoSub, f_GuiListBoxLoad
  }
return

f_GuiUpPush:
  GoSub, f_GuiGetText

  GuiControlGet, f_GuiListBoxSelected,,f_GuiListBox
  if f_GuiListBoxSelected <>
  {
    if f_GuiListBoxSelected <> 1
    {
      f_GuiListBoxSelectedOther = %f_GuiListBoxSelected%
      Transform, f_GuiListBoxLabelSelected, Deref, `%f_GuiListBoxLabel%f_GuiListBoxSelected%`%
      Transform, f_GuiListBoxPathSelected, Deref, `%f_GuiListBoxPath%f_GuiListBoxSelected%`%
      f_GuiListBoxSelected--
      Transform, f_GuiListBoxLabel%f_GuiListBoxSelectedOther%, Deref, `%f_GuiListBoxLabel%f_GuiListBoxSelected%`%
      Transform, f_GuiListBoxPath%f_GuiListBoxSelectedOther%, Deref, `%f_GuiListBoxPath%f_GuiListBoxSelected%`%
      f_GuiListBoxLabel%f_GuiListBoxSelected% = %f_GuiListBoxLabelSelected%
      f_GuiListBoxPath%f_GuiListBoxSelected% = %f_GuiListBoxPathSelected%
      GoSub, f_GuiUpdateListBox
      GoSub, f_GuiListBoxLoad
    }
  }
return

f_GuiDownPush:
  GoSub, f_GuiGetText

  GuiControlGet, f_GuiListBoxSelected,,f_GuiListBox
  if f_GuiListBoxSelected <>
  {
    if f_GuiListBoxSelected <> %f_GuiListBoxNumber%
    {
      f_GuiListBoxSelectedOther = %f_GuiListBoxSelected%
      Transform, f_GuiListBoxLabelSelected, Deref, `%f_GuiListBoxLabel%f_GuiListBoxSelected%`%
      Transform, f_GuiListBoxPathSelected, Deref, `%f_GuiListBoxPath%f_GuiListBoxSelected%`%
      f_GuiListBoxSelected++
      Transform, f_GuiListBoxLabel%f_GuiListBoxSelectedOther%, Deref, `%f_GuiListBoxLabel%f_GuiListBoxSelected%`%
      Transform, f_GuiListBoxPath%f_GuiListBoxSelectedOther%, Deref, `%f_GuiListBoxPath%f_GuiListBoxSelected%`%
      f_GuiListBoxLabel%f_GuiListBoxSelected% = %f_GuiListBoxLabelSelected%
      f_GuiListBoxPath%f_GuiListBoxSelected% = %f_GuiListBoxPathSelected%
      GoSub, f_GuiUpdateListBox
      GoSub, f_GuiListBoxLoad
    }
  }
return

f_GuiOkPush:
  GoSub, f_GuiSave
  Gui, Submit
  f_GuiDone = 1
return

f_GuiCancelPush:
  Gui, Cancel
  f_GuiDone = 1
return

f_GuiClose:
  f_GuiDone = 1
return


f_GuiGetText:
if f_GuiListBoxSelected <>
{
  GuiControlGet, f_GuiLabel,, f_GuiLabel
  GuiControlGet, f_GuiPath,, f_GuiPath
  f_GuiListBoxLabel%f_GuiListBoxSelected% = %f_GuiLabel%
  if f_GuiListBoxLabel%f_GuiListBoxSelected% <>
  {
    f_GuiListBoxPath%f_GuiListBoxSelected% = %f_GuiPath%
  }
  else
  {
    f_GuiListBoxPath%f_GuiListBoxSelected% =
  }
}
return

f_GuiUpdateListBox:
GuiControl,, f_GuiListBox, |
f_GuiListBox = |
loop, %f_GuiListBoxNumber%
{
  Transform, f_GuiListBoxLabelCurrent, Deref, `%f_GuiListBoxLabel%A_Index%`%
  if f_GuiListBoxLabelCurrent =
  {
    f_GuiListBoxLabelCurrent = ----------------------------
  }
  if A_Index = 1
  {
    f_GuiListBox = |%f_GuiListBoxLabelCurrent%
  }
  else
  {
    f_GuiListBox = %f_GuiListBox%|%f_GuiListBoxLabelCurrent%
  }
  if f_GuiListBoxSelected = %A_Index%
  {
    f_GuiListBox = %f_GuiListBox%|
  }
}
if f_GuiListBoxSelected = %f_GuiListBoxNumber%
{
  f_GuiListBox = %f_GuiListBox%|
}
GuiControl,, f_GuiListBox, %f_GuiListBox%
return


While I was at it I went ahead and altered ChrisM's original version of Favorite Folders (the one with the ini) to use the gui instead of opening the ini file in notepad when Edit Favorite Folders is chosen

The changes are fairly minimal, and are marked.
Make sure to note the #include at the bottom
Code:

; Easy Access to Favorite Folders with Gui
; Original Script -- by Savage
; This Version -- by ChrisM
; FavoriteFoldersGui Compatability Edits -- by Matt (Simpleton) Edlefsen
; http://www.autohotkey.com
; Tested with version 1.0.23

; 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.

; Revisions - by ChrisM
; Two menu items always appear at the bottom:
;  - Add to Favorites - allows the user to add new menu items.
;  - Edit Favorites File - conveniently opens .ini file in editor.
; A file with the same name as this script but with .ini as an extension
; will automaticaly be created in the same directory as where this script resides.


; CONFIG: CHOOSE YOUR HOTKEY
; If your mouse has more than 3 buttons, you could try using
; XButton1 (the 4th) or XButton2 (the 5th) instead of MButton.
; You could also use a modified mouse button (such as ^MButton) or
; a keyboard hotkey.  In the case of MButton, the tilde (~) prefix
; is used so that MButton's normal functionality is not lost when
; you click in other window types, such as a browser.  The presence
; of a tilde tells the script to avoid showing the menu for
; unsupported window types.  In other words, if there is no tilde,
; the hotkey will always display the menu; and upon selecting a
; favorite while an unsupported window type is active, a new
; Explorer window will be opened to display the contents of that
; folder.
f_Hotkey = ^MButton


; CONFIG: CHOOSE YOUR EDITOR
; Specify the editor you would like to use to edit the .ini file with.
; This editor will be called when you select 'Edit Favorites File'
; from the popup menu. If not in the Path enviroment variable you will
; have to supply the full path with quotes possibly.
f_Editor = notepad.exe


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

#SingleInstance  ; Needed since the hotkey is dynamically created.

Hotkey, %f_Hotkey%, f_DisplayMenu
StringLeft, f_HotkeyFirstChar, f_Hotkey, 1
if f_HotkeyFirstChar = ~  ; Show menu only for certain window types.
   f_AlwaysShowMenu = n
else
    f_AlwaysShowMenu = y

; Get .ini filename by splitting apart this script's name.
SplitPath, A_ScriptName, , , , f_FavoritesFile
f_FavoritesFile = %f_FavoritesFile%.ini
f_FavoritesFile = %A_ScriptDir%\%f_FavoritesFile%

;----Read the configuration file.
f_AtStartingPos = n
f_MenuItemCount = 0
Loop, Read, %f_FavoritesFile%
{
   ; Search for, and skip over, comment lines ( whose first character must be # )
   f_line = %A_LoopReadLine% ; Trim leading and trailing spaces.
   StringGetPos, f_comm, f_line, #
   if f_comm = 0
      continue

   ; 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_menuName%f_MenuItemCount%, deref, %f_line1%
      Menu, Favorites, Add, %f_line1%, f_OpenFavorite
   }
}
; add another separator line.
Menu, Favorites, Add
; add a command to capture the current folder address back to the .ini file.
Menu, Favorites, Add, Add to Favorites, f_FindPath
; add a command to allow the user to edit the .ini file.
Menu, Favorites, Add, Edit Favorites File, f_EditFavorites

;If the .ini changes we reload this script to read in the new file.
SetTimer, f_UpdatedFavoritesFile, 1000

return  ;----End of auto-execute section.


;----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, Explorer %f_path%  ; Might work on more systems without double quotes.
return


;----Display the menu
f_DisplayMenu:
   ; This next variable is used to record the title of the ative window when popup menu
   ; was called. This variable is then used in f_AddToFavorites: if user wants to save it.
   WinGetActiveTitle, f_addFavorite
   
   ; 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%
   if f_AlwaysShowMenu = n  ; 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


;----Try to find a valid path from the active window title or the clipboard.
f_FindPath:
   ifExist, %f_addFavorite%
   {
      GoSub, f_AddToFavorites
      return
   }
   f_clipboard = %clipboard%
   ifExist, %f_clipboard%
   {
      f_addFavorite = %clipboard%
      GoSub, f_AddToFavorites
      return
   }
   ; Report to user that no valid path was found.
   MsgBox, No valid path was found.
return


;----Save found valid path to the .ini file.
f_AddToFavorites:
   StringLen, f_length, f_addFavorite
   f_length *= 8   
   if f_length < 340
      f_length = 340
   InputBox, f_shortName, Favorite Name, Found: %f_addFavorite%`nWhat name would you like to give the Favorite shortcut, , %f_length%, 140
   ; If CANCEL was not pressed, try to add menu item.
   if ErrorLevel <> 1
   {   
      f_shortName = %f_shortName%  ; Trim leading and trailing spaces.
      StringLower, f_test, f_shortName
      ; Loop thru existing menu items to check for duplicates.
      f_index = 0
      Loop, %f_MenuItemCount%
      {
         f_index++
         StringLower, f_nextMenu, f_menuName%f_index%
         ifEqual f_nextMenu, %f_test%
         {
            MsgBox, The name %f_shortName% is already in the menu.`nTry again.
            return
         }
      }
      ; Stop the reload timer while we update the .ini file
      SetTimer, f_UpdatedFavoritesFile, Off

      GoSub f_CreateIniFile
   
      ; Here's where we save the menu item to file.
      FileAppend, `n%f_shortName% `; %f_addFavorite%, %f_FavoritesFile%

      MsgBox, The path %f_addFavorite% has been added to favorites.

      ; Start the reload timer again
      SetTimer, f_UpdatedFavoritesFile, On
   }
return


;----Allow user to edit the .ini using the editor of their choice.
f_EditFavorites:
   ; Stop the reload timer while we update the .ini file
   SetTimer, f_UpdatedFavoritesFile, Off

;----------------------------FavoriteFoldersGui Edits---------------------------;
;                                     Old                                       ;   
;-------------------------------------------------------------------------------;
;   GoSub f_CreateIniFile                                                       
                                                                               
;   Run, %f_Editor% "%f_FavoritesFile%"                                         
;-------------------------------------------------------------------------------;
;                                     New                                       ;
;-------------------------------------------------------------------------------;
    ; Call Gui
    f_GuiPathSource = f_path
    f_GuiLabelSource = f_menuName
    f_GuiSizeSource = f_MenuItemCount
    GoSub, f_GuiLoad
   
    ; Delete Current ini file
    FileDelete, %f_FavoritesFile%
   
    ; Create new blank ini file
    GoSub, f_CreateIniFile

    ; Copy new menu list to ini file
    loop, %f_MenuItemCount%
    {
      Transform, f_current_path, deref, `%f_path%A_Index%`%
      Transform, f_current_name, deref, `%f_menuName%A_Index%`%
      FileAppend, `n%f_current_name% `; %f_current_path%, %f_FavoritesFile%
    }
;--------------------------------------------------------------------------------;

   ; Start the reload timer again
   SetTimer, f_UpdatedFavoritesFile, On
return


;----If the .ini has changed reload this script, which then rereads the .ini file.
f_UpdatedFavoritesFile:
   FileGetAttrib, f_attribs, %f_FavoritesFile%
   IfInString, f_attribs, A
   {
      FileSetAttrib, -A, %f_FavoritesFile%
      Reload
   }
return


;----If the .ini file does not exist we will create it.
f_CreateIniFile:
   ifNotExist, %f_FavoritesFile%
   {
      ; Add some helpfull comment lines about format.
      FileAppend, # Popup menu list for directory shortcuts.`n , %f_FavoritesFile%
      FileAppend, # This file was generated by %A_ScriptName%`n , %f_FavoritesFile%
      FileAppend, # You can hand edit this file if you follow these simple rules.`n ,%f_FavoritesFile%
      FileAppend, # Specify the name of the menu item first`, followed by a semicolon`,`n, %f_FavoritesFile%
      FileAppend, # followed by the actual directory path.`n, %f_FavoritesFile%
      FileAppend, # Use a blank line to create a separator line in the menu.`n,%f_FavoritesFile%
      FileAppend, # You can add comment lines`, like this one. The first character must bea '#'.`n, %f_FavoritesFile%
      FileAppend, #, %f_FavoritesFile%
   }
return

;Important, need to include the Gui file
#include FavoriteFoldersGui.ahk
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Sat Dec 11, 2004 3:37 pm    Post subject: Reply with quote

I tried it and found it to be a great enhancement to the concept. Thanks for sharing it, and for taking them time to edit it into a general-purpose form.
Back to top
View user's profile Send private message Send e-mail
dijiyd



Joined: 01 Apr 2004
Posts: 90
Location: Philippines

PostPosted: Sun Dec 12, 2004 12:02 am    Post subject: Reply with quote

Whoa.. nice. Yeah, it seems that there is a lot going on about this favorite folders script. I really like this. I have a suggestion though, it might be nice to add an option to place a separator, you know, to organize your folder groups.
Back to top
View user's profile Send private message
Simpleton



Joined: 02 Nov 2004
Posts: 14

PostPosted: Sun Dec 12, 2004 12:36 am    Post subject: Reply with quote

Favorite Folders will create seperators for menu entries with blank labels. The gui will also show a line in the listbox for blank labels
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group