Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
expandable menu macros
#1
Hi!

As of version 2.2.0 it is possible to expand file folders, ie automatically create submenus of files. This is really nice. But wouldn't it be great to be able to get the same effect with menu macro's? Suppose I have a menu macro like this:

macro1:
Code:
Copy      Help
>labelA
  item1
  labelB macro2
  item2
  item3
  <
item4
item5
... and another menu macro like

macro2:
Code:
Copy      Help
itemA
itemB
itemC
If macro2 is set to expand (e.g. via an option) then macro1 would act like

Code:
Copy      Help
>labelA
  item1
  >labelB
    itemA
    itemB
    itemC
    <
  item2
  item3
  <
item4
item5
This feature would have the following extra advantages:
a. macro can be re-used in other macro's
b. macro can have its own trigger if used as stand-alone menu
c. nice hover effect if macro is a button on toolbar

Please disregard this wish if it's already possible to accomplish. But please tell me how.

Thanks & Regards.
#2
Function TemplateMenu
Code:
Copy      Help
;\
function# $template [$tempitemname] [sync]

;Shows popup menu created at run time.
;Replaces every {menuname} in template text with submenu created
;;;from a menu (QM item) whose name is menuname.
;{menuname} must be at the beginning of a line. It can be preceded
;;;by tabs. If it is followed by more text in the same line, the
;;;menu name is not inserted.
;If menu menuname does not exist, removes the line.


;template - menu text (if multiline), or existing menu name (if single line).
;tempitemname - the name of the temporary menu. Default: "temp_menu".
;sync - if nonzero, waits and returns 1-based index of selected line.



str s sn st sr si; int i
ARRAY(CHARRANGE) a

if(findc(template 10)<0) s.getmacro(template)
else s=template

if(findrx(s "^\t*\{(.+?)\}([^[]]*)$" 0 12 a))
,for i a.len-1 -1 -1
,,CHARRANGE r(a[0 i]) rn(a[1 i]) ri(a[2 i])
,,sn.get(s rn.cpMin rn.cpMax-rn.cpMin)
,,st.getmacro(sn); err s.remove(r.cpMin r.cpMax-r.cpMin+2); continue
,,st.rtrim("[]")
,,if(ri.cpMax>ri.cpMin) si.get(s ri.cpMin ri.cpMax-ri.cpMin); sn=""; else si=""
,,sr.format(">%s%s[]%s[]<" sn si st)
,,s.replace(sr r.cpMin r.cpMax-r.cpMin)

;out s
ret DynamicMenu(s tempitemname sync)
err+ end _error

Example
Code:
Copy      Help
TemplateMenu "tm main"

Menu "tm main" (example)
Code:
Copy      Help
Macro492 :mac "Macro492"
{tm sub 1}
>sub
,Macro492 :mac "Macro492"
,{tm sub 2}Mouse * mouse.ico
,<
Macro492 :mac "Macro492"

Menu "tm sub 1" (example)
Code:
Copy      Help
Function48 :mac "Function48"
Function48 :mac "Function48"

Menu "tm sub 2" (example)
Code:
Copy      Help
Function47 :mac "Function47"
Function47 :mac "Function47"
#3
Man, this is awesome. Works like a charm! Thank you very much Gintaras.

(do you want to remove this request from the wish list and put it in the general or programming section?)
#4
Quote:do you want to remove this request from the wish list and put it in the general or programming section?)

The functions is what we can do today. In the future, QM menus and toolbars should support something similar.


Forum Jump:


Users browsing this thread: 2 Guest(s)