2013-03-28 125 views
0

我有一個項目最近已經從studio 2008轉換爲2010.它對DSL有很大的用處。我使用了SDK附帶的DslProjectsMigrationTool。雖然大部分功能正在運行,但我在菜單上遇到了一些問題。我有一個自定義工具欄,其中有三個按鈕,我的代碼。但是,事件處理程序似乎沒有工作。我有一個回來,檢查了2008年的版本,這是沒有任何問題的工作。Visual Studio擴展菜單按鈕事件不會觸發

不幸的是,這些代碼都不是我自己的,最初編寫它的人已經轉向並且無法提供幫助。

在Commands.vsct我有

<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>&lt;Retranslate All&gt;</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>&lt;Translate All&gt;</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>&lt;Translate Current&gt;</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 
} 

當我在按鈕出現在蜂巢中運行時運行該代碼或者安裝的版本或工具欄沒有問題,但點擊它們從不調用OntranslateAll或類似的。任何幫助將非常有用。

+0

我發現CommandSetId Guid在兩個地方顯式使用,然後一個版本更新爲2010版,而第二個版本沒有更新。通過不同的指導,事件被髮送到了錯誤的地方 – user2207853 2013-03-28 14:24:06

回答

0

我發現CommandSetId Guid在兩個地方顯式使用,然後一個版本更新爲2010版,而第二個版本不是。使用不同的GUID,事件被髮送到了錯誤的地方