2012-07-27 1 views
1

Visual Studio 용 AddIn을 개발하여 javascript 파일 및 이미지 파일의 마우스 오른쪽 단추를 상황에 맞는 메뉴로 가져 오려고합니다. 나는 모든 프로젝트 아이템의 오른쪽 클릭에 Addin을 추가 할 수 있었다.Visual Studio에서 특정 파일 형식의 마우스 오른쪽 단추로 상황에 맞는 메뉴를 얻는 방법

내가 달성하고 싶은 것은 Addin을 얻는 것이다. 오직을 자바 스크립트 파일과 이미지 파일에만 적용한다. 이런 식으로 뭔가를 (참고 : - 현재 내가 모든 파일 형식 에 추가 기능을 얻고있다) 아래

내가 연결

if (connectMode == ext_ConnectMode.ext_cm_UISetup) 
     { 
      object[] contextGUIDS = new object[] { }; 
      Commands2 commands = (Commands2)_applicationObject.Commands; 
      string toolsMenuName = "Tools"; 

      //Place the command on the tools menu. 
      //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items: 
      Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"]; 

      //Find the Tools command bar on the MenuBar command bar: 
      CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName]; 
      CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl; 

      Microsoft.VisualStudio.CommandBars.CommandBar itemToolBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["Item"]; 

      //This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in, 
      // just make sure you also update the QueryStatus/Exec method to include the new command names. 
      try 
      { 
       //Add a command to the Commands collection: 
       Command command = commands.AddNamedCommand2(_addInInstance, "CrmAddin", "CrmAddin", "Executes the command for CrmAddin", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); 

       //Add a control for the command to the tools menu: 
       if ((command != null) && (toolsPopup != null)) 
       { 
        command.AddControl(toolsPopup.CommandBar, 1); 
       } 

       if ((command != null) && (itemToolBar != null)) 
       { 
        command.AddControl(itemToolBar, 1); 
       } 
      } 
      catch (System.ArgumentException) 
      { 
       //If we are here, then the exception is probably because a command with that name 
       // already exists. If so there is no need to recreate the command and we can 
       // safely ignore the exception. 
      } 

에있는 코드를 내가 QueryStatus에서 파일 형식을 필터링하는 시도이다 이 방법은 도움이되지 않습니다.

if (neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone) 
     { 
      if (commandName == "CrmAddin.Connect.CrmAddin") 
      { 
       bool supportedFileTypes = true; 
       foreach (Project project in _applicationObject.Solution.Projects) 
       { 
        foreach (ProjectItem projectItem in project.ProjectItems) 
        { 
         if (!projectItem.Name.EndsWith(".js")) 
         { 
          supportedFileTypes = false; 
         } 
        } 
       } 
       if (supportedFileTypes) 
       { 
        status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; 
       } 
       else 
       { 
        status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported; 
       } 

       return; 
      } 
     } 

누군가가 올바른 방향으로 나를 가리킬 수 있으면 도와주세요.

답변

관련 문제