Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Favorite Folders popup menu with Gui


  • Please log in to reply
33 replies to this topic
rbrtryn
  • Members
  • 1177 posts
  • Last active: Sep 11 2013 08:04 PM
  • Joined: 22 Jun 2011

        DirMenu gives you easy access to your favorite folders.

 

        Clicking middle mouse button while hovering over certain window types
        will bring up a custom menu of your favorite folders. Upon selecting a
        favorite, the script will instantly switch to that folder within the
        active window.
       
        Holding down the Shift key while clicking the middle mouse button
        will bring up the menu regardless of which window the mouse is over.
        The folder in this case will be shown in a new Explorer window.

 

        By default, The following window types are supported:
        Standard file-open or file-save dialogs
        Explorer windows
        Console (command prompt) windows
        The Desktop

 

        A set up screen is provided that makes it easy to change the folders
        shown or change their order.

 

        Both Windows XP and Windows 7 are supported.

 

/*
	Name:		Dirmenu.ahk
	Author:		Robert Ryan
	Version:	2.0

	Function:
		See the About box
*/

#NoEnv
#SingleInstance force
SetBatchLines -1
ListLines Off
SendMode Input
SetWorkingDir %A_ScriptDir%

; Autoexecute
	MakeGUI()
    MakeTrayMenu()
    MakeCallTable()
    LoadListView()
return

GuiCall:
    Call[A_GuiControl].()
return

MenuCall:
    Call[A_ThisMenuItem].()
return

OpenFavorite:
    LV_GetText(Path, A_ThisMenuItemPos, 2)
    if (A_ThisHotkey = "+MButton") {
        NewWindow(Path)
    }
    else {
        WinWaitActive ahk_id %WinId%
        Call[WinGetClass("A")].(Path)
    }
return

GuiClose:
    Cancel()
return

+MButton::
    Menu Favorites, Show
return

#If Call.HasKey(ClassMouseOver())
MButton::
    WinId := WinMouseOver()
    WinActivate ahk_id %WinId%
    Menu Favorites, Show
return

MakeCallTable()
{
    global Call := []
    
    Call["MyList"] := Func("UpdateButtons")
    Call["&Add"] := Func("Add")
    Call["&Remove"] := Func("Remove")
    Call["&Modify"] := Func("Modify")
    Call["&Separator"] := Func("Separator")
    Call["Move &Up"] := Func("MoveUp")
    Call["Move &Down"] := Func("MoveDown")
    Call["&OK"] := Func("OK")
    Call["&Cancel"] := Func("Cancel")
    Call["Re&vert"] := Func("LoadListView")
    Call["About"] := Func("About")
    Call["Edit Custom Menu"] := Func("ShowGUI")
    Call["Edit This Menu"] := Func("ShowGUI")
    
    Call["Progman"] := Func("NewWindow")
    Call["CabinetWClass"] := Func("Explorer")
    Call["#32770"] := Func("Dialog")
    Call["ConsoleWindowClass"] := Func("Console")
}

LoadListView()
{
	if FileExist("DirMenu.txt")
		ReadFile()
	else
		FirstRun()
    GuiControl Disable, Re&vert
}

