
Specificity of selection for submenus with PopupContextualMenu

I have run into some behavior that I don't know how to resolve (Igor 8, Mac). I have an interface that uses PopupContextualMenu, and the menu has a submenu of a list of waves. I want to add a second submenu that offers a different operation but on the same list of waves. The problem is that v_value and s_selection seem to return values referring to their individual submenus, and do not report which item in the parent menu was selected.
I've written a simplified example to illustrate the basic problem:
menu "Tester", contextualmenu submenu "action 1" "wave1" "wave2" end submenu "action 2" "wave1" "wave2" end end function testMenu () PopupContextualMenu /N "Tester" print v_kind, v_flag, s_selection end
If you enter "testmenu ()" on the command line, it will give you the popup menu. If you select action1->wave1, you get the same v_kind, v_flag, and s_selection as if you had selected action2->wave1. So, how can I distinguish the two? Any suggestions for a work-around? Is renaming the items in my submenus the best choice? I am grateful for suggestions.
-Matthew

Forum

Support

Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
September 5, 2019 at 02:08 am - Permalink
Here's a workaround similar to Tony's, but it doesn't require a global variable
September 5, 2019 at 07:14 am - Permalink
Thanks, tony and gsb. I hadn't thought of that. I will try it.
-Matthew
September 5, 2019 at 08:44 am - Permalink
Actually, you don't even need the extra function if you take the global route:
The advantage of using global string is that you don't transfer execution to a different, isolated function. The disadvantage is that it uses a global string.
September 5, 2019 at 09:02 am - Permalink
That's a nice trick. I was a bit worried if it would work for my actual problem. The submenus are dynamic, lists of waves returned by a string function. I think that function calls can't be attached to individual menu items specified using semicolon-delimited strings ("item1;item2"). However, I can put the function call after the dynamic call. So, the below is a better representation of my situation, and your solutions will work. So, thanks again!
-Matthew
September 5, 2019 at 09:25 am - Permalink