Hiding User-defined Extensions to Built-in Menus
Ken
I have created extensions (submenus) to the pre-existing menu "GraphMarquee." However, the functions of these extensions only make sense in the context of one of my graphs, so I would like for the added menu items to only appear on one of my graphs and not the other. It seems that HideIgorMenus cannot affect marquee menus. Is there a way to hide user-defined graphmarquee submenus for a specific graph?
Thanks.
Check out dynamic menus:
DisplayHelpTopic "Dynamic Menu Items"
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
June 8, 2011 at 09:14 am - Permalink
String name = WinName(0,1) // Name of top graph
if (CmpStr(name,"Graph0") == 0)
return "Hello"
endif
return "" // No menu item if not Graph0
End
Menu "GraphMarquee", dynamic
MyItem(), /Q, Print "Hello"
End
June 8, 2011 at 09:29 am - Permalink
How would I alter the code to create submenus within each new entry in the GraphMarquee menu? Replacing the first "hello" with "Submenu \"Submenu name\"" does not work.
June 8, 2011 at 02:49 pm - Permalink
/Q means "don't echo the command to the history area." The command in this case is Print "Hello".
I don't think there is any way to have an optional submenu. The best you can do is to have a submenu with the item removed:
Submenu "MySubMenu"
MyItem(), /Q, Print "Hello"
End
End
Or you can leave the item but have it disabled:
String name = WinName(0,1) // Name of top graph
if (CmpStr(name,"Graph0") == 0)
return "Hello"
endif
return "(Hello" // Disabled menu item if not Graph0
End
Menu "GraphMarquee", dynamic
Submenu "MySubMenu"
MyItem(), /Q, Print "Hello"
End
End
June 8, 2011 at 02:54 pm - Permalink
Menu "GraphMarquee", dynamic
Submenu "A"
MarqueeOption(1,0), /Q, execute "Function(0)"
MarqueeOption(1,1), /Q, execute "Function(1)"
end
Submenu "B"
MarqueeOption(2,0), /Q, "Alpha"
MarqueeOption(2,1), /Q, "Beta"
end
MarqueeOption(3,0), /Q, execute "Gamma"
MarqueeOption(3,1), /Q, execute "Delta"
End
function/S MarqueeOption(id,subid)
variable id, subid
string Active_window = WinName(0,1)
if(CmpStr(Active_window,"Desired_Window1") == 0)
switch(id)
case 1:
switch(subid)
case 0:
return "Name1"
break
case 1:
return "Name2"
break
endswitch
case 2:
switch(subid)
case 0:
return "Name3"
break
case 1:
return "Name4"
break
endswitch
case 3:
switch(subid)
case 0:
return "(Name5"
break
case 1:
return "(Name6"
break
endswitch
endswitch
elseif(CmpStr(Active_window,"Desired_Window2") == 0)
switch(id)
case 1:
switch(subid)
case 0:
return "(Name1"
break
case 1:
return "(Name2"
break
endswitch
case 2:
switch(subid)
case 0:
return "(Name3"
break
case 1:
return "(Name4"
break
endswitch
case 3:
switch(subid)
case 0:
return "Name5"
break
case 1:
return "Name6"
break
endswitch
endswitch
endif
end
The code as it stands now seems a little inefficient, and makes me wonder if there is a better way. I still have not figured out if it is possible to hide submenus entirely depending on the active window, and if so, how to go about it. At least the code works for the most part like I want it to. Please let me know if you find anything. Thanks.
June 9, 2011 at 06:14 am - Permalink
I don't know why you are using Execute in the menu definition. It is not needed. Just use:
MarqueeOption(1,1), /Q, Function(1)
If I were you, I would split MarqueeOption into three functions, MarqueeOption1, MarqueeOption2, MarqueeOption3. This would make the code easier to follow.
Finally, when you post Igor code here, use the igor tags as shown at http://www.igorexchange.com/node/add/code-snippet.
June 9, 2011 at 08:48 am - Permalink
June 10, 2011 at 10:21 am - Permalink