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 

Nested and sorted folder structure for menus

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



Joined: 24 Sep 2006
Posts: 60

PostPosted: Sun Nov 26, 2006 5:44 pm    Post subject: Nested and sorted folder structure for menus Reply with quote

This little function adds the contents of a folder to a menu, and recursively all its subfolders, subsubfolders, etc in submenus , sorted by name in each submenu. It keeps track of the path to each folder and each program, so that you can call them when clicked as in the example below.
I hope it's useful to someone; to me it was Smile

Code:

HIDDEN_MENU_EXTENSIONS = exe,lnk,bat,com,pif

; Example
CUSTOM_FOLDER = %A_Programs%

FolderAdd("CMenu", CUSTOM_FOLDER, "CustomMenuHandler")
Return

MButton::
   Menu, CMenu, show
Return

CustomMenuHandler:
{
   foo := %A_ThisMenu%_Path . "\" . %A_ThisMenu%_File_%A_ThisMenuItemPos%
   Run, %foo%
} Return


FolderAdd(MenuName, Folder, Handler)
{
   Global
   Local i, FileList

   %MenuName%_Path = %Folder%

   Loop, %Folder%\*, 2
      FileList = %FileList%%A_LoopFileName%`n
   Sort, FileList
   i=0
   Loop, parse, FileList, `n
   {
      if A_LoopField =  ; Ignore the blank item at the end of the list.
         continue
      i++
      foo=%MenuName%_%i%
      FolderAdd(foo, Folder . "\" . A_LoopField, Handler)
      Menu, %MenuName%, Add, %A_LoopField%, :%MenuName%_%i%
   }
   
   Filelist=
   Loop, %Folder%\*, 0
      FileList = %FileList%%A_LoopFileName%`n
   Sort, FileList
   Loop, parse, FileList, `n
   {
      if A_LoopField =
         continue
      i++
      foo:=FileExtension(A_LoopField)
      If foo in %HIDDEN_MENU_EXTENSIONS%
         StringTrimRight, foo, A_LoopField, StrLen(foo)+1
      else
         foo=%A_LoopField%
      
      Menu, %MenuName%, Add, %foo%, %Handler%
      %MenuName%_File_%i% = %A_LoopField%
   }
   If i=0
   {
      Menu, %MenuName%, Add, (Empty), %Handler%
      Menu, %MenuName%, Disable, (Empty)
   }
}

FileExtension(FileName)
{
   StringGetPos, Ext, FileName, . ,   R
   StringTrimLeft, Ext, FileName, Ext+1
   Return Ext
}
Back to top
View user's profile Send private message
hoppfrosch



Joined: 25 Jan 2006
Posts: 16
Location: Somewhere in Germany

PostPosted: Tue Dec 12, 2006 12:36 pm    Post subject: Icons on Menu Reply with quote

Thanks - it's very useful for my purposes ...

Are there any recipes how to get the icons of the items into the menu?
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