AutoHotkey Community

It is currently May 27th, 2012, 9:27 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: November 8th, 2004, 4:31 am 
Offline

Joined: October 12th, 2004, 11:34 pm
Posts: 74
Location: São Paulo ,Brazil
If you like menus, this script may be useful
The purpose of this script is to create/modify menus in a fly
It seems too big, but almost half of the lines are GUI definitions.
If you decide to give it a try:
This script,and the menus generated by it, were not made to stay running all the time, just set a hotkey
to call the scripts when needed.
First you must use the script to generate a specially formatted menu script.

you can do it this way:
Open an explorer window and select one or more files/folders and hit the hotkey to launch the script.
The script will copy the files to clipboard to retrieve their paths later ,then it will show a GUI, in which
you must click the "new menu" radiobox ,fill a name in the combobox "main menu" and choose the modifiers
keys if you want(if not, there is a default key setting) then hit the button "submit".The new menu will
appear.The new menu script will be saved in A_ScriptDir.
Or you can just run this script with no files selected and create a new menu,then
the only menu item will be "click to add item"...just click it.

The generated script can be edited directly from menu:
LeftShift+click an item to add new items below the clicked one.
RightShift+click an item to remove it
LeftWin+click --add a submenu
RightWin+click a submenu item to remove the whole submenu
LeftControl+click--add a separator below the clicked item
RightControl+click--remove the separator below the clicked item
click will launch item off course and you can change the modifiers keys using the GUI

