2012-03-21 42 views
1

中添加兩個命令按鈕下面的代碼應該顯示一個自定義上下文菜單項,當用戶右鍵單擊「項目」和不同的自定義上下文菜單項時, Visual Studio 2010解決方案資源管理器中的「文件夾」。將兩個命令按鈕添加到解決方案資源管理器上下文菜單 - Visual Studion在

第一部分工作得很好 - 你好新菜單項yey! - 用戶右擊文件夾時的第二部分 - 不是 - 它總是顯示標準的舊上下文菜單,而不顯示新的菜單項。

任何想法,我要去哪裏錯了?可以創建兩個Command對象,對嗎?

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) 
     { 
      object []contextGUIDS = new object[] { }; 
      Commands2 commands = (Commands2)_applicationObject.Commands; 
      CommandBars cBars = (CommandBars)_applicationObject.CommandBars; 
      try 
      { 
       Command commandProjectSettings = commands.AddNamedCommand2(_addInInstance, "DavecProjectSchemaSettings", "Davec Project Settings", "Manages Database Project Settings", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); 
       Command commandAddSchemaUpdate = commands.AddNamedCommand2(_addInInstance, "DavecProjectUpdate", "Davec Update", "Updates Database Schema", false, 2, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); 

       CommandBar vsBarProject = cBars["Project"]; 
       CommandBar vsBarFolder = cBars["Folder"]; 

       commandProjectSettings.AddControl(vsBarProject, 1); 
       commandAddSchemaUpdate.AddControl(vsBarFolder, 1); 

      } 
      catch(System.ArgumentException) 
      { 
       //ignore 
      } 

      _solutionEvents = _applicationObject.Events.SolutionEvents; 
      _solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened); 

      _documentEvents = _applicationObject.Events.DocumentEvents; 
      _documentEvents.DocumentSaved += new _dispDocumentEvents_DocumentSavedEventHandler(_documentEvents_DocumentSaved); 
     } 
    } 

回答

2

我需要在QueryStatus方法中,當命令的可用性更新該被調用以包括新的命令即

public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText) 
    { 
     if(neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone) 
     { 
      if (commandName == "Sappha.Davec.VSAddIn.Connect.DavecProjectSchemaSettings") 
      { 
       status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled; 
       return; 
      } 

      if (commandName == "Sappha.Davec.VSAddIn.Connect.DavecProjectUpdate") 
      { 
       status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; 
       return; 
      } 
     } 
    } 
相關問題