; If there is no settings file, set up a a default custom menu
FirstRun()
{
    LV_Delete()
    LV_Add("Select Focus", "C:\", "C:\")
    LV_Add("", "My Documents", A_MyDocuments)
    LV_Add("", "---------------", "---------------")
    LV_Add("", "Windows", A_WinDir)
    LV_Add("", "Program Files", A_ProgramFiles)
    LV_ModifyCol(1, "AutoHdr")
    LV_ModifyCol(2, "AutoHdr")
    UpdateMenu()
}

; Read the ListView entries from the settings file
ReadFile()
{
    LV_Delete()
    Loop Read, DirMenu.txt
    {
        StringSplit Item, A_LoopReadLine, %A_Tab%
		LV_Add("", Item1, Item2)
    }
    LV_Modify(1, "Select Focus")
    LV_ModifyCol(1, "AutoHdr")
    LV_ModifyCol(2, "AutoHdr")
    UpdateMenu()
}

; Update the custom menu to match the ListView
UpdateMenu()
{
    Menu Favorites, Add
    Menu Favorites, DeleteAll
    Loop % LV_GetCount() {
        LV_GetText(Name, A_Index, 1)
        if (Name = "---------------")
            Menu Favorites, Add
        else
            Menu Favorites, Add, %Name%, OpenFavorite
    }
    Menu Favorites, Add
    Menu Favorites, Add, Edit This Menu, MenuCall
}

NewWindow(Path)
{
    Run Explorer.exe /n`,%Path%
}

Console(Path)
{
    Send cd /d %Path%{Enter}
}

Dialog(Path)
{
    WinGetTitle Title, A
    if not RegExMatch(Title, "i)save|open") {
        NewWindow(Path)
        return
    }
    ControlFocus Edit1, A
    ControlGetText OldText, Edit1, A
    ControlSetText Edit1, %Path%, A
    ControlSend Edit1, {Enter}, A
    ControlSetText Edit1, %OldText%, A
}

Explorer(Path)
{
    if RegExMatch(A_OSVersion, "WIN_VISTA|WIN_7") 
        Win7_Explorer(Path)
    else
        XP_Explorer(Path)
}

Win7_Explorer(Path)
{
    Send !d
    Send %Path%{Enter}
}

XP_Explorer(Path)
{
    if not ControlExist("Edit1", "A") {
        PostMessage 0x111, 41477, 0, , A ; Show Address Bar
        while not ControlExist("Edit1", "A")
            Sleep 0
        PostMessage 0x111, 41477, 0, , A ; Hide Address Bar
    }
    ControlFocus Edit1, A
    ControlSetText Edit1, %Path%, A
    ControlSend Edit1, {Enter}, A
}

; Add a new entry to the ListView
Add()
{
    Gui +OwnDialogs
    
    FileSelectFolder Path, *C:\
    if (Path = "")
        return
    
    InputBox Name, Menu Name, Please Enter a name for the new entry:, , 250, 120
    if (ErrorLevel)
        return
    
    LV_Insert(LV_GetCount() ? LV_GetNext() : 1, "Select Focus", Name, Path)
    LV_ModifyCol(1, "AutoHdr")
    LV_ModifyCol(2, "AutoHdr")
    GuiControl Enable, Re&vert
}

; Remove an entry from the ListView
Remove()
{
    LV_Delete(LV_GetNext())
    GuiControl Enable, Re&vert
}

; Modify an existing entry in th ListView
Modify()
{
    Gui +OwnDialogs
    SelectedRow := LV_GetNext()
    LV_GetText(Name, SelectedRow, 1)
    LV_GetText(Path, SelectedRow, 2)
    
    FileSelectFolder NewPath, *%Path%
    if (NewPath = "")
        return
    
    InputBox NewName, Menu Name
           , Enter a name for the entry:, , 250, 120, , , , , %Name%
    if (ErrorLevel)
        return
    
    LV_Modify(SelectedRow, "", NewName, NewPath)
    LV_ModifyCol(1, "AutoHdr")
    LV_ModifyCol(2, "AutoHdr")    
    GuiControl Enable, Re&vert
}

; Insert a separator line into the ListView
Separator()
{
    LV_Insert(LV_GetCount() 
            ? LV_GetNext() 
            : 1
            , "Select Focus", "---------------", "---------------")
    GuiControl Enable, Re&vert
}

; Move an entry down in the ListView
; LV_Modify is used to avoid flickering
MoveDown()
{
    SelectedRow := LV_GetNext()
    LV_GetText(ThisName, SelectedRow, 1)
    LV_GetText(ThisPath, SelectedRow, 2)
    
    LV_GetText(NextName, SelectedRow + 1, 1)
    LV_GetText(NextPath, SelectedRow + 1, 2)
    
    LV_Modify(SelectedRow, "", NextName, NextPath)
    LV_Modify(SelectedRow + 1, "Select Focus", ThisName, ThisPath)
    GuiControl Enable, Re&vert
}

; Move an entry up in the ListView
; LV_Modify is used to avoid flickering
MoveUp()
{
    SelectedRow := LV_GetNext()
    LV_GetText(ThisName, SelectedRow, 1)
    LV_GetText(ThisPath, SelectedRow, 2)
    
    LV_GetText(PriorName, SelectedRow - 1, 1)
    LV_GetText(PriorPath, SelectedRow - 1, 2)
    
    LV_Modify(SelectedRow, "", PriorName, PriorPath)
    LV_Modify(SelectedRow - 1, "Select Focus", ThisName, ThisPath)
    GuiControl Enable, Re&vert
}

; Save the ListView entries to the settings file
OK()
{
    Gui Cancel    
    FileDelete DirMenu.txt
    
    Loop % LV_GetCount() {
        LV_GetText(Name, A_Index, 1)
        LV_GetText(Path, A_Index, 2)
        FileAppend % Name . A_Tab . Path "`n", DirMenu.txt
    }
    FileSetAttrib +H, DirMenu.txt
    GuiControl Disable, Re&vert
    UpdateMenu()
}

