我想在 Visual Studio 2012 解决方案资源管理器中的右键单击 => 添加菜单中添加一个菜单项。单击自定义项目时,我可以使用我的模板添加项目。我开发了一个 Visual Studio 插件来做到这一点,但我遇到了一些麻烦。我可以将菜单项添加到右键菜单中,但无法满足我的要求。
menuitem 应该是“添加”的子菜单。不是根项目。
我还需要仅在右键单击名为“Areas”的文件夹时才显示菜单项。当我右键单击其他文件夹时,我不希望它显示。
这是我的OnConnection
功能代码。我怎样才能改变它以满足我的要求。
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = ((AddIn)addInInst);
if (connectMode == ext_ConnectMode.ext_cm_UISetup)
{
object[] contextGUIDS = new object[] { };
Commands2 commands = (Commands2)_applicationObject.Commands;
//Place the command on the tools menu.
//Find the MenuBar command bar, which is the top-level command bar holding all the main menu items:
var bars=((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars);
Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = bars["MenuBar"];
//Find the Tools command bar on the MenuBar command bar:
//CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
//CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;
// get popUp command bars where commands will be registered.
CommandBars cmdBars = (CommandBars)(_applicationObject.CommandBars);
//CommandBar vsBarItem = cmdBars["Item"]; //the pop up for clicking a project Item
CommandBar vsBarFolder = cmdBars["Web Project Folder"];
CommandBar vsBarWebFolder = cmdBars["Web Folder"];
//This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in,
// just make sure you also update the QueryStatus/Exec method to include the new command names.
try
{
//Add a command to the Commands collection:
Command command = commands.AddNamedCommand2(_addInInstance, "ModuleAddin", "Add a Project", "Executes the command for ModuleAddin", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
//Add a control for the command to the tools menu:
if (command != null)
{
//command.AddControl(toolsPopup.CommandBar, 1);
command.AddControl(vsBarFolder);
//CommandBarButton button = (CommandBarButton)command.AddControl(vsBarFolder, 3);
//button.BeginGroup = true;
}
}
catch (System.ArgumentException argEx)
{
System.Diagnostics.Debug.Write("Exception in HintPaths:" + argEx.ToString());
}
}
}