In my VS extension, I need to add a menu item for my new project type. But I want it to show only for my custom type. So I added this code to the .vcst file:
<Button guid="_Interactive_WindowCmdSet" id="cmdidLoadUI" priority="0x0100" type="Button"> <Parent guid="_Interactive_WindowCmdSet" id="ProjectItemMenuGroup" /> <Icon guid="guidImages" id="bmpPic1" /> <CommandFlag>DynamicVisibility</CommandFlag> <Strings> <ButtonText>Load</ButtonText> </Strings> </Button> <Group guid="_Interactive_WindowCmdSet" id="ProjectItemMenuGroup" priority="0x0600"> <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_PROJNODE"/> </Group>
And added this code to initialize the package:
// Create the command for the menu item. CommandID projectMenuCommandID = new CommandID(GuidList.Interactive_WindowCmdSet, (int)PkgCmdIDList.cmdidLoadUI); OleMenuCommand projectmenuItem = new OleMenuCommand(LoadUIMenuItemCallback, projectMenuCommandID); projectmenuItem.BeforeQueryStatus += projectmenuItem_BeforeQueryStatus; mcs.AddCommand(projectmenuItem);
And the request state handler:
private void projectmenuItem_BeforeQueryStatus(object sender, EventArgs e) { OleMenuCommand menuCommand = sender as OleMenuCommand; if (menuCommand != null) menuCommand.Visible = IsProjectOfRightType(GetSelected<Project>()); }
The problem is that this status handler is never called. Therefore, I have this menu item shown for all types of projects.
I also tried implementing the IOleCommandTarget interface on my package, for example:
public int QueryStatus(ref Guid guidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { // Disable all commands in case if project is VisuaART project, otherwise - disable them. OLECMDF cmdf; for (int i = 0; i < cCmds; i++) { var command = prgCmds[i]; if (command.cmdID == PkgCmdIDList.cmdidLoadUI) { if (IsProjectOfRightType(GetSelected<Project>())) command.cmdf = (uint)COMMAND_SUPPORTED; else command.cmdf = (uint)COMMAND_UNSUPPORTED; } } return VSConstants.S_OK; } private const OLECMDF COMMAND_SUPPORTED = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED; private const OLECMDF COMMAND_UNSUPPORTED = OLECMDF.OLECMDF_INVISIBLE;
But that didn't help either. The method is called, but setting OLECMDF.OLECMDF_INVISIBLE does nothing. What needs to be done to hide this menu item for unsupported menu items?
c # visual-studio visual-studio-2010 visual-studio-2012 vsix
Seekeer
source share