Or from GUI.I wrote some "tips" inside GUI to explain its functions.
Code:
SetWorkingDir, %A_ScriptDir%
?menu_items = `/*`nmain_menu|Click to Add Item|temp_item`nmain_menu|last_item`n*/`n
?menu_mount = Menu, main_menu, Add, •TITLE`nMenu, main_menu, Add`nLoop, Read, `%A_ScriptFullPath`%`n{`n   If A_LoopReadLine = ``/`*`n      Continue`n   IfInString, A_LoopReadLine, last_item`n      Continue`n   If A_LoopReadLine = *`/`n      Break`n   ?items = `%?items`%`%A_LoopReadLine`%``n`n   StringSplit, ?line, A_LoopReadLine, |`n   If ?line2 = separator`n      Menu, `%?line1`%, Add`n   Else If ?line3 = sm`n      Menu, `%?line4`%, Add, `%?line2`%, :`%?line1`%`n   Else`n      Menu, `%?line1`%, Add, `%?line2`%, launch`n}`nMenu, main_menu, show`nReturn`n`n•TITLE:`n`nlaunch:`nGetKeyState, ?add_item, `%?key_add_item`%, P`nGetKeyState, ?add_sub, `%?key_add_submenu`%, P`nGetKeyState, ?add_sep, `%?key_add_separator`%, P `n
?combined = If ?add_item = D`n{`n   GetKeyState, ?rem_item, `%?key_rem_item`%`n   If ?rem_item = D`n   {`n      Clipboard =`n      Clipboard = `%A_ScriptFullPath`%|`%A_ThisMenu`%|`%A_ThisMenuItem`%|Remove_Item`n      Run, %A_ScriptName%`n   }`n   Else`n   {`n      Clipboard =`n      Clipboard = `%A_ScriptFullPath`%|`%A_ThisMenu`%|`%A_ThisMenuItem`%|Insert_Item`n      Run, %A_ScriptName%`n   }`n   Return`n}`nIf ?add_sub = D`n{`n   GetKeyState, ?rem_sub, `%?key_rem_submenu`%`n   If ?rem_sub = D`n   {`n      Clipboard =`n      Clipboard = `%A_ScriptFullPath`%|`%A_ThisMenu`%|`%A_ThisMenuItem`%|Remove_Submenu`n      Run, %A_ScriptName%`n   }`n   Else`n   {`n      Clipboard =`n      Clipboard = `%A_ScriptFullPath`%|`%A_ThisMenu`%|`%A_ThisMenuItem`%|Insert_Submenu`n      Run, %A_ScriptName%`n   }`n   Return`n}`nIf  ?add_sep = D`n{`n   GetKeyState, ?rem_sep, `%?key_rem_separator`%`n   If ?rem_sep = D`n   {`n      Clipboard =`n      Clipboard = `%A_ScriptFullPath`%|`%A_ThisMenu`%|`%A_ThisMenuItem`%|Remove_Separator`n      Run, %A_ScriptName%`n   }`n   Else`n   {`n      Clipboard =`n      Clipboard = `%A_ScriptFullPath`%|`%A_ThisMenu`%|`%A_ThisMenuItem`%|Insert_Separator`n      Run, %A_ScriptName%`n   }`n   Return`n}`n
?single = GetKeyState, ?rem_item, `%?key_rem_item`%, P`nGetKeyState, ?rem_sub, `%?key_rem_submenu`%, P `nGetKeyState, ?rem_sep, `%?key_rem_separator`%, P `nIf ?add_item = D`n{`n   Clipboard =`n   Clipboard = `%A_ScriptFullPath`%|`%A_ThisMenu`%|`%A_ThisMenuItem`%|Insert_Item`n   Run, %A_ScriptName%`n   Return`n}`nIf ?rem_item = D`n{`n   Clipboard =`n   Clipboard = `%A_ScriptFullPath`%|`%A_ThisMenu`%|`%A_ThisMenuItem`%|Remove_Item`n   Run, %A_ScriptName%`n   Return`n}`nIf ?add_sub = D`n{`n   Clipboard =`n   Clipboard = `%A_ScriptFullPath`%|`%A_ThisMenu`%|`%A_ThisMenuItem`%|Insert_Submenu`n   Run, %A_ScriptName%`n   Return`n}`nIf ?rem_sub = D`n{`n   Clipboard =`n   Clipboard = `%A_ScriptFullPath`%|`%A_ThisMenu`%|`%A_ThisMenuItem`%|Remove_Submenu`n   Run, %A_ScriptName%`n   Return`n}`nIf  ?add_sep = D`n{`n   Clipboard =`n   Clipboard = `%A_ScriptFullPath`%|`%A_ThisMenu`%|`%A_ThisMenuItem`%|Insert_Separator`n   Run, %A_ScriptName%`n   Return`n}`nIf ?rem_sep = D`n{`n   Clipboard =`n   Clipboard = `%A_ScriptFullPath`%|`%A_ThisMenu`%|`%A_ThisMenuItem`%|Remove_Separator`n   Run, %A_ScriptName%`n   Return`n}`n
?common = Else`n{`n   If A_ThisMenuItem = Click to Add Item`n   {`n      Clipboard =`n      Clipboard = `%A_ScriptFullPath`%|`%A_ThisMenu`%|`%A_ThisMenuItem`%|Insert_Item`n      Run, %A_ScriptName%`n      Return`n   }`n   Loop, Parse, ?items, ``n`n   {`n      IfInString, A_LoopField, `%A_ThisMenu`%|`%A_ThisMenuItem`%`n      {`n         StringSplit, ?line, A_LoopField, |`n         Run, `%?line3`%`n         Break`n      }`n   }`n   Return`n}`n
DriveGet, ?alldrives, list
?drives =
Loop, parse, ?alldrives
{
   ?drives = %?drives%%A_LoopField%:\,
}
StringTrimRight, ?drives, ?drives, 1

If Clipboard contains Insert_Item,Insert_Separator,Insert_Submenu,Remove_Item,Remove_Separator,Remove_Submenu
{
   SetCapsLockState, Off
   StringSplit, ?Qmenu, Clipboard, |
   Clipboard =
   If ?Qmenu4 = Insert_Separator
   {
      Loop, Read, %?Qmenu1%
      {
         IfNotInString, A_LoopReadLine, %?Qmenu2%|%?Qmenu3%
            ?write = %?write%%A_LoopReadLine%`n
         Else
            ?write = %?write%%A_LoopReadLine%`n%?Qmenu2%|separator|%?Qmenu2%`n
      }
      Gosub, rebuilding
      ExitApp
   }
   If ?Qmenu4 = Remove_Item
   {
      Loop, Read, %?Qmenu1%
      {
         IfNotInString, A_LoopReadLine, %?Qmenu2%|%?Qmenu3%
            ?write = %?write%%A_LoopReadLine%`n
         Else
            Continue
      }
      Gosub, rebuilding
      ExitApp
   }
   If ?Qmenu4 = Remove_Submenu
   {
      Loop, Read, %?Qmenu1%
      {
         If ?Qmenu2 = main_menu
         {
            MsgBox, 16, , Warning. You cannot remove the main menu!!!
            ExitApp
         }
         IfNotInString, A_LoopReadLine, %?Qmenu2%
            ?write = %?write%%A_LoopReadLine%`n
         Else
            Continue
      }
      Gosub, rebuilding
      ExitApp
   }
   If ?Qmenu4 = Remove_Separator
   {
      ?RemSep = n
      Loop, Read, %?Qmenu1%
      {
         If ?RemSep = y
         {
            IfInString, A_LoopReadLine, %?Qmenu2%|separator
               ?RemSep = n
            Continue
         }
         IfInString, A_LoopReadLine, %?Qmenu2%|%?Qmenu3%
         {
            ?write = %?write%%A_LoopReadLine%`n
            ?RemSep = y
         }
         Else
            ?write = %?write%%A_LoopReadLine%`n
      }
      Gosub, rebuilding
      ExitApp
   }
   If ?Qmenu4 = Insert_Item
   {
      Gui, 2:Add, Button, Default x10 y50 w80 h30, &1-File(s)
      Gui, 2:Add, Button, x110 y50 w80 h30, &2-Folder
      Gui, 2:Add, Button, x210 y50 w80 h30, Cancel
      Gui, 2:Font, s10 w600
      Gui, 2:Add, Text, x40 y10 w220 h30, Browse for files or folders?
      Gui, 2:Show, h90 w300, Choose files
      Return

      2Button1-File(s):
      Gui, 2:Destroy
      FileSelectFile, ?path, 7,, Select files., All Files (*.*)
      Gosub, Insert_Item
      ExitApp
      2Button2-Folder:
      Gui, 2:Destroy
      FileSelectFolder, ?path, , 3,Slect folder.
      Gosub, Insert_Item
      ExitApp
      2ButtonCancel:
      2GuiEscape:
      2GuiClose:
      MsgBox, 64, , Cancelling., 1
      ExitApp
   }
   If ?Qmenu4 = Insert_Submenu
   {
      Gosub, Insert_Submenu
      ExitApp
   }
}

