2012-07-27 63 views
1

我正在尝试为Visual Studio开发一个AddIn以获取JavaScript文件和图像文件的右键单击上下文菜单。我已经设法添加我的地址到所有项目的右键点击如何在Visual Studio中的某些文件类型上获得右键单击上下文菜单

我想实现的是在JavaScript文件和图像文件上获取Addin ONLY。像这样的东西(注: - 目前我正在越来越外接ALL文件类型)

下面是我在连接

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; 
      } 
     } 

请帮助,如果任何人都可以指出我的方向是正确的。

回答

相关问题