lunedì 12 marzo 2012 14:16
I can add a menu to the context menu in the solution explorer by setting the parent to
I can also apply DynamicVisibility to this command (button).
Now I want to move this command to a sub menu, so I add a Menu, then set this Menu as the parent of my previous group (there are more). Anyway, I can see my "top-level" menu and the submenu item. But how can I make this "top-level" menu display only in some conditions, i.e. when selected file has a "compile" action.
I follow the instruction on this page
I also check the SDK sample, but I can't find a way to hide the whole "Parent Menu". How can I get the "Menu" object and wire up the BeforeQueryStatus event to it?
Tutte le risposte
lunedì 12 marzo 2012 21:02Moderatore
Menu visibility is based on at least one child being visible. Alternatively you can tag the Menu with the DynamicVisibility command flag and add a QueryStatus handler for the Menu's ID and specificy its visibility that way, doing this 'overrides' the visibility based on one visible child.
- Contrassegnato come risposta Sowen giovedì 15 marzo 2012 13:46
giovedì 15 marzo 2012 05:30Moderatore
I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?
Yi Feng Li [MSFT]
MSDN Community Support | Feedback to us
giovedì 15 marzo 2012 13:46
Thanks for the answer
unfortunately, I was frustrated how the whole vsct is structured. I have to add a group for all commands, add a menu as the group's parent, and then add another group for the menu's parent, the latter group is set to the item_node, it's so not intuitive
when no command is visible, the menu is invisible too, that part works fine; but I am not sure how I can get the menu object, so I can only need to wire up one querystatus event to the menu object, instead of wiring it to all child commands
I now have to do this to all my commands under this menu
CommandID menuCommandID = new CommandID(GuidList.guidEnhancementVSCmdSet, (int)PkgCmdIDList.cmdAddCustom); OleMenuCommand menuItem = new OleMenuCommand(HandleAddCustom, menuCommandID); menuItem.BeforeQueryStatus += new EventHandler(HandleAddCustomBeforeQueryStatus);
sabato 17 marzo 2012 18:56Moderatore
>unfortunately, I was frustrated how the whole vsct is structured. I have to add a group for all commands, add a menu as the group's parent, and then add another group for the menu's parent, the latter group is set to the item_node, it's so not intuitive
Well technically you don't HAVE to create a new group for your menu's parent, you can place it in an existing group. I agree, for simple things it does seem fairly complicated, the power comes when you are multiplacing entire groups or doing group level inclusion/exclusion like VS does to build different SKUs (i.e. Express vs. Ultimate vs. Isolate Shell, etc...)
>when no command is visible, the menu is invisible too, that part works fine; but I am not sure how I can get the menu object, so I can only need to wire up one querystatus event to the menu object, instead of wiring it to all child commands
What do you mean by 'the menu object'? When you use MPF (like you are showing in your above example) and you do something like new CommandID or new OleMenuCommand you aren't getting any 'menu object', you are simply creating data for MPF which it uses to look up callback handlers when your WindowPane/Packages QueryStatus method is called by the shell. You would create an entry for a menu just like you do for a command, you supply the GUID/DWORD (int) and then you register it with the menu command service. If your menu for that id is marked with DynamicVisibility in the VSCT and you have a BeforeQueryStatus handler set up for the menu item entry it should be invoked when the visbility of the menu itself needs to be determined.