我知道已经有一些线索,但我不会为我工作。
我想要的: 我需要Visual Studio源代码管理资源管理器的上下文菜单中的新条目。为此,我开始了一个新的插件项目。
我用过的东西: 我用这篇文章作为指导。 http://blogs.msdn.com/b/team_foundation/archive/2010/06/24/extending-work-item-tracking-context-menus.aspx
什么不起作用: 我没有任何例外,无论我在哪里添加它,菜单都不会出现。
一些代码段:
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)
{
AddCommandToContextMenu(
"Team Project", // context menu Name
"ClearQuery", // menu reference name
"Clear", // display name
47, // command icon
1); // command placement, 1= first item on top
}
}
我使用“团队项目”菜单名称进行测试。 VSIPLogging告诉我,如果我右键单击我们的TFS团队项目,这就是菜单的名称。我也试过其他菜单但没有成功。
以下是AddCommandToContextMenu函数:
private void AddCommandToContextMenu(string menuName, string commandName, string commandText, int iconId, int position)
{
CommandBar contextMenu = ((CommandBars)_applicationObject.CommandBars)[menuName];
AddCommand(contextMenu, commandName, commandText, iconId, position);
}
private void AddCommand(CommandBar parent, string commandName, string commandText, int iconId, int position)
{
Commands2 commands = (Commands2)_applicationObject.Commands;
//create the command
Command newCommand = commands.AddNamedCommand2(_addInInstance, commandName, commandText, commandText, true, iconId);
// add it to parent menu
newCommand.AddControl(parent, position);
}
命令栏“parent”给了我一些例外,如果我仔细看看它:
accChildCount ='parent.accChildCount'引发类型'Microsoft.VisualStudio.PlatformUI.Automation.DeprecatedException'的异常
每个其他“acc”值都相同。
现在我真的不知道我做错了什么或者我还能尝试做些什么。我想要做的就是在源代码管理资源管理器中有一个上下文菜单条目,它应该调用电动工具命令行exe来调用它的“撤消未更改”功能。
答案 0 :(得分:3)
我很确定Visual Studio中的Popups是CommnadBarPopup类型。 我非常确定的另一件事是你需要使你的命令/控件全局,所以引用它们,否则GC会杀死它们。
您需要确保AddCommand中的命令名称不包含点,并且在Query / Exec函数中确实如此:例如:
newCommand = commands.AddNamedCommand2(_addInInstance, commandName, commandText, commandText, true, iconId, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,(int)vsCommandStyle.vsCommandStylePictAndText,vsCommandControlType.vsCommandControlTypeButton);
这里有几点需要注意:
这只是一个起点,plaese参考这篇文章: HOWTO: Create a context menu using a Visual Studio commandbar popup from an add-in
祝你好运!