Hiding User-defined Extensions to Built-in Menus

Hi,

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.
Here is a graph marquee item that appears only if the graph name is Graph0:
Function/S MyItem()
    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

I understand most of how your code above works. The first "hello" in the code seems to be the name of the extension to the menu, while the second "hello" seems to be the action that accompanies selecting the "hello" in the GraphMarquee menu. However, the line MyItem(), /Q, Print "Hello" puzzles me. I have never seen commas used this way. Can you clarify what that line does?

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.
The menu item is "Hello" if the graph is named Graph0 or "" otherwise. "" causes the item to not appear in the menu.

/Q means "don't echo the command to the history area." The command in this case is Print "Hello".

Quote:
How would I alter the code to create submenus within each new entry in the GraphMarquee menu?


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:
Menu "GraphMarquee", dynamic
    Submenu "MySubMenu"
        MyItem(), /Q, Print "Hello"
    End
End


Or you can leave the item but have it disabled:
Function/S MyItem()
    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


Thank you. I have my code working now using the disabling extensions method.

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.
I don't think it is possible to hide submenus.

I don't know why you are using Execute in the menu definition. It is not needed. Just use:
MarqueeOption(1,0), /Q, Function(0)
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.
Thanks. I was wondering why my code didn't show up in its original format when I pasted it on here. I'll use the code snippet in the future.