Cancel()
{
    Gui Cancel
    LoadListView()
}

; This is called anytime the listview changes
UpdateButtons()
{
    Critical

    TotalNumberOfRows := LV_GetCount()
    
    ; Make sure there is always one selected row
    SelectedRow := LV_GetNext(0, "Focused")
    LV_Modify(SelectedRow, "Select")

    GuiControl % (TotalNumberOfRows = 0) ? "Disable" : "Enable", &Remove
    GuiControl % (SelectedRow <= 1) ? "Disable" : "Enable", Move &Up
    GuiControl % (SelectedRow = TotalNumberOfRows) ? "Disable" : "Enable", Move &Down
}

WinMouseOver()
{
    MouseGetPos, , , WinId
    return WinId
}

WinGetClass(WinTitle = "", WinText = "", ExTitle = "", ExText = "")
{
    WinGetClass out, % WinTitle, % WinText, % ExTitle, % ExText
    return out
}

ClassMouseOver()
{
    return WinGetClass("ahk_id" WinMouseOver())
}

; Determine if a particular control exists in a particular window
ControlExist(Cntrl = "", WTitle = "", WText = "", ExTitle = "", ExText = "")
{
    ControlGet out, Enabled,, % Cntrl, % WTitle, % WText, % ExTitle, % ExText
    return not ErrorLevel
}

About()
{
    MsgBox, , About DirMenu,
    ( LTrim
        DirMenu gives you easy access to your favorite folders.

        Clicking middle mouse button while hovering over certain window types
        will bring up a custom menu of your favorite folders. Upon selecting a
        favorite, the script will instantly switch to that folder within the 
        active window. 
        
        Holding down the Shift key while clicking the middle mouse button
        will bring up the menu regardless of which window the mouse is over.
        The folder in this case will be shown in a new Explorer window.

        By default, The following window types are supported:
        Standard file-open or file-save dialogs
        Explorer windows
        Console (command prompt) windows
        The Desktop

        A set up screen is provided that makes it easy to change the folders
        shown or change their order.

        Both Windows XP and Windows 7 are supported.

        rbrtryn 2012
    )
}

ShowGUI()
{
    Gui Show, , Favorite Folders
}

MakeGUI()
{
    global
    
    Gui , Add, ListView
        , xm w350 h240 Count15 -Multi NoSortHdr AltSubmit vMyList gGuiCall
        , Name|Path
    Gui, Add, Button, x+10 w75 r1 gGuiCall, &Add
    Gui, Add, Button, w75 r1 gGuiCall, &Remove
    Gui, Add, Button, W75 r1 gGuiCall, &Modify
    Gui, Add, Button, w75 r1 gGuiCall, &Separator
    Gui, Add, Button, w75 r1 gGuiCall, Move &Up
    Gui, Add, Button, w75 r1 gGuiCall, Move &Down
    Gui, Add, Button, xm+85 w75 r1 gGuiCall Default, &OK
    Gui, Add, Button, x+20 w75 r1 gGuiCall, &Cancel
    Gui, Add, Button, x+20 w75 r1 gGuiCall, Re&vert
}

MakeTrayMenu()
{
	Menu Default Menu, Standard
	Menu Tray, NoStandard
	Menu Tray, Add, About, MenuCall
	Menu Tray, Add
	Menu Tray, Add, Default Menu, :Default Menu
	Menu Tray, Add
	Menu Tray, Add, Edit Custom Menu, MenuCall
	Menu Tray, Default, Edit Custom Menu
}


 


My Scripts are written for the latest released version of AutoHotkey.

Need a secure, accessible place to backup your stuff? Use Dropbox!