Else
{
   WinGet, ?winID, ID, A
   WinGetClass, ?winClass, ahk_id %?winID%
   If ?winClass in CabinetWClass,ExploreWClass
   {
      Clipboard =
      Sleep, 100
      Send, ^c
      ClipWait, 1
      StringReplace, ?clip, Clipboard, `r`n, `n, All
      Clipboard =
      Loop, Parse, ?clip, `n
      {
         If A_Index = 1
         {
            If A_LoopField in %?drives%
            {
               ?path = %A_LoopField%`n
               ?create = main_menu|%A_LoopField%|%A_LoopField%`n
               ?is_drive = yes
            }
            Else
            {
               SplitPath, A_LoopField, ?filename, ?dir
               ?path = %?dir%`n%?filename%`n
               ?create = main_menu|%?filename%|%A_LoopField%`n
            }
         }
         Else
         {
            If A_LoopField in %?drives%
            {
               ?path = %?path%%A_LoopField%`n
               ?create = main_menu|%A_LoopField%|%A_LoopField%`n
               ?is_drive = yes
            }
            Else
            {
               StringSplit, ?file, A_LoopField, \
               StringTrimLeft, ?filename, ?file%?file0%, 0
               ?path = %?path%%?filename%`n
               ?create = %?create%main_menu|%?filename%|%A_LoopField%`n
            }
         }
      }
   }
   ?tipEMM = Choose a menu file listed in the combobox "Main menu".`nIf there is no menu click the radiobox "New menu" .To add items to a submenu inside the selected Main menu check the option "Existing submenu",for a new submenu check "New submenu".You can change the keys settings for any menu going to tab "Key settings" after selecting a menu in the combobox "Main menu".
   ?tipESM = Select a submenu listed in the combobox "Submenu".`nIf there is no submenu listed you can create one checking "New submenu"
   ?tipNMM = Enter a name for your new menu.Just type the word you want to be the menu title,the same word is also used as filename, the script will be saved with the prefix "«" ,".ahk" extension and "_" replacing spaces.`nEg:DOCUMENTS
   ?tipNSM = Enter a name for your new submenu.`nYou can add a submenu to the Main menu  selecting "top level" in the combobox "Submenu list" or to an existent submenu selecting it in the same combobox.If there is no existent submenu the new submenu will be added to the top level of the main menu.
   ?tipKEY = Choose the keys you want.Most keys ( eg :A-Z and 1-0 ) may launch an menu item, so be careful.`nOption "Single keys" : this option does not need explanations.`nOption "Combined keys" : choose a key to add items and to remove items use the same(MUST be the same) key together with another that will be the modifier key.You must enter the key names using "+" as delimiter.`n`neg: add submenu-- Rcontrol , remove submenu--Rcontrol+Rwin`n       add separator--Lcontrol  ,  remove separator--Lcontrol+Lwin
   ?tipREAD = This script , and the menus generated by it ,  were not made to stay running all the time, just set a hotkey to call the scripts when needed.`n`nFirst step :  You must use the script to generate a specially formatted menu file.`n`nTo create a new menu :`nOpen an explorer window and select one or more files/folders and hit the hotkey to launch the script.`nThe script will copy the files to clipboard and retrieve their paths later , then it will show a GUI ,  in which you must click the "New menu" radiobox , fill a name in the  combobox "main menu" and choose the modifiers keys if you want(if not the default key setting will be used) then hit the button "submit".`nThe new menu will be launched.All new scripts are saved in "WorkingDir".`nYou can also run this script with no files selected , in this case the only menu item will be "click to add item" , you can click it to...add items)`nThe generated menu can be edited in several ways.`n`nDirectly from menu :`nLeftShift+click an item to add new items below the clicked one.`nRightShift+click an item to remove it`nLeftWin+click --add a submenu`nRightWin+click a submenu item to remove the whole submenu`nLeftControl+click--add a separator below the clicked item`nRightControl+click--remove the separator below the clicked item`nclick will... launch item  (You can change the modifiers keys using the GUI)`n`nFrom GUI :`nwell,you can click everywhere to see what happens...`njust be carefull with the button "submit".
   ?menulist =
   Loop, «*.ahk
      {
         ?menulist = %?menulist%%A_LoopFileName%|
      }
   Gui, Add, Tab, x2 y5 w413 h280, Menu Definition||Key settings|--------READ-ME FIRST-------
   Gui, Font, s10
   Gui, Add, Edit, vTip xp+8 yp+30 w395 h90, %?tipEMM%
   Gui, font
   Gui, Add, GroupBox, vGr1 xp yp+100 w230 h140, Define wich menu
   Gui, Add, Text, vMaintext xp+15 yp+15, Main menu
   Gui, Add, ComboBox, gMain vMain xp yp+15 w200, Select one||%?menulist%
   Gui, Add, Text, Disabled vSubtext xp yp+25, Submenu list
   Gui, Add, ComboBox, Disabled vSub xp yp+15 w200, Select one||
   Gui, Add, Text, Disabled vSub2text xp yp+25, New submenu
   Gui, Add, ComboBox, Disabled vSub2 xp yp+15 w200, Enter new submenu name||
   Gui, Add, GroupBox, vGr2 x250 y135 w155 h100, Add files to...
   Gui, Add, Radio, Checked gRadio1 vRadio1 xp+15 yp+20, Existing menu
   Gui, Add, Radio, gRadio2 vRadio2 xp yp+20, New menu
   Gui, Add, Checkbox, Disabled gCheck1 vCheck1 xp yp+20, Existing submenu
   Gui, Add, Checkbox, gCheck2 vCheck2 xp yp+20, New submenu
   Gui, Add, Button, xp-15 yp+30 w70 h30, Cancel
   Gui, Add, Button, Default vBsbmt xp+80 yp w75 h30, Submit
   Gui, Tab, 2
   Gui, Add, GroupBox,  vGr3 x10 y175 w395 h100, Modifiers keys
   Gui, Add, Text,  vTe1 xp+15 yp+15, Add item
   Gui, Add, Edit,  vEd1 xp yp+15 w112 h20, Lshift
   Gui, Add, Text,  vTe2 xp yp+25, Remove item
   Gui, Add, Edit,  vEd2 xp yp+15 w112 h20, Rshift
   Gui, Add, Text,  vTe3 xp+127 yp-55, Add submenu
   Gui, Add, Edit,  vEd3 xp yp+15 w112 h20, Lwin
   Gui, Add, Text,  vTe4 xp yp+25, Remove submenu
   Gui, Add, Edit,  vEd4 xp yp+15 w112 h20, Rwin
   Gui, Add, Text,  vTe5 xp+127 yp-55, Add separator
   Gui, Add, Edit,  vEd5 xp yp+15 w112 h20, Lcontrol
   Gui, Add, Text,  vTe6 xp yp+25, Remove separator
   Gui, Add, Edit,  vEd6 xp yp+15 w112 h20, Rcontrol
   Gui, Add, Radio, Checked gRadio3 vRadio3 x20 y155, Single keys
   Gui, Add, Radio, gRadio4 vRadio4 xp+125 y155,  Combined keys
   Gui, Add, Button, xp+103 yp-4,  Change-selected-menu-hotkeys
   Gui, Font, s10
   Gui, Add, Edit, vTip2 x10 y35 w395 h110, %?tipKEY%
   Gui, Tab, 3
   Gui, Add, Edit, x10 y35 w395 h235, %?tipREAD%
   Gui,Font
   Gui, Show, w415, Menu tool
   Return

   GuiEscape:
   GuiClose:
   ButtonCancel:
   MsgBox, 64, ,Cancelling., 1
   ExitApp
   Main:
   GuiControlGet, ?ver, , Main
   ?num = 1
   ?subnum =
   ?submenulist =
   Loop, Read, %?ver%
   {
      If A_LoopReadLine = */
         Break
      IfNotInString, A_LoopReadLine, |sm|
         Continue
      Else
      {
         StringSplit, ?submenu, A_LoopReadLine, |
         If ?num = 1
         {
            ?subnum = %A_LoopReadLine%`n
            ?submenulist = |%?submenu2%||
            ?num ++
         }
         Else
         {
            ?subnum = %?subnum%%A_LoopReadLine%
            ?submenulist = %?submenulist%%?submenu2%|
            ?num ++
         }
      }
   }
   If ?submenulist =
   {
      GuiControl, , Sub, |there is no submenu||
      GuiControl, Disable, Sub
      GuiControl, Disable, Subtext
      GuiControl, Disable, Check1
   }
   Else
   {
      GuiControl, Enable, Sub
      GuiControl, Enable, Subtext
      GuiControl, Enable, Check1
      GuiControl, , Sub, %?submenulist%
   }
   Return
   Check1:
   GuiControlGet, ?chk1, , Check1
   GuiControlGet, ?rad1, , Radio1
   If ?chk1 = 1
   {
         GuiControl, Enable, Sub
         GuiControl, Enable, Subtext
         GuiControl, , Tip, %?tipESM%
         GuiControl, , Sub, %?submenulist%top level
   }
   If ?chk1 = 0
   {
         GuiControl, Disable, Sub
         GuiControl, Disable, Subtext
         If ?rad1 = 1
            GuiControl, , Tip, %?tipEMM%
         Else
            GuiControl, , Tip, %?tipNMM%
   }
   Return
   Check2:
   GuiControlGet, ?chk2, , Check2
   GuiControlGet, ?rad1, , Radio1
   If ?chk2 = 1
   {
         GuiControl, Enable, Sub2
         GuiControl, Enable, Sub2text
         GuiControl, , Tip, %?tipNSM%
   }
   If ?chk2 = 0
   {
         GuiControl, Disable, Sub2
         GuiControl, Disable, Sub2text
         If ?rad1 = 1
            GuiControl, , Tip, %?tipEMM%
         Else
            GuiControl, , Tip, %?tipNMM%
   }
   Return
   Radio1:
   GuiControl, Enable, Check1
   GuiControl, Enable, Check2
   GuiControl, , Main, |Select one||%?menulist%
   GuiControl, , Tip, %?tipEMM%
   Return
   Radio2:
   GuiControl, , Check1, 0
   GuiControl, , Check2, 0
   GuiControl, Disable, Sub
   GuiControl, Disable, Sub2
   GuiControl, Disable, Check1
   GuiControl, Disable, Check2
   GuiControl, , Tip, %?tipNMM%
   GuiControl, , Main, |Enter menu name||
   Return
   Radio3:
   GuiControl, , Ed1, Lshift
   GuiControl, , Ed2, Rshift
   GuiControl, , Ed3, Lwin
   GuiControl, , Ed4, Rwin
   GuiControl, , Ed5, Lcontrol
   GuiControl, , Ed6, Rcontrol
   Return
   Radio4:
   GuiControl, , Ed1, Lshift
   GuiControl, , Ed2, Lshift+Lwin
   GuiControl, , Ed3, capslock
   GuiControl, , Ed4, capslock+Lwin
   GuiControl, , Ed5, Lcontrol
   GuiControl, , Ed6, Lcontrol+Lwin
   Return
   ButtonChange-selected-menu-hotkeys:
   Gui, Submit, NoHide
   If Radio4 = 1
   {
      StringSplit, Ed2rem, Ed2, +
      Ed2 = %Ed2rem2%
      StringSplit, Ed4rem, Ed4, +
      Ed4 = %Ed4rem2%
      StringSplit, Ed6rem, Ed6, +
      Ed6 = %Ed6rem2%
   }
   If Main contains Select one,Enter menu name
   {
      MsgBox, No menu script selected!!
      Return
   }
   ?new_keys = ?key_add_item = %Ed1%`n?key_rem_item = %Ed2%`n?key_add_submenu = %Ed3%`n?key_rem_submenu = %Ed4%`n?key_add_separator = %Ed5%`n?key_rem_separator = %Ed6%`n
   MsgBox, 33, Are you sure?, File to edit:`n%Main%`n`nNew keys:`n%?new_keys%
   IfMsgBox, Cancel
   {
      MsgBox, 64, ,Cancelling., 1
      Return
   }
   Gosub, Change_keys
   Return
   ButtonSubmit:
   GuiControlGet, ?verver, , Main
   If ?verver contains Select one,Enter menu name
   {
      MsgBox, No main menu selected!!
      Return
   }
   Gui, Submit
   ?via_gui = yes
   ?Qmenu1 = %Main%
   ?Qmenu3 = last_item
   If Radio1 = 1
   {
      If Check2 = 0
      {
         If Check1 = 0
            ?Qmenu2 = main_menu
         Else If Check1 = 1
         {
            Loop, Parse, ?subnum, `n
            {
               IfInString, A_LoopField, %Sub%
               {
                  StringSplit, ?Qsubmenu, A_LoopField, |
                  ?Qmenu2 = %?Qsubmenu1%
               }
            }
         }
         Gosub, Insert_Item
         ExitApp
      }
      Else If Check2 = 1
      {
         ?Qmenu2 = sub_menu%?num%
         If Check1 = 0
            ?upper_menu = main_menu
         Else
         {
            If Sub contains no submenu,top level,Select one
               ?upper_menu = main_menu
            Else
               Loop, Parse, ?subnum, `n
               {
                  IfInString, A_LoopField, %Sub%
                  {
                     StringSplit, ?Qsubmenu, A_LoopField, |
                     ?upper_menu = %?Qsubmenu1%
                  }
               }
         }
         Gosub, Insert_Submenu
         ExitApp
      }
   }

   Else If Radio2 = 1
   {
      ?new_menu = yes
      ?Qmenu2 = main_menu
      ?Qmenu3 = null
      Gosub, create_menu
      If ?try_again = yes
      {
         Gui, Show
         Return
      }
      Else
         ExitApp
   }
}

Insert_Item:
If ?path =
{
   MsgBox, 64, ,Cancelling. No items to add., 1
   ExitApp
}
Gosub, define_items
Loop, Read, %?Qmenu1%
{
   IfInString, A_LoopReadLine, %?Qmenu2%|%?Qmenu3%
   {
      If ?Qmenu3 = Click to Add Item
         ?write = %?write%%?items%
      Else If ?Qmenu3 = last_item
         ?write = %?write%%?items%%A_LoopReadLine%`n
      Else
         ?write = %?write%%A_LoopReadLine%`n%?items%
   }
   Else
      ?write = %?write%%A_LoopReadLine%`n
}
Gosub, rebuilding
Return

Insert_Submenu:
If ?via_gui <> yes
   InputBox, ?sub_name, New submenu, Enter a name for your new submenu., ,300, 130
   If ErrorLevel <> 0
   {
      MsgBox, 64, ,Cancelling., 1
      ExitApp
   }
Gosub, define_items
?num = 1
Loop, Read, %?Qmenu1%
{
   IfInString, A_LoopReadLine, sub_menu%?num%
      ?num++
   If A_LoopReadLine = */
   {
      If ?via_gui <> yes
         ?write = %?write%%?Qmenu2%|separator|sub_menu%?num%`nsub_menu%?num%|Click to Add Item|temp_item`nsub_menu%?num%|last_item`nsub_menu%?num%|%?sub_name%|sm|%?Qmenu2%`n%A_LoopReadLine%`n
      Else
      {
         If ?items =
            ?write = %?write%%?upper_menu%|separator|sub_menu%?num%`nsub_menu%?num%|Click to Add Item|temp_item`nsub_menu%?num%|last_item`nsub_menu%?num%|%Sub2%|sm|%?upper_menu%`n%A_LoopReadLine%`n
         Else
            ?write = %?write%%?upper_menu%|separator|sub_menu%?num%`n%?items%sub_menu%?num%|last_item`nsub_menu%?num%|%Sub2%|sm|%?upper_menu%`n%A_LoopReadLine%`n
      }
   }
   Else
      ?write = %?write%%A_LoopReadLine%`n
}
Gosub, rebuilding
Return

create_menu:
?settings = SetWorkingDir, %A_ScriptDir%`n?items =`n?key_add_item = %Ed1%`n?key_rem_item = %Ed2%`n?key_add_submenu = %Ed3%`n?key_rem_submenu = %Ed4%`n?key_add_separator = %Ed5%`n?key_rem_separator = %Ed6%`n
StringReplace, Main, Main, %A_SPACE%, _, All
IfExist, «%Main%.ahk
{
   MsgBox, 49,Paused...,File «%Main%.ahk already exists.`nRetry?.
   IfMsgBox, Cancel
      ExitApp
   IfMsgBox, Ok
      ?try_again = yes
   Return
}
Loop, Parse, ?menu_items, `n
{
   IfInString, A_LoopField, Click to Add Item
   {
      If ?create =
         ?write = %?write%%A_LoopField%`n
      Else
         ?write = %?write%%?create%
   }
   Else
      ?write = %?write%%A_LoopField%`n
}
?write = %?write%%?settings%
StringReplace, ?menu_mount,  ?menu_mount, •TITLE, %Main%, All
?write = %?write%%?menu_mount%
If Radio3 = 1
   ?write = %?write%%?single%
Else
   ?write = %?write%%?combined%
?write = %?write%%?common%
FileAppend, %?write%, «%Main%.ahk
Run, «%Main%.ahk
Return

Change_keys:
StringTrimLeft, ?menu_title, Main, 1
StringTrimRight, ?menu_title, ?menu_title, 4
?change = yes
?write =
Loop, Read, %Main%
{
   IfInString, A_LoopReadLine, ?key_
      Continue
   Else IfInString, A_LoopReadLine, Add, %?menu_title%
   {
      ?write = %?write%%?new_keys%
      Break
   }
   Else
      ?write = %?write%%A_LoopReadLine%`n
}
StringReplace, ?menu_mount,  ?menu_mount, •TITLE, %?menu_title%, All
?write = %?write%%?menu_mount%
If Radio4 = 1
   ?write = %?write%%?combined%
Else
   ?write = %?write%%?single%
?write = %?write%%?common%
FileDelete, %Main%
FileAppend, %?write%, %Main%
Return

define_items:
IfInString, ?path, `n
{
   ?teste = multi
   StringTrimRight, ?path, ?path, 1
}
IfNotInString, ?path, `n
   ?teste = mono
?items =
Loop, Parse, ?path, `n
{
   If A_Index = 1
   {
      If ?teste = multi
         If ?is_drive = yes
            ?items = %?Qmenu2%|%A_LoopField%|%A_LoopField%`n
         Else
            ?dir = %A_LoopField%\
      If ?teste = mono
      {
         IfInString, A_LoopField, %?Qmenu3%
         {
            MsgBox, 16, Ignoring Item, Item: "%A_LoopField%"`nthis item already exists in this menu., 2
            ExitApp
         }
         Else
         {
            SplitPath, A_LoopField, ?filename
            If ?filename =
               ?is_drive = yes
            If ?is_drive = yes
               ?items = %?Qmenu2%|%A_LoopField%|%A_LoopField%`n
            Else
               ?items = %?Qmenu2%|%?filename%|%A_LoopField%`n
            Break
         }
      }
   }
   Else
   {
      IfInString, A_LoopField, %?Qmenu3%
      {
         MsgBox, 16, Ignoring Item, Item: "%A_LoopField%"`nthis item already exists in this menu., 2
         Continue
      }
      Else
         If ?is_drive = yes
            ?items = %?items%%?Qmenu2%|%A_LoopField%|%A_LoopField%`n
         Else
            ?items = %?items%%?Qmenu2%|%A_LoopField%|%?dir%%A_LoopField%`n
   }
}
Return

rebuilding:
FileDelete, %?Qmenu1%
FileAppend, %?write%, %?Qmenu1%
Run, %?Qmenu1%
Return

Sorry for my poor English :oops: I hope you understand what I wrote,
the portuguese version is much clearer...


Last edited by Gre on November 9th, 2004, 5:58 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2004, 6:15 am 
Offline

Joined: September 2nd, 2004, 1:08 am
Posts: 124
Location: Sunnyvale
Wow!! Nice!

I like your use of the tab controls.

I created a "new menu" pointing to a folder with no problem. I'm going to experiment more with it using submenus to several folders.

Good work! :D

_________________
I am he of whom he speaks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2004, 2:12 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Very elaborate; nice work.

I only tried it briefly so I don't think I fully understand the typical/main uses for it (though obviously the dynamic menus are very nice!) What might be good (if you or anyone has time someday) is to give is a real-world example, step by step, of how the script could make someone's life easier, such as by building and updating a menu of "favorite documents".

I also really like how easy it is to build submenus off the main menu. Thanks for sharing it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2004, 1:32 am 
Offline

Joined: October 12th, 2004, 11:34 pm
Posts: 74
Location: São Paulo ,Brazil
It will be a little difficult to give explanations in English.I am using a web translator to write my posts and you know...web translators are not very smart.
Is it OK to put several images in my post ?If it is ok I will try to post something understandable later,I am working now.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2004, 2:06 am 
Offline

Joined: August 26th, 2004, 3:11 pm
Posts: 80
Location: Chelsea - MA, USA
Quote:
It will be a little difficult to give explanations in English.I am using a web translator to write my posts and you know...web translators are not very smart.
You could talk to me in portuguese and let me translate some of your work if you want... 8)

_________________
Working now on:
NumpadMouse v2 (Draw)
top-recode project (private server script) (pkodev)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2004, 3:13 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Quote:
Is it OK to put several images in my post ?
Yes that's fine.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2004, 6:21 am 
Offline

Joined: October 12th, 2004, 11:34 pm
Posts: 74
Location: São Paulo ,Brazil
Script updated
Sorry,there was a stupid mistake in the script,it was working only with CabinetWClass windows and not with ExploreWClass,because I never use explorer.exe,now it is working ok.

Hi,deguix
I really appreciate your offer,but I already had prepared this post before read yours...let me try again :wink:

Quote:
I created a "new menu" pointing to a folder with no problem. I'm going to experiment more with it using submenus to several folders.
Seems you also don't use explorer.exe :)


I think this script can be useful when:
Browsing explorer windows I find some files I wish to put in a menu to have easy access.
With sure I can create hotkeys to launch these files, but I have too many hotkeys, and already forgot a lot of them ,
so I think it is a good idea to use menus.I have menus for everything, system tools, web tools, utilities, AHK scripts, documents...etc.Frequently I want
to add items to my menus, and also frequently I want to remove some items , specially old Documents and Scripts,
The down side of menus is that we must open and edit the script when we want to modify something, or create a new script for a new menu...
then I wrote this script , just to turn menu creation/modification easier.

I will try to describe the script usage.
First save the script anywhere you want and create a hotkey ,in your main script for example(I use Autohotkey.ini), to launch it.

Creating new menus:
1-Open the folfer with the files you want.Select (highlight) how many files or folders you wish and press the hotkey to call the script.
Image
2-If it is the first run, you must click the radiobox "New menu", fill a name for the new menu in the combo "main menu" and press "submit".
Image
A new script(menu) will be created with the selected files ( in step 1) as items,(If there was no file selected the new menu will
show the item "Click to add items" click it and a FileSelectFile dialog will appear).
note:All created scripts are saved with the prefix"«".
Image
Now editing existing menus:
3-Repeat the step 1 above.If the radiobox "Existing menu" is checked( default is checked) all menus created by this
script( those with "«" prefix) will be listed in the combobox "Main menu",just select one to edit and press "submit"
Image
4-you can also insert submenus inside main menu top level or inside any existing submenu checking the checkbox "new menu"( if there is no
submenu the checkbox "existing submenu" is disabled) ,press submit...
Image
the edited menu will appear
Image
5-Now you have a menu with a submenu inside and you can add submenus into submenus checking "existing menu" , "existing submenu" and "new submenu"
Image
the edited menu will appear
Image
The generated script can be edited directly from menu,default keys are used in this description:
LeftShift+click an item to add new items below the clicked one.
RightShift+click an item to remove it
LeftWin+click --add a submenu
RightWin+click a submenu item to remove the whole submenu
LeftControl+click--add a separator below the clicked item
RightControl+click--remove the separator below the clicked item

example:
Lshift+click an item...
Image
these dialogs will appear in sequence, select one or more files...
Image
hit "open" and the menu will be updated.
Image

To add submenus:
LeftWin+click a item in the main menu or any submenu
Image
Enter a name in this dialog, hit OK...
Image
the result will look like this image,clicking "Click to add items" will start the same actions performed by "Lshift+click an item" described above
Image
Important:
Be careful with the remove submenu command(RightWin+click) it will remove the submenu and all its contents including submenus

I guess that the other actions(add/remove separators,remove items) do not need explanations


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2004, 5:08 pm 
Gre, I don't know if I missed this and it's already possible with your script. But, is it possible to have it assign a hotkey to the generated script so that the generated script can sit in the system tray and be called at any time?

To do this manually, here is what I changed in the generated script.

Code:
;Menu, main_menu, show
Return

#x::
Menu, main_menu, show
Return


Thanks


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2004, 5:12 pm 
Offline

Joined: September 2nd, 2004, 1:08 am
Posts: 124
Location: Sunnyvale
Sorry. I thought I was logged in when I posted this...

Anonymous wrote:
Gre, I don't know if I missed this and it's already possible with your script. But, is it possible to have it assign a hotkey to the generated script so that the generated script can sit in the system tray and be called at any time?

To do this manually, here is what I changed in the generated script.

Code:
;Menu, main_menu, show
Return

#x::
Menu, main_menu, show
Return


Thanks

_________________
I am he of whom he speaks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2004, 5:29 pm 
Phhhhh. I thought about to start playing the GUI game as most of you folks seems quite attracted by its features. Now I'm a l'iiiill demotivated :oops: :wink:

@ Gre
Hell what a script. Congrats :D
btw: would you mind to provide your Gertrude.ahk as well :lol:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2004, 5:50 pm 
Offline

Joined: October 12th, 2004, 11:34 pm
Posts: 74
Location: São Paulo ,Brazil
Hi.
Well, in my opinion it is better add a hotkey to the "main" script (eg:Autohotkey.ini) to call the generated script(#x:Run, c:\menus\«generated_menu.ahk
it will be launched really fast),because the script is "working" only when it is showing a menu,then if it is kept running it will do nothing almost all the time.
Another thing,if the script is running full time a Reload command must be used after each modification.

@BoBo
Thanks BoBo :D

and Gertrude is just a test menu.I really don't know why this name came to my mind! :shock:


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 8th, 2005, 9:52 pm 
Offline

Joined: October 8th, 2005, 7:08 pm
Posts: 5
Hi there,
This is very useful to me. Can I make this menu to be made accessible through the right click? I mean like below:

1) I right click on a text file , then i am looking to get mymenu item appear as the last menuitem.
2) when i mouseover on that last menu item , then a submenu dynamically popsup listing out the all lines in it. one line per each submenuitem. It would be ok if I just see the first 5 characters of each line as a submenuitem.

Could this possible using AutoHotKeys? Or should I try any else similar to this?

Thanks,

Sekhar


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: nomissenrojb, Stigg and 12 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