我知道这里已经有一些线索,但我不会为我工作。VS2010加载项,添加命令到上下文菜单?
我想要的: 我需要在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);
}
命令栏“父”让我颇有些例外,如果我仔细看看吧:
accChildCount =“parent.accChildCount”抛出'Microsoft.VisualStudio.PlatformUI.Automation.DeprecatedException'类型的例外情况对于每个其他“acc”值都是相同的。
现在我真的不知道我做错了什么,或者我可以尝试做什么。我想要做的就是在源代码控制浏览器中有一个上下文菜单条目,它应该调用电动工具命令行EXE来调用它的“撤消不变”功能。
我不会担心DeprecatedExceptions太多;那些可能就在那里,因为MS不希望你使用过时的界面版本。自从它首次发布以来,它们可能会稍微改变界面,并且出于兼容性原因无法删除这些属性。 – takrl 2011-07-06 16:01:39
你的QueryStatus方法在做什么?该方法确定命令是隐藏还是可见,并且我注意到您指向的文章没有给出实现它的示例。 – 2011-11-14 20:55:37
我有几乎相同的代码,除了我在“IDTExtensibility2.OnStartupComplete”方法中添加自定义命令。 与 “IDTExtensibility2.OnConnection” 方法中,我使用的 “ext_ConnectMode.ext_cm_AfterStartup” 而不是 “ext_ConnectMode.ext_cm_UISetup”: 如果(connectMode == ext_ConnectMode.ext_cm_AfterStartup) this.OnStartupComplete(参照定制); – 2011-11-29 21:42:54