Brandon_oma692
  • Members
  • 6 posts
  • Last active: Jun 27 2013 03:14 PM
  • Joined: 26 Dec 2012

very nice. This works well if i run it alone but if i try to add it to my main script it does not. I think I would have to edit to named gui's. Is it as simple as replacing "gui" with "gui db:"?

 

thanks



Sanctus
  • Members
  • 283 posts
  • Last active: Dec 06 2014 04:05 PM
  • Joined: 30 Nov 2012

Trying it out right now very nice


Check out ALL My Scripts  ;)


R3gX
  • Members
  • 307 posts
  • Last active: Dec 29 2013 04:50 PM
  • Joined: 28 Feb 2011

Trying it out right now very nice

 

+1


signature.png
Previously known as TomXIII
AutoHotkey version : 1.1.10


JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007

Yes, nice script, rbrtryn.  I had to make some edits to make it fully work in a French Windows 7 environment.

 

Line 149, replace

if not RegExMatch(Title, "i)save|open") {

with

if not RegExMatch(Title, "i)save|open|enreg|ouvrir") {

 
For Spanish or other languages, add your translations for save and open "|...|..."
 
And this one to select the Explorer address bar:
 
Line 170, replace
Send !d
with
Send {F4}^a
 
"{F4}" selects the address bar and "^a" (Select All) select the address before its replacement with de desired path.
 
I did not test on Win XP, but, reading your code, it seems to be good for French version.
 


JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007

I had the idea to add an option to your scritp: "Add current folder". It would get the current path from the active Explorer or dialog box, ask for a name and add this folder to the menu file. If you don't mind, I may work on this when I have some time.



neil1999
  • Members
  • 2 posts
  • Last active: Mar 14 2014 02:02 AM
  • Joined: 28 Jun 2013

Hi, I am bnew with AHK. Thanks for the scripts which I've been looking for!

I tried on Win7 x64 and it works fine with +MButton (Open a new explore to go to new directory).

However MButton (without SHIFT), it will break when I choose "C:Program Files".

The address bar in Explore will turn to "C:\ProgramFiles" <-- The single [SPACE] is missing for some reason ...

 

Error msgbox shows up with :

(Windows can't find 'C:\ProgramFiles'. Check spelling and try again)

========================

 

I also find, sometimes, the address bar is changed to target path and just stay there...The [return] seems not be sent correctly...

(Not sure if I can add an additional [return] at this line:

 

Win7_Explorer(Path)
{
    Send !d ; select & highlight the path bar
    Send %Path%{Enter}{Enter} ; Send double Enter to make it always work ?? <-----------------
   }
 
I also found some others like this: But the scripts here do not exist anymore :
 
Thanks for your help !!!


rbrtryn
  • Members
  • 1177 posts
  • Last active: Sep 11 2013 08:04 PM
  • Joined: 22 Jun 2011

Hi, I am bnew with AHK. Thanks for the scripts which I've been looking for!

I tried on Win7 x64 and it works fine with +MButton (Open a new explore to go to new directory).

However MButton (without SHIFT), it will break when I choose "C:Program Files".

The address bar in Explore will turn to "C:\ProgramFiles" <-- The single [SPACE] is missing for some reason ...

 

Error msgbox shows up with :

(Windows can't find 'C:\ProgramFiles'. Check spelling and try again)

 

Open up the GUI and modify the entry for Program Files so it points to the correct place. I have never seen the problem you describe and I use this daily on Win XP and Win 7, so hopefully this will fix it.

 

I also find, sometimes, the address bar is changed to target path and just stay there...The [return] seems not be sent correctly...

(Not sure if I can add an additional [return] at this line:

 

Win7_Explorer(Path)
{
    Send !d ; select & highlight the path bar
    Send %Path%{Enter}{Enter} ; Send double Enter to make it always work ?? <-----------------
   }

 

This can happen if the computer is under heavy load, but I've never had it actually fail. It just takes awhile for the change to take place. Can you give me more information about when this happens? Is there any pattern to the activity that would give a clue as to what is going on?


My Scripts are written for the latest released version of AutoHotkey.

Need a secure, accessible place to backup your stuff? Use Dropbox!


RiseUp
  • Members
  • 38 posts
  • Last active: Jan 04 2016 01:42 PM
  • Joined: 06 Dec 2007

I had the idea to add an option to your scritp: "Add current folder". It would get the current path from the active Explorer or dialog box, ask for a name and add this folder to the menu file. If you don't mind, I may work on this when I have some time.


Hi JnLLnd. Have you had a chance to work on this? It's definitely a feature I would like to see available in this script.

JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007

No not yet, working on other projects. But this would be a nice addtion to this nice script. I put it on my to-do list.

 

For now, I'll put this code on BitBucket to keep track of the edits.

 

Unless the author rbrtryn has other projects with this script?



JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007
Hello,m
 
I just finish an update to DirMenu:
 
    - make it work with any locale (still working with English)
    - put supported dialog box titles in a variable (strDialogNames) at the top of the script for easy editing
    - put DirMenu data file name in a variable (strDirMenuFile) at the top of the script for easy editing
    - add "Add This Folder" to the MButton menu to add the current folder
    - add "Menu File" button to open de DirMenu.txt file for edition in Notepad (or default text editor)
    - propose the deepest folder name as default name for a new folder

/*
	Name:		Dirmenu.ahk
	Author:		Robert Ryan
	Edited by:  Jean Lalonde (see https://github.com/JnLlnd/DirMenu-JL for difference with original script)
	- make it work with any locale (still working with English)
	- put supported dialog box titles in a variable (strDialogNames) at the top of the script for easy editing
	- put DirMenu data file name in a variable (strDirMenuFile) at the top of the script for easy editing
	- add "Add This Folder" to the MButton menu to add the current folder
	- add "Menu File" button to open de DirMenu.txt file for edition in Notepad
	- propose the deepest folder name as default name for a new folder
	Version:	2.1

	Function:
		See the About box
		
	
*/

#NoEnv
#SingleInstance force
SetBatchLines -1
ListLines Off
SendMode Input
SetWorkingDir %A_ScriptDir%

; Autoexecute
	global strDialogNames := "save|open|unzip|select|insert"
	; for French Windows, add: "|ouvrir|enregistrer|création de documents|insérer|télécharger|ajouter|joindre"
	; for English and other languages, add part of name of dialog boxes used to open or save files
	global strDirMenuFile := "DirMenu.txt"
	MakeGUI()
	MakeTrayMenu()
	MakeCallTable()
	LoadListView()
return

GuiCall:
	Call[A_GuiControl].()
return

MenuCall:
	Call[A_ThisMenuItem].()
return

OpenFavorite:
	LV_GetText(Path, A_ThisMenuItemPos, 2)
	if (A_ThisHotkey = "+MButton") {
		NewWindow(Path)
	}
	else {
		WinWaitActive ahk_id %WinId%
		Call[WinGetClass("A")].(Path)
	}
return

GuiClose:
	Cancel()
return

+MButton::
	ReadFile() ; in case the setting file was modified with Notepad
	Menu Favorites, Show
return

#If Call.HasKey(ClassMouseOver())
MButton::
	WinId := WinMouseOver()
	WinActivate ahk_id %WinId%
	ReadFile() ; in case the setting file was modified with Notepad
	Menu Favorites, Show
return

MakeCallTable()
{
	global Call := []
	
	Call["MyList"] := Func("UpdateButtons")
	Call["&Add"] := Func("Add")
	Call["&Remove"] := Func("Remove")
	Call["&Modify"] := Func("Modify")
	Call["&Separator"] := Func("Separator")
	Call["Move &Up"] := Func("MoveUp")
	Call["Move &Down"] := Func("MoveDown")
	Call["&OK"] := Func("OK")
	Call["&Cancel"] := Func("Cancel")
	Call["Re&vert"] := Func("LoadListView")
	Call["About"] := Func("About")
	Call["Edit Custom Menu"] := Func("ShowGUI")
	Call["Edit This Menu"] := Func("ShowGUI")
	Call["Add This Folder"] := Func("AddThisFolder")
	Call["Menu File"] := Func("OpenMenuFile")
	
	Call["Progman"] := Func("NewWindow")
	Call["CabinetWClass"] := Func("Explorer")
	Call["#32770"] := Func("Dialog")
	Call["ConsoleWindowClass"] := Func("Console")
}

AddThisFolder()
{
	global strCurrentFolder
	global strDialogNames

	Sleep, 200
	if (WinGetClass("A") = "CabinetWClass") or (WinGetClass("A") = "#32770") ; Explorer or Dialog
	{
		Send {F4}^a ; F4 move the caret the "Go To A Different Folder box" and ^a select it content
		Sleep, 200
		Send ^c ; Copy
		Sleep, 200
		strCurrentFolder := ClipBoard
	}
	ShowGUI()
	Add()
}

LoadListView()
{
	if FileExist(strDirMenuFile)
		ReadFile()
	else
		FirstRun()
	GuiControl Disable, Re&vert
}

; If there is no settings file, set up a a default custom menu
FirstRun()
{
	LV_Delete()
	LV_Add("Select Focus", "C:\", "C:\")
	LV_Add("", "My Documents", A_MyDocuments)
	LV_Add("", "---------------", "---------------")
	LV_Add("", "Windows", A_WinDir)
	LV_Add("", "Program Files", A_ProgramFiles)
	LV_ModifyCol(1, "AutoHdr")
	LV_ModifyCol(2, "AutoHdr")
	Save()
	UpdateMenu()
}

; Read the ListView entries from the settings file
ReadFile()
{
	LV_Delete()
	Loop Read, %strDirMenuFile%
	{
		StringSplit Item, A_LoopReadLine, %A_Tab%
		LV_Add("", Item1, Item2)
	}
	LV_Modify(1, "Select Focus")
	LV_ModifyCol(1, "AutoHdr")
	LV_ModifyCol(2, "AutoHdr")
	UpdateMenu()
}

; Update the custom menu to match the ListView
UpdateMenu()
{
	Menu Favorites, Add
	Menu Favorites, DeleteAll
	Loop % LV_GetCount() {
		LV_GetText(Name, A_Index, 1)
		if (Name = "---------------")
			Menu Favorites, Add
		else
			Menu Favorites, Add, %Name%, OpenFavorite
	}
	Menu Favorites, Add
	Menu Favorites, Add, Edit This Menu, MenuCall
	Menu Favorites, Add, Add This Folder, MenuCall
}

NewWindow(Path)
{
	Run Explorer.exe /n`,%Path%
}

Console(Path)
{
	Send cd /d %Path%{Enter}
}

Dialog(Path)
{
	WinGetTitle Title, A
	if not RegExMatch(Title, "i)" . strDialogNames) {
		NewWindow(Path)
		return
	}
	ControlFocus Edit1, A
	ControlGetText OldText, Edit1, A
	ControlSetText Edit1, %Path%, A
	ControlSend Edit1, {Enter}, A
	ControlSetText Edit1, %OldText%, A
}

Explorer(Path)
{
	if RegExMatch(A_OSVersion, "WIN_VISTA|WIN_7") 
		Win7_Explorer(Path)
	else
		XP_Explorer(Path)
}

Win7_Explorer(Path)
{
	WinGetTitle Title, A
	Send {F4}^a ; Previously command "!d" worked only in English Windows 7. "{F4}^a" should work in all locales.
	Send %Path%{Enter}
}

XP_Explorer(Path)
{
	if not ControlExist("Edit1", "A") {
		PostMessage 0x111, 41477, 0, , A ; Show Address Bar
		while not ControlExist("Edit1", "A")
			Sleep 0
		PostMessage 0x111, 41477, 0, , A ; Hide Address Bar
	}
	ControlFocus Edit1, A
	ControlSetText Edit1, %Path%, A
	ControlSend Edit1, {Enter}, A
}

; Add a new entry to the ListView
Add()
{
	global strCurrentFolder ; to support "Add This Folder"
	Gui +OwnDialogs
	
	if (strCurrentFolder = "")
	{
		FileSelectFolder Path, *C:\
		if (Path = "")
			return
	}
	else
	{
		Path := strCurrentFolder
		strCurrentFolder := "" ; will make the Add button act normally if called after an "Add This Folder"
	}

	; propose the deepest folder's name as default name for the added folder
	StringGetPos, intLastSlash, Path, \, R
	if (ErrorLevel) ; no \ found in Path
		StringGetPos, intLastSlash, Path, /, R ; parse URL type Path
	StringMid, strDefault, Path, % intLastSlash + 2
	
	InputBox Name, Menu Name, Please Enter a name for the new entry:, , 250, 120, , , , , %strDefault%
	if (ErrorLevel)
		return
	
	LV_Insert(LV_GetCount() ? LV_GetNext() : 1, "Select Focus", Name, Path)
	LV_ModifyCol(1, "AutoHdr")
	LV_ModifyCol(2, "AutoHdr")
	GuiControl Enable, Re&vert
}

; Remove an entry from the ListView
Remove()
{
	LV_Delete(LV_GetNext())
	GuiControl Enable, Re&vert
}

; Modify an existing entry in th ListView
Modify()
{
	Gui +OwnDialogs
	SelectedRow := LV_GetNext()
	LV_GetText(Name, SelectedRow, 1)
	LV_GetText(Path, SelectedRow, 2)
	
	FileSelectFolder NewPath, *%Path%
	if (NewPath = "")
		return
	
	InputBox NewName, Menu Name
		   , Enter a name for the entry:, , 250, 120, , , , , %Name%
	if (ErrorLevel)
		return
	
	LV_Modify(SelectedRow, "", NewName, NewPath)
	LV_ModifyCol(1, "AutoHdr")
	LV_ModifyCol(2, "AutoHdr")    
	GuiControl Enable, Re&vert
}

; Insert a separator line into the ListView
Separator()
{
	LV_Insert(LV_GetCount() 
			? LV_GetNext() 
			: 1
			, "Select Focus", "---------------", "---------------")
	GuiControl Enable, Re&vert
}

; Move an entry down in the ListView
; LV_Modify is used to avoid flickering
MoveDown()
{
	SelectedRow := LV_GetNext()
	LV_GetText(ThisName, SelectedRow, 1)
	LV_GetText(ThisPath, SelectedRow, 2)
	
	LV_GetText(NextName, SelectedRow + 1, 1)
	LV_GetText(NextPath, SelectedRow + 1, 2)
	
	LV_Modify(SelectedRow, "", NextName, NextPath)
	LV_Modify(SelectedRow + 1, "Select Focus", ThisName, ThisPath)
	GuiControl Enable, Re&vert
}

; Move an entry up in the ListView
; LV_Modify is used to avoid flickering
MoveUp()
{
	SelectedRow := LV_GetNext()
	LV_GetText(ThisName, SelectedRow, 1)
	LV_GetText(ThisPath, SelectedRow, 2)
	
	LV_GetText(PriorName, SelectedRow - 1, 1)
	LV_GetText(PriorPath, SelectedRow - 1, 2)
	
	LV_Modify(SelectedRow, "", PriorName, PriorPath)
	LV_Modify(SelectedRow - 1, "Select Focus", ThisName, ThisPath)
	GuiControl Enable, Re&vert
}

; Save the ListView entries to the settings file
OK()
{
	Gui Cancel    
	FileDelete %strDirMenuFile%
	Save()
	GuiControl Disable, Re&vert
	UpdateMenu()
}

Cancel()
{
	Gui Cancel
	LoadListView()
}

Save()
{
	Loop % LV_GetCount() {
		LV_GetText(Name, A_Index, 1)
		LV_GetText(Path, A_Index, 2)
		FileAppend % Name . A_Tab . Path "`n", %strDirMenuFile%
	}
	FileSetAttrib +H, %strDirMenuFile%
}

; This is called anytime the listview changes
UpdateButtons()
{
	Critical

	TotalNumberOfRows := LV_GetCount()
	
	; Make sure there is always one selected row
	SelectedRow := LV_GetNext(0, "Focused")
	LV_Modify(SelectedRow, "Select")

	GuiControl % (TotalNumberOfRows = 0) ? "Disable" : "Enable", &Remove
	GuiControl % (SelectedRow <= 1) ? "Disable" : "Enable", Move &Up
	GuiControl % (SelectedRow = TotalNumberOfRows) ? "Disable" : "Enable", Move &Down
}

WinMouseOver()
{
	MouseGetPos, , , WinId
	return WinId
}

WinGetClass(WinTitle = "", WinText = "", ExTitle = "", ExText = "")
{
	WinGetClass out, % WinTitle, % WinText, % ExTitle, % ExText
	return out
}

ClassMouseOver()
{
	return WinGetClass("ahk_id" WinMouseOver())
}

; Determine if a particular control exists in a particular window
ControlExist(Cntrl = "", WTitle = "", WText = "", ExTitle = "", ExText = "")
{
	ControlGet out, Enabled,, % Cntrl, % WTitle, % WText, % ExTitle, % ExText
	return not ErrorLevel
}

About()
{
	MsgBox, , About DirMenu,
	( LTrim
		DirMenu gives you easy access to your favorite folders.

		Clicking middle mouse button while hovering over certain window types
		will bring up a custom menu of your favorite folders. Upon selecting a
		favorite, the script will instantly switch to that folder within the 
		active window. 
		
		Holding down the Shift key while clicking the middle mouse button
		will bring up the menu regardless of which window the mouse is over.
		The folder in this case will be shown in a new Explorer window.

		By default, the following window types are supported:
		Standard file-open or file-save dialogs
		Explorer windows
		Console (command prompt) windows
		The Desktop

		A set up screen is provided that makes it easy to change the folders
		shown or change their order.

		Both Windows XP and Windows 7 are supported.

		rbrtryn 2012 (edited JnLlnd 2013)
	)
}

ShowGUI()
{
	Gui Show, , Favorite Folders
}

MakeGUI()
{
	global
	
	Gui , Add, ListView
		, xm w350 h240 Count15 -Multi NoSortHdr AltSubmit vMyList gGuiCall
		, Name|Path
	Gui, Add, Button, x+10 w75 r1 gGuiCall, &Add
	Gui, Add, Button, w75 r1 gGuiCall, &Remove
	Gui, Add, Button, W75 r1 gGuiCall, &Modify
	Gui, Add, Button, w75 r1 gGuiCall, &Separator
	Gui, Add, Button, w75 r1 gGuiCall, Move &Up
	Gui, Add, Button, w75 r1 gGuiCall, Move &Down
	Gui, Add, Button, w75 r1 gGuiCall, Menu File
	Gui, Add, Button, xm+85 w75 r1 gGuiCall Default, &OK
	Gui, Add, Button, x+20 w75 r1 gGuiCall, &Cancel
	Gui, Add, Button, x+20 w75 r1 gGuiCall, Re&vert
}

MakeTrayMenu()
{
	Menu Default Menu, Standard
	Menu Tray, NoStandard
	Menu Tray, Add, About, MenuCall
	Menu Tray, Add
	Menu Tray, Add, Default Menu, :Default Menu
	Menu Tray, Add
	Menu Tray, Add, Edit Custom Menu, MenuCall
	Menu Tray, Default, Edit Custom Menu
}


OpenMenuFile()
{
	OK()
	Run, %strDirMenuFile%
}
GitHub repository is here: https://github.com/JnLlnd/DirMenu-JL
 
Raw source of this script here: https://raw.github.c...ter/DirMenu.ahk
 
Hope you will like these additions to this already so useful script (I'm using it every day!). And thanks to the original author Robert Ryan.


Edit 2013-10-25: Fix indenting style for lines added. No functionality change.

Edited by JnLLnd, 25 October 2013 - 06:01 PM.


chaz
  • Members
  • 192 posts
  • Last active: Oct 01 2015 02:42 AM
  • Joined: 26 Mar 2013

Wow! This thing is AWESOME! I am SO glad I found it. I've only used it for the past five minutes, but I can tell that this is something I'm going to be using for a very long time. It even works in conjunction with QTTabBar, a tabbed Explorer add-on.


Find me at the other forum as timeFlies.


chaz
  • Members
  • 192 posts
  • Last active: Oct 01 2015 02:42 AM
  • Joined: 26 Mar 2013

Minor change:
On line 208, change from

Send {F4}^a

to

ControlFocus, Edit1, A

to prevent the opening of the drop-down list and the flashing that occurs.


Find me at the other forum as timeFlies.


JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007

Minor change:
On line 208, change from

Send {F4}^a
to
ControlFocus, Edit1, A
to prevent the opening of the drop-down list and the flashing that occurs.


I'll do! Should it also work on Win XP?

chaz
  • Members
  • 192 posts
  • Last active: Oct 01 2015 02:42 AM
  • Joined: 26 Mar 2013

Is it possible to display the menu without the active window being deactivated? This behaviour is rather annoying.


Find me at the other forum as timeFlies.