Visual studio 2010 Visual Studio扩展菜单按钮事件未激发
我有一个项目,最近已从studio 2008转换为2010。它充分利用了DSL。我使用了SDK附带的DslProjectsMigrationTool。虽然大部分功能都在工作,但我在菜单方面有一些问题。我有一个自定义工具栏,其中有三个按钮,可以编辑我的代码。但是,事件处理程序似乎不起作用。我有一个回来,并检查了2008年的版本,这是工作没有问题 不幸的是,这些代码都不是我自己的,最初编写它们的人已经离开了,无法提供帮助 在Commands.vsct中,我有Visual studio 2010 Visual Studio扩展菜单按钮事件未激发,visual-studio-2010,visual-studio,event-handling,vsix,Visual Studio 2010,Visual Studio,Event Handling,Vsix,我有一个项目,最近已从studio 2008转换为2010。它充分利用了DSL。我使用了SDK附带的DslProjectsMigrationTool。虽然大部分功能都在工作,但我在菜单方面有一些问题。我有一个自定义工具栏,其中有三个按钮,可以编辑我的代码。但是,事件处理程序似乎不起作用。我有一个回来,并检查了2008年的版本,这是工作没有问题 不幸的是,这些代码都不是我自己的,最初编写它们的人已经离开了,无法提供帮助 在Commands.vsct中,我有 <CommandTable xml
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<Commands package="guidPkg">
<Menus>
<Menu guid="guidCmdSet" id="blueprintToolbar" priority="0x0000" type="Toolbar">
<Parent guid="guidCmdSet" id="blueprintToolbar"/>
<CommandFlag>DefaultDocked</CommandFlag>
<CommandFlag>AlwaysCreate</CommandFlag>
<Strings>
<ButtonText>Blueprint Toolbar</ButtonText>
</Strings>
</Menu>
</Menus>
<Groups>
<Group guid="guidCmdSet" id="grpidTranslate" priority="0x0000">
<Parent guid="guidCmdSet" id="blueprintToolbar" />
</Group>
</Groups>
<Buttons>
<Button guid="guidCmdSet" id="cmdidReTranslateAllCmd" priority="0x0100" type="Button">
<Parent guid="guidCmdSet" id="grpidTranslate" />
<Icon guid="guidCmdSet" id="bmpPic1"/>
<CommandFlag>TextOnly</CommandFlag>
<Strings>
<ButtonText><Retranslate All></ButtonText>
</Strings>
</Button>
<Button guid="guidCmdSet" id="cmdidTranslateAllCmd" priority="0x0101" type="Button">
<Parent guid="guidCmdSet" id="grpidTranslate" />
<Icon guid="guidCmdSet" id="bmpPic1"/>
<CommandFlag>TextOnly</CommandFlag>
<Strings>
<ButtonText><Translate All></ButtonText>
</Strings>
</Button>
<Button guid="guidCmdSet" id="cmdidTranslateCurCmd" priority="0x0102" type="Button">
<Parent guid="guidCmdSet" id="grpidTranslate" />
<Icon guid="guidCmdSet" id="bmpPic1"/>
<CommandFlag>TextOnly</CommandFlag>
<Strings>
<ButtonText><Translate Current></ButtonText>
</Strings>
</Button>
</Buttons>
</Commands>
<Symbols>
<GuidSymbol name="guidCmdSet" value="Extern">
<!--Group IDs-->
<IDSymbol name="grpidTranslate" value="0x1050"/>
<!--Command IDs-->
<IDSymbol name="cmdidTranslateAllCmd" value="0x9100"/>
<IDSymbol name="cmdidTranslateCurCmd" value="0x9101"/>
<IDSymbol name="cmdidReTranslateAllCmd" value="0x9102"/>
<IDSymbol name="blueprintToolbar" value="0x1000"/>
<IDSymbol name="bmpPic1" value="1"/>
</GuidSymbol>
</Symbols>
</CommandTable>
默认停靠
总是创造
蓝图工具栏
纯文本
全部重发
纯文本
全部翻译
纯文本
转换电流
然后在CommandSetOverride.cs中
/// <summary>
/// Constants relating to commands
/// </summary>
partial class Constants
{
public const string CLSID_StandardCommandSet97 = "5efc7975-14bc-11cf-9b2b-00aa00573819";
#region Command Codes
const int cmdidTranslateAllCmd = 0x9100;
const int cmdidTranslateCurrentCmd = 0x9101;
const int cmdidReTranslateAllCmd = 0x9102;
#endregion
#region CommandIDs
public static readonly CommandID TranslateAllCommandID =
new CommandID(new Guid(Constants.BlueprintCommandSetId), cmdidTranslateAllCmd);
public static readonly CommandID TranslateCurrentCommandID =
new CommandID(new Guid(Constants.BlueprintCommandSetId), cmdidTranslateCurrentCmd);
public static readonly CommandID ReTranslateAllCommandID =
new CommandID(new Guid(Constants.BlueprintCommandSetId), cmdidReTranslateAllCmd);
#endregion
}
/// <summary>
/// Additions to the blueprint command set for context menu items and extra commands.
/// </summary>
partial class BlueprintCommandSet
{
/// <summary>
/// Retrieves the available menu commands
/// </summary>
/// <returns>List of menu commands</returns>
protected override IList<MenuCommand> GetMenuCommands()
{
IList<MenuCommand> commands = base.GetMenuCommands();
OleMenuCommand oleMenuCommand;
// Translate
if (null != MenuService)
{
MenuCommand menuCommand = new MenuCommand(new EventHandler(OnTranslateAll), Constants.TranslateAllCommandID);
MenuService.AddCommand(menuCommand);
menuCommand = new MenuCommand(new EventHandler(OnTranslateCurrent), Constants.TranslateCurrentCommandID);
MenuService.AddCommand(menuCommand);
menuCommand = new MenuCommand(new EventHandler(OnReTranslateAll), Constants.ReTranslateAllCommandID);
MenuService.AddCommand(menuCommand);
}
return commands;
}
#region Translation
/// <summary>
/// Handles the "ReTranslate All" toolbar button command.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnReTranslateAll(object sender, EventArgs e)
{
ReTranslateAll();
}
/// <summary>
/// Handles the "Translate All" toolbar button command.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnTranslateAll(object sender, EventArgs e)
{
TranslateAll(false);
}
/// <summary>
/// Handles the "Translate Current" toolbar button command.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnTranslateCurrent(object sender, EventArgs e)
{
TranslateCurrent();
}
#endregion
}
//
///与命令有关的常量
///
部分类常数
{
公共常量字符串CLSID_StandardCommandSet97=“5efc7975-14bc-11cf-9b2b-00aa00573819”;
#区域命令代码
const int cmdidTranslateAllCmd=0x9100;
const int cmdidTranslateCurrentCmd=0x9101;
const int cmdidReTranslateAllCmd=0x9102;
#端区
#区域命令ID
公共静态只读命令ID TranslateAllCommand=
新命令ID(新Guid(常量.BlueprintCommandSetId)、cmdidTranslateAllCmd);
公共静态只读命令ID TranslateCurrentCommandID=
新命令ID(新Guid(常量.BlueprintCommandSetId)、cmdidTranslateCurrentCmd);
公共静态只读命令ID重新传输AllCommandID=
新CommandID(新Guid(Constants.BlueprintCommandSetId),cmdidReTranslateAllCmd);
#端区
}
///
///为关联菜单项和额外命令添加到blueprint命令集。
///
部分类BlueprintCommandSet
{
///
///检索可用的菜单命令
///
///菜单命令列表
受保护的覆盖IList GetMenuCommand()
{
IList commands=base.getMenuCommand();
OleMenuCommand OleMenuCommand;
//翻译
if(null!=MenuService)
{
MenuCommand MenuCommand=new MenuCommand(new EventHandler(OnTranslateAll),Constants.translateAllCommand);
MenuService.AddCommand(menuCommand);
menuCommand=new menuCommand(neweventhandler(OnTranslateCurrent),Constants.TranslateCurrentCommandID);
MenuService.AddCommand(menuCommand);
menuCommand=new menuCommand(neweventhandler(OnReTranslateAll),Constants.ReTranslateAllCommandID);
MenuService.AddCommand(menuCommand);
}
返回命令;
}
#区域平移
///
///处理“全部重传”工具栏按钮命令。
///
///
///
private void OnReTranslateAll(对象发送方,事件参数e)
{
重传全部();
}
///
///处理“全部平移”工具栏按钮命令。
///
///
///
私有void OnTranslateAll(对象发送方,事件参数e)
{
翻译(假);
}
///
///处理“转换当前”工具栏按钮命令。
///
///
///
私有无效OnTranslateCurrent(对象发送方,事件参数e)
{
TranslateCurrent();
}
#端区
}
当我运行已安装版本的代码或在配置单元中运行代码时,按钮会出现在工具栏中,没有问题,但是单击它们时,决不会调用OntranslateAll或类似命令。任何帮助都会非常有用。我发现CommandSetId Guid在两个地方被显式使用,然后一个版本被更新为2010版本,而第二个版本则没有。使用不同的Guid时,事件被发送到了错误的位置我发现CommandSetId Guid在两个位置被显式使用,然后一个版本被更新为2010版本,而第二个版本没有。使用不同的GUID,事件被发送到错误的位置