public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom) { try { m_dte = (EnvDTE.DTE)application; m_addIn = (EnvDTE.AddIn)addInInst; switch (connectMode) { case ext_ConnectMode.ext_cm_UISetup: // Create commands in the UI Setup phase. This phase is called only once when the add-in is deployed. CreateCommands(); break; case ext_ConnectMode.ext_cm_AfterStartup: InitializeAddIn(); break; case ext_ConnectMode.ext_cm_Startup: // Do nothing yet, wait until the IDE is fully initialized (OnStartupComplete will be called) break; } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public WindowManager(DTE2 applicationObject, EnvDTE.AddIn addInInstance) { this.addInInstance = addInInstance; this.applicationObject = applicationObject; this.events = this.applicationObject.DTE.Events.get_WindowEvents(null); this.events.WindowActivated += new _dispWindowEvents_WindowActivatedEventHandler(WindowManager_WindowActivated); }
/// <summary> /// Called when the AddIn is loaded. This method allows each of the commands to /// store member variables with the objects passed in and ensure that the menu /// items and commands have been properly added to the object model. /// </summary> /// <param name="application"> Root object in the application </param> /// <param name="connectMode"> 'Mode' in which the environment is starting up the addin </param> /// <param name="addIn"> Object representing this AddIn in the Object Model</param> public void OnConnection(EnvDTE._DTE application, Extensibility.ext_ConnectMode connectMode, EnvDTE.AddIn addIn) { try { m_applicationObject = (EnvDTE._DTE)application; m_addInInstance = (EnvDTE.AddIn)addIn; m_strCommandName = "AMDeleteCourse"; m_strName = AMResources.GetLocalizedString("AMDeleteCourseName"); m_strItemText = AMResources.GetLocalizedString("AMDeleteCourseItemText"); string description = AMResources.GetLocalizedString("AMDeleteCourseDescription"); EnvDTE.Commands commands = null; EnvDTE.Command command = null; _CommandBars officeCommandBars = null; CommandBar officeCommandBar = null; CommandBarControl officeCommandControl = null; CommandBar officeAcademic = null; object [] contextGuids; contextGuids = new object[] { }; commands = m_applicationObject.Commands; try { command = commands.AddNamedCommand(m_addInInstance, m_strCommandName, m_strName, description, false, 108, ref contextGuids, (int)(EnvDTE.vsCommandStatus.vsCommandStatusEnabled | EnvDTE.vsCommandStatus.vsCommandStatusSupported)); // Add the new command to the tools menu officeCommandBars = m_applicationObject.CommandBars; string amFacultyMenuItem = AMResources.GetLocalizedString("AMFacultyMenuItem"); try { officeAcademic = (CommandBar)officeCommandBars[amFacultyMenuItem]; } catch { } if (officeAcademic == null) { officeCommandBar = (CommandBar)officeCommandBars["Tools"]; officeAcademic = (CommandBar)m_applicationObject.Commands.AddCommandBar(amFacultyMenuItem, EnvDTE.vsCommandBarType.vsCommandBarTypeMenu, officeCommandBar, 1); } officeCommandControl = command.AddControl((object)officeAcademic, 1); officeCommandControl.Caption = m_strItemText; } catch { // Falling into this simply means that the command was already registered. } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception e = " + e.Message); } }
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { addInInstance = (AddIn)addInInst; applicationObject = (DTE2)addInInstance.DTE; switch (connectMode) { case ext_ConnectMode.ext_cm_Startup: Commands2 commands = (Commands2)applicationObject.Commands; CommandBar menuBarCommandBar = ((CommandBars)applicationObject.CommandBars)["MenuBar"]; CommandBar standardCommandBar = ((CommandBars)applicationObject.CommandBars)["Standard"]; this.openViewerButton = AddCommandBarButton(commands, standardCommandBar, "OpenInternalsViewer", "Open Internals Viewer", Properties.Resources.allocationMapIcon, Properties.Resources.allocationMapIconMask); CommandBarPopup commandBarPopup = (CommandBarPopup)menuBarCommandBar.Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, 8, Properties.Resources.AppWindow); commandBarPopup.Caption = "Internals Viewer"; AddCommandBarPopup(commands, commandBarPopup, "AllocationMap", "Allocation Map", "Show the Allocation Map", Properties.Resources.allocationMapIcon, Properties.Resources.allocationMapIconMask); AddCommandBarPopup(commands, commandBarPopup, "TransactionLog", "Display Transaction Log", "Include the Transaction Log with query results", Properties.Resources.TransactionLogIcon, Properties.Resources.allocationMapIconMask); IObjectExplorerEventProvider provider = ServiceCache.GetObjectExplorer().GetService(typeof(IObjectExplorerEventProvider)) as IObjectExplorerEventProvider; provider.NodesRefreshed += new NodesChangedEventHandler(Provider_NodesRefreshed); provider.NodesAdded += new NodesChangedEventHandler(Provider_NodesRefreshed); provider.BufferedNodesAdded += new NodesChangedEventHandler(Provider_NodesRefreshed); this.windowManager = new WindowManager(applicationObject, addInInstance); this.queryEditorExtender = new QueryEditorExtender(applicationObject, this.windowManager); break; } }
/// <summary> /// Registers a command and places it on the Tools menu. /// </summary> public void OnConnection(EnvDTE._DTE application, Extensibility.ext_ConnectMode connectMode, EnvDTE.AddIn addIn) { m_applicationObject = (EnvDTE._DTE)application; m_addInInstance = (EnvDTE.AddIn)addIn; m_strCommandName = "AMRemoveCourse"; m_strName = AMResources.GetLocalizedString("AMRemoveCourseName"); m_strItemText = AMResources.GetLocalizedString("AMRemoveCourseItemText"); string strDescription = AMResources.GetLocalizedString("AMRemoveCourseDescription"); EnvDTE.Commands commands = null; EnvDTE.Command command = null; Microsoft.Office.Core._CommandBars officeCommandBars = null; Microsoft.Office.Core.CommandBar officeCommandBar = null; Microsoft.Office.Core.CommandBarControl officeCommandControl = null; Microsoft.Office.Core.CommandBar officeAcademic = null; object [] contextGuids; contextGuids = new object[] { }; commands = m_applicationObject.Commands; try { command = commands.AddNamedCommand(m_addInInstance, m_strCommandName, m_strName, strDescription, false, 108, ref contextGuids, (int)(EnvDTE.vsCommandStatus.vsCommandStatusEnabled | EnvDTE.vsCommandStatus.vsCommandStatusSupported)); // Add the new command to the tools menu officeCommandBars = m_applicationObject.CommandBars; string amStudentMenuItem = AMResources.GetLocalizedString("AMStudentMenuItem"); try { officeAcademic = (CommandBar)officeCommandBars[amStudentMenuItem]; } catch { } if (officeAcademic == null) { officeCommandBar = (CommandBar)officeCommandBars["Tools"]; officeAcademic = (CommandBar)m_applicationObject.Commands.AddCommandBar(amStudentMenuItem, EnvDTE.vsCommandBarType.vsCommandBarTypeMenu, officeCommandBar, 1); } officeCommandControl = command.AddControl((object)officeAcademic, 1); officeCommandControl.Caption = m_strItemText; } catch (System.Exception /*e*/) { // Falling into this simply means that the command was already registered. } }
/// <summary> /// Run initialization code on first connection of the AddIn. /// </summary> /// <param name="appObj"> Application Object. </param> /// <param name="addin"> Add In Object. </param> public void Connect(DTE2 appObj, EnvDTE.AddIn addin) { /// Initialize External and Internal Variables. _applicationObject = appObj; _addInInstance = addin; /// Register Command Events _commandEvents = new VSNDKCommandEvents(appObj); _commandEvents.RegisterCommand(GuidList.guidVSStd2KString, CommandConstants.cmdidSolutionPlatform, cmdNewPlatform_afterExec, cmdNewPlatform_beforeExec); _commandEvents.RegisterCommand(GuidList.guidVSStd2KString, CommandConstants.cmdidSolutionCfg, cmdNewPlatform_afterExec, cmdNewPlatform_beforeExec); _commandEvents.RegisterCommand(GuidList.guidVSDebugGroup, CommandConstants.cmdidDebugBreakatFunction, cmdNewFunctionBreakpoint_afterExec, cmdNewFunctionBreakpoint_beforeExec); DisableIntelliSenseErrorReport(true); CheckSolutionPlatformCommand(); }
public static EnvDTE.Command ReplaceCommandInMenu( EnvDTE.AddIn addInInstance, EnvDTE._DTE applicationObject, int iconNumber, string progID, string commandName, string commandButtonText, string commandDescription, string commandBarName ) { object [] contextGUIDS = new object[] { }; Commands commands = applicationObject.Commands; _CommandBars commandBars = applicationObject.CommandBars; try { Command command = FindCommand(commands, progID + "." + commandName); if (command != null) // if we found one { command.Delete(); // delete it as we're going to replace it } // call commands.AddNamedCommand to add it command = commands.AddNamedCommand( addInInstance, commandName, commandButtonText, commandDescription, true, iconNumber, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled); CommandBar commandBar = (CommandBar)commandBars[commandBarName]; CommandBarControl commandBarControl = command.AddControl(commandBar, 1); return(command); } catch (System.Exception e) { MessageBox.Show("Exception in ReplaceCommandInMenu: " + e.Message); return(null); } }
/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary> /// <param term='application'>Root object of the host application.</param> /// <param term='connectMode'>Describes how the Add-in is being loaded.</param> /// <param term='addInInst'>Object representing this Add-in.</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _application = (DTE2)application; _addIn = (EnvDTE.AddIn)addInInst; // Events _events = (Events2)_application.Events; _projectsEvents = _events.ProjectsEvents; _projectItemsEvents = _events.ProjectItemsEvents; _documentEvents = _events.DocumentEvents; _buildEvents = _events.BuildEvents; AttachEvents(); _core = new Core(); // If being connected when Solution is already loaded - try to load all projects if (_application.Solution != null) { _core.Load(_application.Solution); } }
public DTE_Addin FindAddinByGuid(string InGuid) { EnvDTE.AddIns addins = dte2.AddIns; EnvDTE.AddIn foundAddin = null; foreach (AddIn addin in dte2.AddIns) { if (addin.Guid == InGuid) { foundAddin = addin; break; } } if (foundAddin == null) { return(null); } else { return(new DTE_Addin(this, foundAddin)); } }
public DTE_Addin FindAddin(string InProgId) { EnvDTE.AddIns addins = dte2.AddIns; EnvDTE.AddIn foundAddin = null; try { foundAddin = addins.Item(InProgId); } catch (Exception) { foundAddin = null; } if (foundAddin == null) { return(null); } else { return(new DTE_Addin(this, foundAddin)); } }
/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary> /// <param term='application'>Root object of the host application.</param> /// <param term='connectMode'>Describes how the Add-in is being loaded.</param> /// <param term='addInInst'>Object representing this Add-in.</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { m_dte = (EnvDTE.DTE)application; m_addIn = (EnvDTE.AddIn)addInInst; CommandBars commandBars; if (connectMode == ext_ConnectMode.ext_cm_UISetup) { object[] contextGUIDS = new object[] { }; //Commands2 commands = (Commands2)_applicationObject.Commands; try { //Command commandProjectSettings = commands.AddNamedCommand2(_addInInstance, "ViewGraphSettings", "View Graph", "View Graph Settings", // false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, // (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); Command commandProjectSettings = m_dte.Commands.AddNamedCommand(m_addIn, "ViewGraphSettings", "View Graph", "View Graph Settings", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled); commandBars = (CommandBars)m_dte.CommandBars; CommandBar codeWindowCommandBar = commandBars["Code Window"]; var popup = codeWindowCommandBar.Controls.Add(MsoControlType.msoControlButton, System.Reflection.Missing.Value, System.Reflection.Missing.Value, 1, true); popup.Caption = "View graph"; //commandProjectSettings.AddControl(popup); var commandBarEvents = (CommandBarEvents)(m_dte.Events.CommandBarEvents[popup]); commandBarEvents.Click += ViewGraphClick; } catch (System.ArgumentException) { //ignore } } }
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom) { try { applicationObject = (DTE2)application; addInInstance = (EnvDTE.AddIn)addInInst; switch (connectMode) { case ext_ConnectMode.ext_cm_UISetup: // Initialize the UI of the add-in AddPermanentUI(); break; case ext_ConnectMode.ext_cm_Startup: // The add-in was marked to load on startup // Do nothing at this point because the IDE may not be fully initialized // Visual Studio will call OnStartupComplete when fully initialized break; case ext_ConnectMode.ext_cm_AfterStartup: // The add-in was loaded by hand after startup using the Add-In Manager // Initialize it in the same way that when is loaded on startup InitializeAddIn(); break; } } catch (System.Exception e) { System.Windows.Forms.MessageBox.Show(e.ToString()); } }
/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary> /// <param term='application'>Root object of the host application.</param> /// <param term='connectMode'>Describes how the Add-in is being loaded.</param> /// <param term='addInInst'>Object representing this Add-in.</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (EnvDTE.AddIn)addInInst; if(connectMode == ext_ConnectMode.ext_cm_UISetup) { object []contextGUIDS = new object[] { }; Commands2 commands = (Commands2)_applicationObject.Commands; string toolsMenuName; try { //If you would like to move the command to a different menu, change the word "Tools" to the // English version of the menu. This code will take the culture, append on the name of the menu // then add the command to that menu. You can find a list of all the top-level menus in the file // CommandBar.resx. string resourceName; ResourceManager resourceManager = new ResourceManager("JsParser_AddIn.CommandBar", Assembly.GetExecutingAssembly()); CultureInfo cultureInfo = new CultureInfo(_applicationObject.LocaleID); if(cultureInfo.TwoLetterISOLanguageName == "zh") { System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent; resourceName = String.Concat(parentCultureInfo.Name, "Tools"); } else { resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools"); } toolsMenuName = resourceManager.GetString(resourceName); } catch { //We tried to find a localized version of the word Tools, but one was not found. // Default to the en-US word, which may work for the current culture. 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; //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: var comShow = commands.AddNamedCommand2(_addInInstance, "Show", "Javascript Parser", "Javascript Parser AddIn Show", true, 629, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton ); //Add a command to the Commands collection: var comFind = commands.AddNamedCommand2(_addInInstance, "Find", "Javascript Parser Find", "Javascript Parser AddIn 'Find' Feature", true, 0, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton ); //Add a control for the command to the tools menu: if(toolsPopup != null) { if (comShow != null) { comShow.AddControl(toolsPopup.CommandBar, 1); } if (comFind != null) { comFind.Bindings = "Text Editor::SHIFT+ALT+J"; comFind.AddControl(toolsPopup.CommandBar, 2); } } } 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. } } //Subscribe to IDE events Events events = _applicationObject.Events; _documentEvents = events.get_DocumentEvents(null); _windowEvents = events.get_WindowEvents(null); _documentEvents.DocumentSaved += documentEvents_DocumentSaved; _documentEvents.DocumentOpened += documentEvents_DocumentOpened; _windowEvents.WindowActivated += windowEvents_WindowActivated; _uiThemeProvider = new DefaultUIThemeProvider(); _jsParserService = new JsParserService(Settings.Default); _jsParserToolWindowManager = new JsParserToolWindowManager(_jsParserService, _uiThemeProvider, () => { return EnsureWindowCreated(); }); }
/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary> /// <param term='application'>Root object of the host application.</param> /// <param term='connectMode'>Describes how the Add-in is being loaded.</param> /// <param term='addInInst'>Object representing this Add-in.</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (EnvDTE.AddIn)addInInst; if (connectMode == ext_ConnectMode.ext_cm_UISetup) { object [] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)_applicationObject.Commands; string toolsMenuName; try { //If you would like to move the command to a different menu, change the word "Tools" to the // English version of the menu. This code will take the culture, append on the name of the menu // then add the command to that menu. You can find a list of all the top-level menus in the file // CommandBar.resx. string resourceName; ResourceManager resourceManager = new ResourceManager("JsParser_AddIn.CommandBar", Assembly.GetExecutingAssembly()); CultureInfo cultureInfo = new CultureInfo(_applicationObject.LocaleID); if (cultureInfo.TwoLetterISOLanguageName == "zh") { System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent; resourceName = String.Concat(parentCultureInfo.Name, "Tools"); } else { resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools"); } toolsMenuName = resourceManager.GetString(resourceName); } catch { //We tried to find a localized version of the word Tools, but one was not found. // Default to the en-US word, which may work for the current culture. 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; //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: var comShow = commands.AddNamedCommand2(_addInInstance, "Show", "Javascript Parser", "Javascript Parser AddIn Show", true, 629, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton ); //Add a command to the Commands collection: var comFind = commands.AddNamedCommand2(_addInInstance, "Find", "Javascript Parser Find", "Javascript Parser AddIn 'Find' Feature", true, 0, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton ); //Add a control for the command to the tools menu: if (toolsPopup != null) { if (comShow != null) { comShow.AddControl(toolsPopup.CommandBar, 1); } if (comFind != null) { comFind.Bindings = "Text Editor::SHIFT+ALT+J"; comFind.AddControl(toolsPopup.CommandBar, 2); } } } 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. } } //Subscribe to IDE events Events events = _applicationObject.Events; _documentEvents = events.get_DocumentEvents(null); _windowEvents = events.get_WindowEvents(null); _documentEvents.DocumentSaved += documentEvents_DocumentSaved; _documentEvents.DocumentOpened += documentEvents_DocumentOpened; _windowEvents.WindowActivated += windowEvents_WindowActivated; _uiThemeProvider = new DefaultUIThemeProvider(); _jsParserService = new JsParserService(Settings.Default); _jsParserToolWindowManager = new JsParserToolWindowManager(_jsParserService, _uiThemeProvider, () => { return(EnsureWindowCreated()); }); }
//public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) public void OnConnection(object addInInst) { addInInstance = (AddIn)addInInst; applicationObject = (DTE2)addInInstance.DTE; //switch (connectMode) //{ // case ext_ConnectMode.ext_cm_Startup: // Commands2 commands = (Commands2)applicationObject.Commands; // CommandBar menuBarCommandBar = ((CommandBars)applicationObject.CommandBars)["MenuBar"]; // CommandBar standardCommandBar = ((CommandBars)applicationObject.CommandBars)["Standard"]; // this.openViewerButton = AddCommandBarButton(commands, // standardCommandBar, // "OpenInternalsViewer", // "Open Internals Viewer", // Properties.Resources.allocationMapIcon, // Properties.Resources.allocationMapIconMask); // CommandBarPopup commandBarPopup = (CommandBarPopup)menuBarCommandBar.Controls.Add(MsoControlType.msoControlPopup, // System.Type.Missing, // System.Type.Missing, // 8, // Properties.Resources.AppWindow); // commandBarPopup.Caption = "Internals Viewer"; // AddCommandBarPopup(commands, // commandBarPopup, // "AllocationMap", // "Allocation Map", // "Show the Allocation Map", // Properties.Resources.allocationMapIcon, // Properties.Resources.allocationMapIconMask); // AddCommandBarPopup(commands, // commandBarPopup, // "TransactionLog", // "Display Transaction Log", // "Include the Transaction Log with query results", // Properties.Resources.TransactionLogIcon, // Properties.Resources.allocationMapIconMask); //IObjectExplorerEventProvider provider = ServiceCache.GetObjectExplorer().GetService(typeof(IObjectExplorerEventProvider)) as IObjectExplorerEventProvider; //http://sqlblog.com/blogs/jonathan_kehayias/archive/2009/08/22/sql-2008-r2-breaks-ssms-addins.aspx //ObjectExplorerService objExplorerService = (ObjectExplorerService)ServiceCache.ServiceProvider; //.GetService(typeof(IObjectExplorerService)); // Test to get using name instead of array position //ContextService cs = (ContextService)objExplorerService.Container.Components["ContextService"]; //cs.ObjectExplorerContext.CurrentContextChanged += new NodesChangedEventHandler(Provider_SelectionChanged); ////cs.ObjectExplorerContext.ItemsRefreshed //provider.NodesRefreshed += new NodesChangedEventHandler(Provider_NodesRefreshed); //provider.NodesAdded += new NodesChangedEventHandler(Provider_NodesRefreshed); //provider.BufferedNodesAdded += new NodesChangedEventHandler(Provider_NodesRefreshed); // this.windowManager = new WindowManager(applicationObject, addInInstance); // this.queryEditorExtender = new QueryEditorExtender(applicationObject, this.windowManager); // break; //} }
private void Initialise(object instance) { _addIn = (EnvDTE.AddIn)instance; Application = ((EnvDTE.AddIn)instance).DTE; _commands = (Commands2)Application.Commands; }
public DTE_Addin(DTE_Main InMain, EnvDTE.AddIn InAddin) { mMain = InMain; mAddin = InAddin; }
/// <summary> /// /// </summary> /// <param name="dte">VS宿主</param> /// <param name="addin">插件实例</param> public DTEHelper(DTE2 dte, EnvDTE.AddIn addin) { this._dte = dte; this._addin = addin; }
/// <summary> /// Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded. /// </summary> /// <param term='application'>Root object of the host application. </param> /// <param term='connectMode'>Describes how the Add-in is being loaded. </param> /// <param term='addInInst'>Object representing this Add-in. </param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (EnvDTE.AddIn)addInInst; vsAddIn.Connect(_applicationObject, _addInInstance); }
/// <summary> /// Run initialization code on first connection of the AddIn /// </summary> /// <param name="appObj">Application Object</param> /// <param name="addin">Add In Object</param> public void Connect(DTE2 appObj, EnvDTE.AddIn addin) { /// Initialize External and Internal Variables. _applicationObject = appObj; _addInInstance = addin; isDebugEngineRunning = false; /// Register Command Events _commandEvents = new VSNDKCommandEvents(appObj); _commandEvents.RegisterCommand(GuidList.guidVSStd2KString, CommandConstants.cmdidSolutionPlatform, cmdNewPlatform_afterExec, cmdNewPlatform_beforeExec); _commandEvents.RegisterCommand(GuidList.guidVSStd2KString, CommandConstants.cmdidSolutionCfg, cmdNewPlatform_afterExec, cmdNewPlatform_beforeExec); _commandEvents.RegisterCommand(GuidList.guidVSStd97String, CommandConstants.cmdidStartDebug, startDebugCommandEvents_AfterExecute, startDebugCommandEvents_BeforeExecute); _commandEvents.RegisterCommand(GuidList.guidVSStd2KString, CommandConstants.cmdidStartDebugContext, startDebugCommandEvents_AfterExecute, startDebugCommandEvents_BeforeExecute); _commandEvents.RegisterCommand(GuidList.guidVSStd97String, CommandConstants.cmdidStartNoDebug, startNoDebugCommandEvents_AfterExecute, startNoDebugCommandEvents_BeforeExecute); _commandEvents.RegisterCommand(GuidList.guidVSDebugGroup, CommandConstants.cmdidDebugBreakatFunction, cmdNewFunctionBreakpoint_afterExec, cmdNewFunctionBreakpoint_beforeExec); // ??? Check why Solution.SolutionBuild.Deploy(false) fires OnBuildComplete event immediately after start deploying when _buildEvents is initialized here. // ??? To avoid that, we should initialize _buildEvents in BuildBar(), but here should be the right place. _buildEvents = _applicationObject.Events.BuildEvents; _buildEvents.OnBuildBegin += new _dispBuildEvents_OnBuildBeginEventHandler(this.OnBuildBegin); // Create a reference to the Output window. // Create a tool window reference for the Output window // and window pane. OutputWindow ow = _applicationObject.ToolWindows.OutputWindow; // Select the Build pane in the Output window. _owP = ow.OutputWindowPanes.Item("Build"); _owP.Activate(); DisableIntelliSenseErrorReport(true); CheckSolutionPlatformCommand(); }
/// <summary> /// Run initialization code on first connection of the AddIn. /// </summary> /// <param name="appObj"> Application Object. </param> /// <param name="addin"> Add In Object. </param> public void Connect(DTE2 appObj, EnvDTE.AddIn addin) { /// Initialize External and Internal Variables. _applicationObject = appObj; _addInInstance = addin; configTable = new List<configtableentry>(); /// Register Command Events _commandEvents = new VSNDKCommandEvents(appObj); _commandEvents.RegisterCommand(GuidList.guidVSStd2KString, CommandConstants.cmdidSolutionPlatform, cmdNewPlatform_afterExec, cmdNewPlatform_beforeExec); _commandEvents.RegisterCommand(GuidList.guidVSDebugGroup, CommandConstants.cmdidDebugBreakatFunction, cmdNewFunctionBreakpoint_afterExec, cmdNewFunctionBreakpoint_beforeExec); DisableIntelliSenseErrorReport(true); CheckSolutionPlatformCommand(); }
void IDTExtensibility2.OnDisconnection( Extensibility.ext_DisconnectMode dmDisconnectMode, ref System.Array arrCustom ) { // Remove command handlers _cmdevDebugStart.BeforeExecute -= new EnvDTE._dispCommandEvents_BeforeExecuteEventHandler( OnBeforeRun ); _cmdevDebugStart.AfterExecute -= new EnvDTE._dispCommandEvents_AfterExecuteEventHandler( OnAfterRun ); _cmdevDebugStart = null; _cmdevNoDebugStart.BeforeExecute -= new EnvDTE._dispCommandEvents_BeforeExecuteEventHandler( OnBeforeRun ); _cmdevNoDebugStart.AfterExecute -= new EnvDTE._dispCommandEvents_AfterExecuteEventHandler( OnAfterRun ); _cmdevNoDebugStart = null; _pApplication = null; _pAddInInstance = null; _pf = null; }
void IDTExtensibility2.OnConnection( object oApplication, Extensibility.ext_ConnectMode cmConnectMode, object oAddInInstance, ref System.Array arrCustom ) { _pApplication = ( _DTE )oApplication; _pAddInInstance = ( EnvDTE.AddIn )oAddInInstance; _pf = new ProfilerForm(); _pf.Owner = null; _pf.Closed += new EventHandler(_pf_Closed); // Hook up to run events Command cmdDebug; cmdDebug = _pApplication.Commands.Item( "Debug.Start", 1 ); _cmdevDebugStart = _pApplication.Events.get_CommandEvents( cmdDebug.Guid, cmdDebug.ID ); _cmdevDebugStart.BeforeExecute += new EnvDTE._dispCommandEvents_BeforeExecuteEventHandler( OnBeforeRun ); _cmdevDebugStart.AfterExecute += new EnvDTE._dispCommandEvents_AfterExecuteEventHandler( OnAfterRun ); cmdDebug = _pApplication.Commands.Item( "Debug.StartWithoutDebugging", 1 ); _cmdevNoDebugStart = _pApplication.Events.get_CommandEvents( cmdDebug.Guid, cmdDebug.ID ); _cmdevNoDebugStart.BeforeExecute += new EnvDTE._dispCommandEvents_BeforeExecuteEventHandler( OnBeforeRun ); _cmdevNoDebugStart.AfterExecute += new EnvDTE._dispCommandEvents_AfterExecuteEventHandler( OnAfterRun ); if ( cmConnectMode == Extensibility.ext_ConnectMode.ext_cm_UISetup ) { object[] contextGUIDS = new object[] { }; foreach ( Command cmd in _pApplication.Commands ) { try { if ( cmd.Name != null && cmd.Name.StartsWith( "NProf.Connect" ) ) cmd.Delete(); } catch ( Exception ) { } } try { CommandBar barNProf = _pApplication.CommandBars[ "nprof Profiling" ]; if ( barNProf != null ) barNProf.Delete(); } catch ( Exception ) { } Command command = _pApplication.Commands.AddNamedCommand( _pAddInInstance, "Enable", "Enable nprof", "Toggle nprof integration", true, 0, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusUnsupported ); CommandBar barTools = ( CommandBar )_pApplication.CommandBars[ "Tools" ]; CommandBar barMenu = ( CommandBar )_pApplication.Commands.AddCommandBar( "nprof Profiling", vsCommandBarType.vsCommandBarTypeMenu, barTools, 1 ); CommandBarControl cbc = command.AddControl( barMenu, 1 ); } }
/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary> /// <param term='application'>Root object of the host application.</param> /// <param term='connectMode'>Describes how the Add-in is being loaded.</param> /// <param term='addInInst'>Object representing this Add-in.</param> /// <seealso class='IDTExtensibility2' /> void IDTExtensibility2.OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { try { _addInInstance = (AddIn)AddInInst; //_DTE2 = (DTE2)_addInInstance.DTE; _DTE = (DTE)_addInInstance.DTE; //_DTE = (DTE2)_addInInstance.DTE; //ovako kaze Mladen da radi svugdje //_DTE = CType(ServiceCache.ExtensibilityModel, EnvDTE.DTE) 'Ovako kaze poljak sa dev2dev da treba za ssms2008 i 2005 switch (ConnectMode) { case ext_ConnectMode.ext_cm_UISetup: // Do nothing for this add-in with temporary user interface break; case ext_ConnectMode.ext_cm_Startup: // The add-in was marked to load on startup // Do nothing at this point because the IDE may not be fully initialized // Visual Studio will call OnStartupComplete when fully initialized break; case ext_ConnectMode.ext_cm_AfterStartup: // The add-in was loaded by hand after startup using the Add-In Manager // Initialize it in the same way that when is loaded on startup AddTemporaryUI(); break; } } catch (System.Exception e) { System.Windows.Forms.MessageBox.Show(e.ToString()); } //List all commands //For Each com As Command In _DTE2.Commands // Debug.WriteLine(String.Format("Name={0} | GUID={1} | ID={2}", com.Name, com.Guid, com.ID)) //Next //Dim outputWindow As OutputWindow = CType(_DTE.Windows.Item(Constants.vsWindowKindOutput).Object, OutputWindow) //_outputWindowPane = outputWindow.OutputWindowPanes.Add("DTE Event Information - C# Event Watcher") //Nemam pojma zašto se taj output window vise ne vidi i ne mogu ga nikako prikazati? //Retrieve the event objects from the automation model //_textEditorEvents = events.TextEditorEvents //_textDocumentKeyPressEvents = (CType(events, EnvDTE80.Events2)).TextDocumentKeyPressEvents //Connect to each delegate exposed from each object retrieved above //AddHandler _textDocumentKeyPressEvents.AfterKeyPress, AddressOf AfterKeyPress //Name=Edit.DoubleClick | GUID={1496A755-94DE-11D0-8C3F-00C04FC2AAE2} | ID=134 //Events: AfterExecute, BeforeExecute //Ne koristi se nigdje, pa ne vidim svrhu. //_CommandEvents = _DTE.Events.CommandEvents("{1496A755-94DE-11D0-8C3F-00C04FC2AAE2}", 134) //----Ovo dole ne briši jer možeš naučiti neke trikove, npr. kako napraviti gumb sa grafikom //If connectMode = ext_ConnectMode.ext_cm_UISetup Then // Dim commands As Commands2 = CType(_DTE2.Commands, Commands2) // Dim toolsMenuName As String // Try // 'If you would like to move the command to a different menu, change the word "Tools" to the // ' English version of the menu. This code will take the culture, append on the name of the menu // ' then add the command to that menu. You can find a list of all the top-level menus in the file // ' CommandBar.resx. // Dim resourceManager As System.Resources.ResourceManager = New System.Resources.ResourceManager("SSMSAddinTest3.CommandBar", System.Reflection.Assembly.GetExecutingAssembly()) // Dim cultureInfo As System.Globalization.CultureInfo = New System.Globalization.CultureInfo(_DTE2.LocaleID) // If (cultureInfo.TwoLetterISOLanguageName = "zh") Then // Dim parentCultureInfo As System.Globalization.CultureInfo = cultureInfo.Parent // toolsMenuName = resourceManager.GetString(String.Concat(parentCultureInfo.Name, "Tools")) // Else // toolsMenuName = resourceManager.GetString(String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools")) // End If // Catch e As Exception // 'We tried to find a localized version of the word Tools, but one was not found. // ' Default to the en-US word, which may work for the current culture. // toolsMenuName = "Tools" // End Try // '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: // Dim commandBars As CommandBars = CType(_DTE2.CommandBars, CommandBars) // Dim menuBarCommandBar As CommandBar = commandBars.Item("MenuBar") // 'Find the Tools command bar on the MenuBar command bar: // Dim toolsControl As CommandBarControl = menuBarCommandBar.Controls.Item(toolsMenuName) // Dim toolsPopup As CommandBarPopup = CType(toolsControl, CommandBarPopup) // Try // 'Add a command to the Commands collection: // Dim command As Command = commands.AddNamedCommand2(_addInInstance, "SSMSAddinTest3", "SSMSAddinTest3", "Executes the command for SSMSAddinTest3", True, 59, Nothing, CType(vsCommandStatus.vsCommandStatusSupported, Integer) + CType(vsCommandStatus.vsCommandStatusEnabled, Integer), vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton) // 'Find the appropriate command bar on the MenuBar command bar: // command.AddControl(toolsPopup.CommandBar, 1) // Catch argumentException As 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. // End Try //End If //EnvDTE.Events events = _DTE.Events; }
/// <summary> /// Called when the AddIn is discarded. This method allows each of the commands to /// to unregister and close down on exiting. /// </summary> /// <param name="application"> Root object in the application </param> /// <param name="connectMode"> 'Mode' in which the environment is closing the addin </param> /// <param name="addIn"> Object representing this AddIn in the Object Model</param> public void OnDisconnection(EnvDTE._DTE application, Extensibility.ext_DisconnectMode disconnectMode, EnvDTE.AddIn addIn) { application.Commands.Item("FacultyClient.Connect." + m_strCommandName, 0).Delete(); }