【发布时间】:2011-12-15 23:11:47
【问题描述】:
我知道已经有一些关于此的主题,但我不会为我工作。
我想要的: 我需要在 Visual Studio 源代码管理资源管理器的上下文菜单中添加一个新条目。为此,我启动了一个新的插件项目。
我用过的: 我用这篇文章作为指导。 http://blogs.msdn.com/b/team_foundation/archive/2010/06/24/extending-work-item-tracking-context-menus.aspx
什么不工作: 我没有遇到任何异常,无论我在哪里添加菜单,它都不会出现。
一些代码sn-ps:
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 不希望您使用过时版本的界面。自首次发布以来,他们可能对界面进行了相当大的更改,并且出于兼容性原因无法删除属性。
-
您的 QueryStatus 方法在做什么?该方法确定命令是隐藏还是可见,我注意到您指向的文章没有给出实现它的示例。
-
我有几乎相同的代码,除了我在“IDTExtensibility2.OnStartupComplete”方法中添加我的自定义命令。在“IDTExtensibility2.OnConnection”方法中,我使用的是“ext_ConnectMode.ext_cm_AfterStartup”而不是“ext_ConnectMode.ext_cm_UISetup”: if( connectMode == ext_ConnectMode.ext_cm_AfterStartup ) this.OnStartupComplete( ref custom );
标签: c# add-in contextmenu