public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; helper = new DTEHelper(_applicationObject, _addInInstance); if (connectMode == ext_ConnectMode.ext_cm_UISetup) { // Get main menu bar CommandBar menuBarCommandBar = ((CommandBars)_applicationObject.CommandBars)["MenuBar"]; #region Add CommandViewer command // TODO: So many hard coded strings... // Get Tools menu string toolsMenuName = helper.GetCulturedMenuName("Tools"); CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName]; CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl; // Add a new command helper.AddNamedCommand2(toolsPopup.CommandBar, COMMAND_VIEWER_COMMAND_NAME, "CommandViewer", "View All Commands", true, 59, toolsPopup.Controls.Count + 1); #endregion #region Add CloseAllDocuments command // Get "Easy MDI Document Window" command bar CommandBar mdiDocCommandBar = helper.GetCommandBarByName("Easy MDI Document Window"); // Place the command below "Close All But This" menu item CommandBarControl closeAllButThisCmd = mdiDocCommandBar.Controls["Close All But This"]; int closeAllCmdIndex = (closeAllButThisCmd == null) ? 1 : (closeAllButThisCmd.Index + 1); // Add a new command helper.AddNamedCommand2(mdiDocCommandBar, CLOSE_ALL_DOCUMENTS_COMMAND_NAME, "Close All Documents", "Close All Documents", false, 0, closeAllCmdIndex); #endregion #region Add NPetshopSlnGenerator command helper.AddNamedCommand2(toolsPopup.CommandBar, NPETSHOP_SLN_GENERATOR_COMMAND_NAME, "Generate NPetshop Sln", "Generate NPetshop Solution", true, 59, toolsPopup.Controls.Count + 1); #endregion #region Add ShortcutList command // Get View menu string viewMenuName = helper.GetCulturedMenuName("View"); CommandBarControl viewControl = menuBarCommandBar.Controls[viewMenuName]; CommandBarPopup viewPopup = (CommandBarPopup)viewControl; helper.AddNamedCommand2(viewPopup.CommandBar, SHOW_SHORTCUT_LIST_COMMAND_NAME, "Show shortcut list window", "Show shortcut list window", false, 0, viewPopup.Controls.Count + 1); #endregion #region Add CollapseAllProjects command // Get "Solution Explorer" command bar CommandBar slnCommandBar = helper.GetCommandBarByName("Solution"); // Add a new command helper.AddNamedCommand2(slnCommandBar, COLLAPSE_ALL_PROJECTS_COMMAND_NAME, "Collapse All Projects", "Collapse All Projects", false, 0, slnCommandBar.Controls.Count + 1); #endregion #region Add PropertyManager commands // Get "Code Window" command bar CommandBar codeWinCommandBar = helper.GetCommandBarByName("Code Window"); int pmPopupIndex = codeWinCommandBar.Controls.Count + 1; CommandBarPopup pmPopup = codeWinCommandBar.Controls.Add( MsoControlType.msoControlPopup, Type.Missing, Type.Missing, pmPopupIndex, true) as CommandBarPopup; pmPopup.Caption = "PropertyManager"; CommandBarButton batchPropertyCmd = helper.AddButtonToPopup(pmPopup, pmPopup.Controls.Count + 1, "Batch Property", "Encapsulate these fields"); batchPropertyCmdEvent = _applicationObject.Events.get_CommandBarEvents(batchPropertyCmd) as CommandBarEvents; batchPropertyCmdEvent.Click += new _dispCommandBarControlEvents_ClickEventHandler(BatchPropertyCmdEvent_Click); CommandBarButton convertToAutoPropCmd = helper.AddButtonToPopup(pmPopup, pmPopup.Controls.Count + 1, "Convert to Auto-Property", "Convert to Auto-Property(C# 3.0 style)"); convertToAutoPropCmdEvent = _applicationObject.Events.get_CommandBarEvents(convertToAutoPropCmd) as CommandBarEvents; convertToAutoPropCmdEvent.Click += new _dispCommandBarControlEvents_ClickEventHandler(ConvertToAutoPropCmdEvent_Click); CommandBarButton convertToNormalPropCmd = helper.AddButtonToPopup(pmPopup, pmPopup.Controls.Count + 1, "Convert to Normal-Property", "Convert to Normal-Property(C# 2.0 style)"); convertToNormalPropCmdEvent = _applicationObject.Events.get_CommandBarEvents(convertToNormalPropCmd) as CommandBarEvents; convertToNormalPropCmdEvent.Click += new _dispCommandBarControlEvents_ClickEventHandler(ConvertToNormalPropCmdEvent_Click); #endregion #region Add CodeTemplate commands // Add popup menu item int templatePopupIndex = codeWinCommandBar.Controls.Count + 1; CommandBarPopup codeTemplatePopup = codeWinCommandBar.Controls.Add( MsoControlType.msoControlPopup, Type.Missing, Type.Missing, templatePopupIndex, true) as CommandBarPopup; codeTemplatePopup.Caption = "Code Template"; List <string> templateNames = CodeTemplateManager.Instance.GetTemplateNames(); codeTemplateCmdEvents = new CommandBarEvents[templateNames.Count]; for (int i = 0; i < templateNames.Count; i++) { string name = templateNames[i]; CommandBarButton codeTemplateCmd = helper.AddButtonToPopup(codeTemplatePopup, codeTemplatePopup.Controls.Count + 1, name, "Insert this code template"); codeTemplateCmdEvents[i] = _applicationObject.Events.get_CommandBarEvents(codeTemplateCmd) as CommandBarEvents; codeTemplateCmdEvents[i].Click += new _dispCommandBarControlEvents_ClickEventHandler(codeTemplateCmdEvent_Click); } #endregion #region Add Code Model commands //CommandBarButton codeModelCmd = helper.AddButtonToCmdBar(codeWinCommandBar, codeWinCommandBar.Controls.Count + 1, // "Code Model", "Code Model Sample"); //codeModelCmdEvent = _applicationObject.Events.get_CommandBarEvents(codeModelCmd) as CommandBarEvents; //codeModelCmdEvent.Click += new _dispCommandBarControlEvents_ClickEventHandler(CodeModelCmdEvent_Click); #endregion #region Search This commands int searchThisPopupIndex = codeWinCommandBar.Controls.Count + 1; CommandBarPopup searchThisPopup = codeWinCommandBar.Controls.Add( MsoControlType.msoControlPopup, Type.Missing, Type.Missing, searchThisPopupIndex, true) as CommandBarPopup; searchThisPopup.Caption = "Search This In"; List <SearchEngine> engines = SearchEngineConfigManager.Instance.GetSearchEngines(); searchTextCmdEvents = new CommandBarEvents[engines.Count]; for (int i = 0; i < engines.Count; i++) { SearchEngine e = engines[i]; CommandBarButton searchCmd = helper.AddButtonToPopup(searchThisPopup, searchThisPopup.Controls.Count + 1, e.Name, "Search in " + e.Name); if (i == 0) { searchCmd.FaceId = 141; } searchTextCmdEvents[i] = _applicationObject.Events.get_CommandBarEvents(searchCmd) as CommandBarEvents; searchTextCmdEvents[i].Click += new _dispCommandBarControlEvents_ClickEventHandler(SearchTextCmdEvent_Click); } #endregion } else if (connectMode == ext_ConnectMode.ext_cm_AfterStartup) { object programmingObj = null; string guidString = "{41F8DEA8-EB07-45b7-9B1D-EB969DC43EC5}"; Windows2 windows2 = _applicationObject.Windows as Windows2; Assembly asm = Assembly.GetExecutingAssembly(); shortcutListWindow = windows2.CreateToolWindow2(_addInInstance, asm.Location, "NEnhancer.ShortcutListControl", "Visual Studio Shortcut List", guidString, ref programmingObj); shortcutListCtrl = shortcutListWindow.Object as ShortcutListControl; shortcutListCtrl.DTEObject = _applicationObject; } }
/// <summary>Implements the OnStartupComplete method of the IDTExtensibility2 interface. Receives notification that the host application has completed loading.</summary> /// <param term='custom'>Array of parameters that are host application specific.</param> /// <seealso class='IDTExtensibility2' /> public void OnStartupComplete(ref Array custom) { object[] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)_applicationObject.Commands; Microsoft.VisualStudio.CommandBars.CommandBars _commandBars = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars); // add a top-level menu to stick some global options in { Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"]; int nenhancerPopupIndex = menuBarCommandBar.Controls.Count + 1; CommandBarPopup clangMenuRoot = menuBarCommandBar.Controls.Add( MsoControlType.msoControlPopup, Type.Missing, Type.Missing, nenhancerPopupIndex, true) as CommandBarPopup; clangMenuRoot.Caption = "Clang"; // open the settings dialog { _dteHelper.AddNamedCommand2( COMMAND_CLANG_SETTINGS_DLG, "Settings...", "Settings...", false, 0); Command commandToAdd = _applicationObject.Commands.Item(GetCommandFullName(COMMAND_CLANG_SETTINGS_DLG), 0); SettingsButton = commandToAdd.AddControl(clangMenuRoot.CommandBar, clangMenuRoot.CommandBar.Controls.Count + 1) as CommandBarButton; } // get active vcproj, rebuild it with Clang { _dteHelper.AddNamedCommand2( COMMAND_CLANG_REBUILD_ACTIVE, "Rebuild Active Project", "Rebuild Active Project", false, 0); Command commandToAdd = _applicationObject.Commands.Item(GetCommandFullName(COMMAND_CLANG_REBUILD_ACTIVE), 0); RebuildActiveProjectButton = commandToAdd.AddControl(clangMenuRoot.CommandBar, clangMenuRoot.CommandBar.Controls.Count + 1) as CommandBarButton; } { _dteHelper.AddNamedCommand2( COMMAND_CLANG_RELINK_ACTIVE, "Relink", "Relink", false, 0); Command commandToAdd = _applicationObject.Commands.Item(GetCommandFullName(COMMAND_CLANG_RELINK_ACTIVE), 0); RebuildActiveProjectButton = commandToAdd.AddControl(clangMenuRoot.CommandBar, clangMenuRoot.CommandBar.Controls.Count + 1) as CommandBarButton; } } // add a compile-this-file option to the editor window { Microsoft.VisualStudio.CommandBars.CommandBar codeWinCommandBar = _dteHelper.GetCommandBarByName("Code Window"); int pmPopupIndex = codeWinCommandBar.Controls.Count + 1; CommandBarPopup pmPopup = codeWinCommandBar.Controls.Add( MsoControlType.msoControlPopup, Type.Missing, Type.Missing, pmPopupIndex, true) as CommandBarPopup; pmPopup.Caption = "Clang Compiler"; CommandBarButton saveAndCompileCmd = _dteHelper.AddButtonToPopup( pmPopup, pmPopup.Controls.Count + 1, "Compile", "Compile"); CompileCmdEvent = _applicationObject.Events.get_CommandBarEvents(saveAndCompileCmd) as CommandBarEvents; CompileCmdEvent.Click += new _dispCommandBarControlEvents_ClickEventHandler(cvxCompileFile_menuop); CommandBarButton saveAndAnalyseCmd = _dteHelper.AddButtonToPopup( pmPopup, pmPopup.Controls.Count + 1, "Run Static Analysis", "Run Static Analysis"); AnalyseCmdEvent = _applicationObject.Events.get_CommandBarEvents(saveAndAnalyseCmd) as CommandBarEvents; AnalyseCmdEvent.Click += new _dispCommandBarControlEvents_ClickEventHandler(cvxAnalyseFile_menuop); CommandBarButton saveAndDasmCmd = _dteHelper.AddButtonToPopup( pmPopup, pmPopup.Controls.Count + 1, "View Disassembly (LLVM)", "View Disassembly (LLVM)"); DasmCmdEvent = _applicationObject.Events.get_CommandBarEvents(saveAndDasmCmd) as CommandBarEvents; DasmCmdEvent.Click += new _dispCommandBarControlEvents_ClickEventHandler(cvxDasmnFile_menuop); CommandBarButton dasmAndPreproCmd = _dteHelper.AddButtonToPopup( pmPopup, pmPopup.Controls.Count + 1, "View Preprocessor Result", "View Preprocessor Result"); PreproCmdEvent = _applicationObject.Events.get_CommandBarEvents(dasmAndPreproCmd) as CommandBarEvents; PreproCmdEvent.Click += new _dispCommandBarControlEvents_ClickEventHandler(cvxPreProFile_menuop); } }