 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Rajat
Joined: 28 Mar 2004 Posts: 1717
|
Posted: Thu Jul 08, 2004 1:10 am Post subject: Folder menu (menu cmd) |
|
|
This script will show a folder menu.
Click the folder to show the contents in new menu. shift + click to select folder.
and yeah, the menu items are sorted.
| Code: |
home = c:
show:
Folders =
Menu, Foldermenu, add, dummy, RunFolder
Menu, Foldermenu, DeleteAll
Menu, Foldermenu, add, [..], RunFolder
Loop, %home%\*.*, 2
{
Folders = %Folders%`n%A_LoopFileName%
}
Sort, Folders
Loop, parse, Folders, `n
{
Menu, Foldermenu, add, %A_LoopField%, RunFolder
}
Menu, Foldermenu, show
Exit
RunFolder:
GetKeyState, State, Shift
IfEqual, A_ThisMenuItem, [..]
{
StringLen, Len, Home
StringGetPos, SPos, Home, \, R
Len -= %SPos%
StringTrimRight, Home, Home, %Len%
Goto, Show
}
IfEqual, State, D
{
Run, %home%\%A_ThisMenuItem%
}
Else
{
home = %home%\%A_ThisMenuItem%
goto, show
}
Return
|
there is an ongoing discussion on folder menu using menu cmd so i thought i'll give it a show. i think its nice. _________________
 |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Thu Jul 08, 2004 2:06 am Post subject: |
|
|
That's a nice way to handle navigating through subfolders, just like your tooltip approach. There is one potential flaw with this script: Whenever you choose a menu item, a new thread is created, interrupting the previous one. Eventually, the maximum number of threads is reached (10 in this case), and all the threads collapse back to the original menu command and then the Exit command is reached. You might already know about this and just intended this script for demonstration purposes.
In case there's ever any need to address this, I think the only way is to avoid calling the menu command recursively from a menu subroutine (which in this case happens as a result of the line "goto, show"). Somehow, the menu subroutine must be returned from before you show another menu. This might be achievable with a Loop that monitors the state of the A_ThisMenuItem variable and when it changes, builds and displays a new menu.
Regardless, it's a great script. |
|
| Back to top |
|
 |
Rajat
Joined: 28 Mar 2004 Posts: 1717
|
Posted: Thu Jul 08, 2004 3:59 am Post subject: |
|
|
You're partly right while saying that its for demonstration purposes, as what i don't like about this script (as compared to the tooltip foldermenu) is that the menu keeps popping at different positions (because mouse keeps moving down). though i could've addressed it partly by using mousegetpos initially and then mousemove everytime before showing menu, but that was also part-evil.
But its true that what you pointed out was something i totally missed. Thanx Chris for pointing that out. i made this script so that new users might find use for it.
I didn't completely follow your solution. do you mean that when a_ThisMenuItem changes then i leave the original menu where it is and then make a new menu? probably using a random name...
though i'm sure for most uses the limit of 10 menu-shows won't create a problem.
by the way tell me something, did u run the script and clicked more than 10 times and the script poofed out or u saw this thing just by browsing through the code (?!)  _________________
 |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Thu Jul 08, 2004 1:31 pm Post subject: |
|
|
| Quote: | | did u run the script and clicked more than 10 times and the script poofed out or u saw this thing just by browsing through the code |
I saw it *poof* after 10 clicks and then I looked at the script to try to find out why.
| Quote: | | do you mean that when a_ThisMenuItem changes then i leave the original menu where it is and then make a new menu? probably using a random name... |
Well, you can't leave the original menu because it automatically disappears when the user selects an item. Here is a revised version that seems to work okay:
| Code: | ; Navigate through the directories until you find one you want to open.
; Shift-left-click it to open it.
home = c:
cancel? = n
Loop
{
if cancel? = y
break
Folders =
Menu, Foldermenu, add, [..], RunFolder
Loop, %home%\*.*, 2
Folders = %Folders%`n%A_LoopFileName%
Sort, Folders
Loop, parse, Folders, `n
Menu, Foldermenu, add, %A_LoopField%, RunFolder
an_item_was_selected? = n
Menu, Foldermenu, show
if an_item_was_selected? = n ; Cancel the menu
break
IfEqual, A_ThisMenuItem, [..]
SplitPath, Home, , Home
else
{
GetKeyState, State, Shift
IfEqual, State, D
{
Run, %home%\%A_ThisMenuItem%
break
}
; Otherwise, shift key is not down:
home = %home%\%A_ThisMenuItem%
}
Menu, FolderMenu, DeleteAll
}
Exit
; To prevent new threads from being created, one for each time the user
; selects a folder, this intentionally does nothing to let the main
; loop handle it:
RunFolder:
an_item_was_selected? = y
return
|
Btw, I saw this line in the script and I wasn't sure if it was just a remnant you forgot to remove, or something you discovered was needed to avoid an error:
Menu, Foldermenu, add, dummy, RunFolder
Also, this provided another chance to use SplitPath for something useful.
Edit: Added missing subroutine at the bottom. Made it so that menu can be canceled rather than being forced to make a selection.
Last edited by Chris on Sat Jul 10, 2004 3:05 am; edited 4 times in total |
|
| Back to top |
|
 |
Rajat
Joined: 28 Mar 2004 Posts: 1717
|
Posted: Fri Jul 09, 2004 8:05 pm Post subject: |
|
|
honey u shrunk the script!
is it the complete script Chris or does it need something more as it doesn't seem to work for me.
or wait a sec! does it need a recent download?... i think i don't have splitpath, but then its only needed if one has to step out a folder... for me the script doesn't even load and gives an error. _________________
 |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Fri Jul 09, 2004 8:16 pm Post subject: |
|
|
Opps, I forgot the empty subroutine at the bottom, which I've added to the above script:
; To prevent new threads from being created, one for each time the user
; selects a folder, this intentionally does nothing to let the main
; loop handle it:
RunFolder:
return |
|
| Back to top |
|
 |
Rajat
Joined: 28 Mar 2004 Posts: 1717
|
Posted: Fri Jul 09, 2004 8:33 pm Post subject: |
|
|
nice! now just make the menu disappear if one clicks outside it... its adamant to get an item selected! _________________
 |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Fri Jul 09, 2004 9:02 pm Post subject: |
|
|
| Yeah that's a good point. I added a big fat CANCEL item at the top, since there's no super-easy way to detect a click outside of the menu area in this case. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Sat Jul 10, 2004 3:07 am Post subject: |
|
|
| I now see how to make this repeating menu close by clicking outside it, so I changed the above script accordingly. |
|
| Back to top |
|
 |
Rajat
Joined: 28 Mar 2004 Posts: 1717
|
Posted: Sat Jul 10, 2004 6:01 pm Post subject: |
|
|
i'll check it. thanx. _________________
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|