public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { try { _application = Core.Default.CreateObjectFromComProxy(null, Application); /* * _application is stored as COMObject the common base type for all reference types in NetOffice * because this addin is loaded in different office application. * * with the CreateObjectFromComProxy method the _application instance is created as corresponding wrapper based on the com proxy type */ if (_application is Excel.Application) _hostApplicationName = "Excel"; else if (_application is Word.Application) _hostApplicationName = "Word"; else if (_application is Outlook.Application) _hostApplicationName = "Outlook"; else if (_application is PowerPoint.Application) _hostApplicationName = "PowerPoint"; else if (_application is Access.Application) _hostApplicationName = "Access"; } catch (Exception exception) { if(_hostApplicationName != null) OfficeRegistry.LogErrorMessage(_hostApplicationName, _progId, "Error occured in OnConnection. ", exception); } }
/// <summary>Implements the constructor for the Add-in object. Place your initialization code within this method.</summary> //public Connect() //{ //} /// <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 = (AddIn) addInInst; // Only execute the startup code if the connection mode is a startup mode //if( connectMode == ext_ConnectMode.ext_cm_UISetup ) { if (connectMode == ext_ConnectMode.ext_cm_AfterStartup) { //Initializing Context Context.ApplicationObject = applicationObject; Context.AddInInstance = addInInstance; //Initializing EventSinks SolutionEventSink solutionEventSink = new SolutionEventSink(); addinEventSink = new AddinEventSink(); //Initializing Controller controller = new UIController(); controller.Sinks.Add(solutionEventSink); controller.Sinks.Add(addinEventSink); controller.Init(solutionEventSink, addinEventSink); addinEventSink.OnStartup(applicationObject); if (Context.ApplicationObject.Solution.IsOpen){ solutionEventSink.OnOpenSolution(); } } }
/// <summary> /// Implements the OnConnection method of the IDTExtensibility2 interface. /// </summary> /// <remarks> /// <para> /// Receives notification that the Add-in is being loaded. /// </para> /// </remarks> /// <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) { dte = (DTE2)application; addIn = (AddIn)addInInst; ShellProxy.Instance.AddInConnected(this); }
public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { pb = new PBHelper(); application = (DTE2)Application; addInInstance = (AddIn)AddInInst; if (ConnectMode == ext_ConnectMode.ext_cm_UISetup) { object[] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)application.Commands; // get item bar Microsoft.VisualStudio.CommandBars.CommandBar itemCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)application.CommandBars)["Item"]; try { // add me commands Command command = commands.AddNamedCommand2(addInInstance, "Dw2Struct", "Generate Structure", "Generates a structure of the columns in the datawindow", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); Command command2 = commands.AddNamedCommand2(addInInstance, "Dw2Nv", "Generate NonVisualObject", "Generates an NonVisualObject of the columns in the datawindow", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); if ((command != null)) { command.AddControl(itemCommandBar, itemCommandBar.Controls.Count); } if ((command2 != null)) { command2.AddControl(itemCommandBar, itemCommandBar.Controls.Count); } } catch (System.ArgumentException) { } } }
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { try { this._applicationObject = (DTE2)application; this._addInInstance = (AddIn)addInInst; if (connectMode == ext_ConnectMode.ext_cm_Startup && AddinSetupState.State == SetupState.FirstRun) { LogHelper.LogDebug("Add-in SetupState is FirstRun"); LogHelper.LogDebug("Removing add-in commands"); this.RemoveAddinCommands(); LogHelper.LogDebug("Creating add-in commands"); this.CreateAddinCommands(); LogHelper.LogDebug("Opening FirstRunStep1 form"); FirstRunStep1 firstRunStep = new FirstRunStep1(); firstRunStep.ShowDialog(); LogHelper.LogDebug("Setting add-in SetupState to complete"); AddinSetupState.State = SetupState.SetupComplete; } if (connectMode == ext_ConnectMode.ext_cm_Startup || connectMode == ext_ConnectMode.ext_cm_AfterStartup) { LogHelper.LogDebug("Creating add-in menus"); this.CreateAddinMenus(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "CodeKeep"); } }
public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { Connect.CurrentAddin = (EnvDTE.AddIn)AddInInst; Connect.CurrentApplication = (EnvDTE80.DTE2)Connect.CurrentAddin.DTE; SetObjectExplorerEventProvider(); }
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { var dte = application as DTE; if (dte == null) return; _dte = dte; try { if (dte.Version != DteVersion) { Notify("OpenWrap Visual Studio integration is not correct version, re-creating now."); dte.Solution.AddIns.OfType<AddIn>().First(x => x.ProgID == _progId).Remove(); if (dte.Version == "9.0") dte.Solution.AddIns.Add(ComConstants.ADD_IN_PROGID_2008, ComConstants.ADD_IN_DESCRIPTION, ComConstants.ADD_IN_NAME, true); else if (dte.Version == "10.0") dte.Solution.AddIns.Add(ComConstants.ADD_IN_PROGID_2010, ComConstants.ADD_IN_DESCRIPTION, ComConstants.ADD_IN_NAME, true); else if (dte.Version == "11.0") dte.Solution.AddIns.Add(ComConstants.ADD_IN_PROGID_2012, ComConstants.ADD_IN_DESCRIPTION, ComConstants.ADD_IN_NAME, true); return; } _rootPath = GetRootLocation(dte.Solution.FullName); if (_rootPath == null) return; Notify("OpenWrap Visual Studio Integration ({0}) starting.", FileVersionInfo.GetVersionInfo(GetType().Assembly.Location).FileVersion); Notify("Root location: " + _rootPath); LoadAppDomain(); } catch (Exception e) { Notify("OpenWrap failed to initialize. Improbability Drive has been activated.\r\n", 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 = (AddIn)addInInst; if (connectMode == ext_ConnectMode.ext_cm_UISetup) { object[] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)_applicationObject.Commands; Microsoft.VisualStudio.CommandBars.CommandBar standardToolBar = ((Microsoft.VisualStudio.CommandBars.CommandBars) _applicationObject.CommandBars)["Project"]; try { Command command = commands.AddNamedCommand2(_addInInstance, "MVCScaffolder", "MVCScaffolder...", "Executes the command for MVCScaffolder", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); if ((command != null) && (standardToolBar != null)) { CommandBarControl ctrl = (CommandBarControl)command.AddControl(standardToolBar, 1); ctrl.TooltipText = "Executes the command for MVCScaffolder"; } } catch (System.ArgumentException) { } } }
public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { try { _vbe = Application as VBE; _addin = AddInInst as AddIn; switch (ConnectMode) { case ext_ConnectMode.ext_cm_AfterStartup: InitializeAddIn(); break; case ext_ConnectMode.ext_cm_Startup: break; case ext_ConnectMode.ext_cm_External: break; case ext_ConnectMode.ext_cm_CommandLine: break; default: throw new ArgumentOutOfRangeException("ConnectMode"); } } catch (Exception e) { MessageBox.Show(e.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <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; _addInInstance = (AddIn)addInInst; // Core var name = _addInInstance.Name; var outputPane = _application.ToolWindows.OutputWindow.OutputWindowPanes.GetPane(name); var feedback = new FeedbackManager(name, outputPane); _core = new Core(feedback); // Events _events = (Events2)_application.Events; _projectsEvents = _events.ProjectsEvents; _projectItemsEvents = _events.ProjectItemsEvents; _documentEvents = _events.DocumentEvents; _buildEvents = _events.BuildEvents; AttachEvents(); // If being connected when Solution is already loaded - try to load all projects if (_application.Solution != null) { _core.Load(_application.Solution); } }
/// <summary> /// Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded. /// </summary> /// <param name='application'> /// Root object of the host application. /// </param> /// <param name='connectMode'> /// Describes how the Add-in is being loaded. /// </param> /// <param name='addIn'> /// Object representing this Add-in. /// </param> /// /// <param name='custom'> /// Array of parameters that are host application specific. /// </param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addIn, ref Array custom) { _application = (DTE2)application; _addIn = (AddIn)addIn; try { if (connectMode == ext_ConnectMode.ext_cm_Startup || connectMode == ext_ConnectMode.ext_cm_AfterStartup) { _listener = CreateTraceListener(); _env = new ControllerEnvironment(new WindowHandle(_application.MainWindow.HWnd), _listener); _controller = CreateController(); _controller.OnConnectionStateChange += OnConnectionStateChange; CreateCommands(); CreateToolWindow(); _listener.WriteLine("Addin initialized"); if (connectMode == ext_ConnectMode.ext_cm_AfterStartup) { OnStartupComplete(ref custom); } } } catch (Exception ex) { if (_listener != null) { _listener.WriteLine(ex); } } }
/// <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 = (AddIn)addInInst; if (connectMode == ext_ConnectMode.ext_cm_UISetup) { // Create the command object object[] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)_applicationObject.Commands; try { Command cmd = commands.AddNamedCommand2(_addInInstance, "DocumentClass", "Class Documentator", "Document your class module ", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); // Create a command bar on the code window CommandBar CmdBar = ((CommandBars)_applicationObject.CommandBars)["Code Window"]; // Add a command to the Code Window's shortcut menu. CommandBarControl cmdBarCtl = (CommandBarControl)cmd.AddControl(CmdBar, CmdBar.Controls.Count + 1); cmdBarCtl.Caption = "Class Doc"; } catch (System.ArgumentException) { } } }
/// <summary>Implements the OnConnection method of theIDTExtensibility2 interface. Receives notification that the Add-in isbeing loaded.</summary> /// <param term='application'>Root object of the hostapplication.</param> /// <param term='connectMode'>Describes how the Add-in isbeing 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) { try { Logger.SetListener(new FileLogger()); Logger.Write("Connecting to Visual Studio"); _applicationObject = (DTE2) application; StartupHandler.SetApplication(_applicationObject); setupListener(); bindWorkspaceEvents(); SolutionStateHandler.BindEvents(_applicationObject); SaverOfFilesThatVSKeepsStashigInMem.BindEvents(_applicationObject); _addInInstance = (AddIn) addInInst; Logger.Write("Adding menu item"); RegisterCommandHandlers(); if (connectMode == ext_ConnectMode.ext_cm_UISetup || theShitIsNotThere()) { if (connectMode == ext_ConnectMode.ext_cm_UISetup) Analytics.SendEvent("UI_SETUP"); else Analytics.SendEvent("UI_SETUP_MANUAL"); AddMenuItems(); Logger.Write("Menu item added"); _initializedMenu = true; } AddContextMenue(); } catch(Exception ex) { Logger.Write("OnConnect " + ex); } }
/// <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 = (AddIn)addInInst; if(connectMode == ext_ConnectMode.ext_cm_UISetup) { // Add the command Command cmd = (Command)_applicationObject.Commands.AddNamedCommand(_addInInstance, "BadWords", "BadWords", "Search for bad words", true, RED_STAR_ICON, null, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled); CommandBar stdCmdBar = null; // Reference the Visual Studio standard toolbar. CommandBars commandBars = (CommandBars)_applicationObject.CommandBars; foreach (CommandBar cb in commandBars) { if (cb.Name == "Standard") { stdCmdBar = cb; break; } } // Add a button to the standard toolbar. CommandBarControl stdCmdBarCtl = (CommandBarControl)cmd.AddControl(stdCmdBar, stdCmdBar.Controls.Count + 1); // Set a caption for the toolbar button. stdCmdBarCtl.Caption = "Search for bad words"; // Set the toolbar's button style to an icon button. CommandBarButton cmdBarBtn = (CommandBarButton)stdCmdBarCtl; cmdBarBtn.Style = MsoButtonStyle.msoButtonIcon; } }
/// <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 = (AddIn)addInInst; _dbgWatchConfig = new QuickWatchConfig(); try { CommandBar commandBar = ((CommandBars)_applicationObject.CommandBars)["Code Window"]; // Create Quick watch menu _controlQuickWatch = commandBar.Controls.Add(MsoControlType.msoControlButton, System.Reflection.Missing.Value, System.Reflection.Missing.Value, 1, true); _controlQuickWatch.Caption = "QuickWatchEx..."; _controlQuickWatch.Enabled = IsInDebugMode(_applicationObject); _menuItemHandlerQuickWatch = (CommandBarEvents)_applicationObject.Events.CommandBarEvents[_controlQuickWatch]; _menuItemHandlerQuickWatch.Click += MenuItemHandlerQuickWatch_Click; _debuggerEvents = _applicationObject.Events.DebuggerEvents; _debuggerEvents.OnEnterDesignMode += DebuggerEvents_OnEnterDesignMode; _debuggerEvents.OnEnterBreakMode += DebuggerEvents_OnEnterBreakMode; _debuggerEvents.OnEnterRunMode += DebuggerEvents_OnEnterRunMode; } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Implements the OnConnection method of the IDTExtensibility2 interface. /// Receives notification that the Add-in is being loaded. /// </summary> /// <param name="application">Root object of the host application.</param> /// <param name="connectMode"> /// Describes how the Add-in is being loaded (e.g. command line or UI). This is unused since /// the add-in functions the same regardless of how it was loaded. /// </param> /// <param name="addInInst">Object representing this Add-in.</param> /// <param name="custom">Unused, but could contain host specific data for the add-in.</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection( object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { dte_ = (DTE2)application; debuggerEvents_ = dte_.Events.DebuggerEvents; debuggerEvents_.OnEnterDesignMode += DebuggerOnEnterDesignMode; debuggerEvents_.OnEnterRunMode += DebuggerOnEnterRunMode; commandEvents_ = dte_.Events.CommandEvents; commandEvents_.AfterExecute += CommandEventsAfterExecute; try { webServerOutputPane_ = dte_.ToolWindows.OutputWindow.OutputWindowPanes.Item( Strings.WebServerOutputWindowTitle); } catch (ArgumentException) { // This exception is expected if the window pane hasn't been created yet. webServerOutputPane_ = dte_.ToolWindows.OutputWindow.OutputWindowPanes.Add( Strings.WebServerOutputWindowTitle); } }
/// <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) { Globals.DTE = (DTE2)application; Globals.Addin = (AddIn)addInInst; solutionEvents = Globals.DTE.Events.SolutionEvents; solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened); solutionEvents.BeforeClosing += new _dispSolutionEvents_BeforeClosingEventHandler(SolutionEvents_BeforeClosing); commandManager = new CommandManager(Globals.DTE, Globals.Addin); commandBarBuilder = new CommandBarBuilder(Globals.DTE, Globals.Addin); switch (connectMode) { case ext_ConnectMode.ext_cm_UISetup: // Initialize the UI of the add-in 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 Initialize(); break; } }
/// <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 = (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 } var _solutionEvents = _applicationObject.Events.SolutionEvents; _solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened); var _documentEvents = _applicationObject.Events.DocumentEvents; _documentEvents.DocumentSaved += new _dispDocumentEvents_DocumentSavedEventHandler(_documentEvents_DocumentSaved); } }
/// <summary> /// Implements the OnDisconnection method of the IDTExtensibility2 interface. /// Occurs when he Add-in is loaded into Visual Studio. /// </summary> /// <param name="application">A reference to an instance of the IDE, DTE.</param> /// <param name="connectMode"> /// An <see cref="ext_ConnectMode"/> enumeration value that indicates /// the way the add-in was loaded into Visual Studio. /// </param> /// <param name="instance">An <see cref="AddIn"/> reference to the add-in's own instance.</param> /// <param name="custom">An empty array that you can use to pass host-specific data for use in the add-in.</param> public void OnConnection(object application, ext_ConnectMode connectMode, object instance, ref Array custom) { App = (DTE2) application; Instance = (AddIn) instance; Events = App.Events as Events2; Logger = new OutputWindowLogger(App); Logger.Log("Loading..."); Compose(); // Do not attempt to use [Import]s before this line! if(Chirp == null) { Logger.Log("Unable to load."); return; } BindEvents(); PrintLoadedEngines(); Logger.Log("Ready"); if(App.Solution.IsOpen) { SolutionOpened(); foreach (var project in App.Solution.Projects.Cast<Project>()) { ProjectAdded(project); } } }
/// <summary> /// Implements the OnConnection method of the IDTExtensibility2 interface. /// Receives notification that the Add-in is being loaded. /// </summary> /// <param name="application">The application.</param> /// <param name="connectMode">The connect mode.</param> /// <param name="addInInst">The add in inst.</param> /// <param name="custom">The custom.</param> /// <seealso class="IDTExtensibility2"/> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { if (_gitPlugin == null) { var cultureInfo = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = cultureInfo; _gitPlugin = new Plugin((DTE2)application, (AddIn)addInInst, "GitExtensions", "GitPlugin.Connect"); } switch (connectMode) { case ext_ConnectMode.ext_cm_UISetup: // Install CommandBar permanently (only runs once per AddIn) GitPluginUISetup(); 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 GitPluginUIUpdate(); 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 GitPluginInit(); break; } }
/// <summary> /// Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded. /// </summary> /// <param name="application">Root object of the host application.</param> /// <param name="connectMode">Describes how the Add-in is being loaded.</param> /// <param name="addInInst">Object representing this Add-in.</param> /// <param name="custom"></param> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; var bootstrap = new Bootstrap(_applicationObject, _addInInstance); bootstrap.Run(); }
public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { $ApplicationConstruction$ // If the addin not connected during startup, we call OnStartupComplete at hand if (ConnectMode != ext_ConnectMode.ext_cm_Startup) OnStartupComplete(ref custom); }
public void OnConnection( object application, ext_ConnectMode connectMode, object addInInst, ref Array custom ) { _pluginContext = CreatePluginContext( application, addInInst ); var fmgPluginMenuGenerator = new FMGPluginMenuGenerator( _pluginContext ); fmgPluginMenuGenerator.GenerateMenu(); }
/// <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) { _addInInstance = (AddIn)addInInst; IObjectExplorerService objectExplorer = ServiceCache.GetObjectExplorer(); IObjectExplorerEventProvider provider = (IObjectExplorerEventProvider)objectExplorer.GetService(typeof(IObjectExplorerEventProvider)); provider.SelectionChanged += new NodesChangedEventHandler(Provider_SelectionChanged); }
/// <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 = (AddIn)addInInst; buildBegin = _applicationObject.Events.BuildEvents; buildDone = _applicationObject.Events.BuildEvents; System.Diagnostics.Debug.WriteLine("Connected!"); }
/// <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 = (AddIn)addInInst; _buildEvents = _applicationObject.Events.BuildEvents; _buildEvents.OnBuildDone += new _dispBuildEvents_OnBuildDoneEventHandler(BuildEvents_OnBuildDone); }
/// <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 = (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. ResourceManager resourceManager = new ResourceManager("Tab.Right.Click.CommandBar", Assembly.GetExecutingAssembly()); CultureInfo cultureInfo = new System.Globalization.CultureInfo(_applicationObject.LocaleID); string 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: Command command = commands.AddNamedCommand2(_addInInstance, "Tab.Right.Click", "Tab.Right.Click", "Executes the command for Tab.Right.Click", 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); } } 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. } } }
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { m_application = (DTE2) application; m_addIn = (AddIn) addInInst; if (connectMode == ext_ConnectMode.ext_cm_UISetup) { CreateCommands(); } }
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInstance, ref Array custom) { _applicationObject = (DTE2)application; _buildEvents = _applicationObject.Events.BuildEvents; _buildEvents.OnBuildBegin += OnBuildBegin; _buildEvents.OnBuildProjConfigDone += OnBuildProjConfigDone; _buildEvents.OnBuildDone += OnBuildDone; }
/// <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 = (AddIn)addInInst; _debug = _applicationObject.ToolWindows.OutputWindow.OutputWindowPanes.Add("Solution Settings Loader"); Output("loaded..."); _applicationObject.Events.SolutionEvents.Opened += SolutionEvents_Opened; Output("listening for solution load..."); }
/// <summary>Environment situation established here.</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> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _addInInstance = (AddIn)addInInst; _applicationObject = (DTE2)_addInInstance.DTE; _isVisualStudio = _applicationObject.RegistryRoot.StartsWith(@"Software\Microsoft\VisualStudio"); if (connectMode == ext_ConnectMode.ext_cm_UISetup || connectMode == ext_ConnectMode.ext_cm_Startup) { object [] contextGUIDS = new object[] { }; Commands2 commandsList = (Commands2)_applicationObject.Commands; CommandBarPopup targetPopup = GetMainMenuPopup("Tools"); //remove old commands List <string> oldCommandNames = new List <string>(); oldCommandNames.Add("PoorMansTSqlFormatterSSMSAddIn.Connect.PoorMansTSqlFormatterSSMSAddIn"); oldCommandNames.Add("PoorMansTSqlFormatterSSMSAddIn.AddinConnector.FormatSelectionOrActiveWindow"); oldCommandNames.Add("PoorMansTSqlFormatterSSMSAddIn.AddinConnector.FormattingOptions"); RemoveCommands(commandsList, oldCommandNames); if (!Properties.Settings.Default.FirstInstallCompleted) { if (_isVisualStudio) { //no default shortcut - we'd just end up overwriting another one. Properties.Settings.Default.Hotkey = ""; } else { string scopeName = GetTextEditorKeyBindingScopeName(); if (scopeName != null) { Properties.Settings.Default.Hotkey = Properties.Settings.Default.Hotkey.Replace("Text Editor", scopeName); } } Properties.Settings.Default.FirstInstallCompleted = true; Properties.Settings.Default.Save(); } //add new commands Command formatCommand = commandsList.AddNamedCommand2( _addInInstance, "FormatSelectionOrActiveWindow", _generalResourceManager.GetString("FormatButtonText"), _generalResourceManager.GetString("FormatButtonToolTip"), true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton ); if ((formatCommand != null) && (targetPopup != null)) { formatCommand.AddControl(targetPopup.CommandBar, 1); } _formatCommand = formatCommand; SetFormatHotkey(); Command optionsCommand = commandsList.AddNamedCommand2( _addInInstance, "FormattingOptions", _generalResourceManager.GetString("OptionsButtonText"), _generalResourceManager.GetString("OptionsButtonToolTip"), true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton ); if ((optionsCommand != null) && (targetPopup != null)) { optionsCommand.AddControl(targetPopup.CommandBar, 2); } } }
/// <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 = (AddIn)addInInst; _openedFileManager = new OpenedFileManager(_applicationObject); 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; //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, "QuickOpen", "Quick Open", "Shows quick open dialog", true, 25, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); command.Bindings = new object[] { "Global::alt+shift+o", "Global::ctrl+shift+d" }; //Add a control for the command to the tools menu: if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 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. } //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, "GoTo", "Go to definition", "Opens defenition of object under cursor", true, 39, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); command.Bindings = "Global::f12"; //Add a control for the command to the tools menu: if ((command != null) && (toolsPopup != null)) { command.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. } } }
/// <summary> /// Implements the OnConnection method of the IDTExtensibility2 /// interface. Receives notification that the Add-in is being loaded. /// </summary> /// <param term='app'>Root object of the host application.</param> /// <param term='mode'>Describes how the Add-in is being loaded.</param> /// <param term='addin'>Object representing this Add-in.</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object appObject, ext_ConnectMode mode, object addinObject, ref Array custom) { Command command = null; log.Debug("on connection ..."); app = (DTE2)appObject; addin = (AddIn)addinObject; if (mode == ext_ConnectMode.ext_cm_AfterStartup || mode == ext_ConnectMode.ext_cm_Startup) { Array contextGUIDS = new object[] { }; Commands2 commands = (Commands2)app.Commands; // Try to retrieve the command, just in case it was already created try{ log.Debug(" try to retrieve the command, just in case it was already created ..."); command = app.Commands.Item(addin.ProgID + "." + "KnowledgeNETFramework", 1); }catch (Exception e) { } log.Debug(" command: " + command); try { // Add the command if it does not exists log.Debug(" add the command if it does not exists"); if (command == null) { command = commands.AddNamedCommand2( addin, "KnowledgeNETFramework", "KnowledgeNETFramework", "Executes the command for KnowledgeNETFramework", true, 2946, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton ); } log.Debug(" command: " + command); 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. System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("AspectNETFramework.CommandBar", System.Reflection.Assembly.GetExecutingAssembly()); System.Threading.Thread thread = System.Threading.Thread.CurrentThread; System.Globalization.CultureInfo cultureInfo = thread.CurrentCulture; toolsMenuName = resourceManager.GetString(String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools")); } catch (Exception e) { // 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"; } log.Debug(" toolsMenuName: " + toolsMenuName); // Retrieve some built-in command bars Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar; CommandBarControl toolsControl; CommandBarPopup toolsPopup; CommandBarControl commandBarControl; //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: menuBarCommandBar = ((CommandBars)app.CommandBars)["MenuBar"]; //Find the Tools command bar on the MenuBar command bar: toolsControl = menuBarCommandBar.Controls[toolsMenuName]; toolsPopup = (CommandBarPopup)toolsControl; //Find the appropriate command bar on the MenuBar command bar: commandBarControl = (CommandBarControl)command.AddControl(toolsPopup.CommandBar, 1); // Add a button to the built-in "Tools" menu /* * log.Debug(" Add a button to the built-in 'Tools' menu"); * CommandBarControl cb = (CommandBarControl)command.AddControl(toolsControl, 1); * cb.Caption = "KnowledgeNETFramework"; * cb.Enabled = true; */ } catch (Exception e) { log.Debug("connection failed.", e); } } }
void NetOffice.Tools.Native.IDTExtensibility2.OnConnection(object application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { try { this.Application = new Visio.Application(null, application); TryCreateCustomObject(AddInInst); RaiseOnConnection(this.Application, ConnectMode, AddInInst, ref custom); } catch (System.Exception exception) { Factory.Console.WriteException(exception); OnError(ErrorMethodKind.OnConnection, exception); } }
/// <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) { Logger.Info(string.Format("Initializing WakaTime v{0}", _version)); try { _applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; _editorVersion = _applicationObject.Version; _docEvents = _applicationObject.Events.DocumentEvents; _docEvents.DocumentOpened += DocEventsOnDocumentOpened; _docEvents.DocumentSaved += DocEventsOnDocumentSaved; _windowsEvents = _applicationObject.Events.WindowEvents; _windowsEvents.WindowActivated += WindowsEventsOnWindowActivated; 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: CommandBar menuBarCommandBar = ((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: Command command = commands.AddNamedCommand2(_addInInstance, "iTimeTrack", "iTimeTrack", "iTimeTrack Settings", 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); } } catch (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. } } // Make sure python is installed if (!PythonManager.IsPythonInstalled()) { var url = PythonManager.PythonDownloadUrl; Downloader.DownloadPython(url, WakaTimeConstants.UserConfigDir); } if (!DoesCliExist() || !IsCliLatestVersion()) { try { Directory.Delete(string.Format("{0}\\itimetrack-master", WakaTimeConstants.UserConfigDir), true); } catch { /* ignored */ } Downloader.DownloadCli(WakaTimeConstants.CliUrl, WakaTimeConstants.UserConfigDir); } GetSettings(); if (string.IsNullOrEmpty(ApiKey)) { PromptApiKey(); } Logger.Info(string.Format("Finished initializing WakaTime v{0}", _version)); } catch (Exception ex) { Logger.Error("Error initializing Wakatime", ex); } }
/// <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 = (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("Randoop.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: //Command command = commands.AddNamedCommand2(_addInInstance, "Randoop", "Randoop...", "Executes the command for Randoop", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); Command command = commands.AddNamedCommand2(_addInInstance, "Randoop", "Randoop...", "Executes the command for Randoop", true, 1, 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); } } 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. } //TODO: right click to activate (p2) //_menuManager = new MenuManager(_applicationObject); //Dictionary<string, CommandBase> cmds = new Dictionary<string, CommandBase>(); //CommandBase randoopCommand = new RandoopCommand(_applicationObject); //cmds.Add("RandoopCommand", randoopCommand); //CommandBarPopup popupMenu = _menuManager.CreatePopupMenu("Assembly", _rm.GetString("RandoopMenuCaption")); //AddCommandMenu(popupMenu, cmds["RandoopCommand"], 1); #region post-randoop-functions //{ // //// Add a popup control to group our buttons under --- add submenu (new on Sep. 2012) // _cmdBarPopup = (CommandBarPopup)toolsPopup.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 2, true); // _cmdBarPopup.Caption = "post Randoop"; // _btnReduce = (CommandBarButton)_cmdBarPopup.Controls.Add(MsoControlType.msoControlButton, Type.Missing, // Type.Missing, Type.Missing, true); // _btnReduce.Style = MsoButtonStyle.msoButtonIconAndCaption; // _btnReduce.Caption = "Reducer"; // _btnReduce.TooltipText = "This command removes tests that it considers redundant"; // ////_btnFreebie.Picture = ImageConverter.ImageToIPicture(Resources.Resource.BarCode); // _btnReduce.Click += new _CommandBarButtonEvents_ClickEventHandler(_btnReduce_Click); // _btnMinimize = (CommandBarButton)_cmdBarPopup.Controls.Add(MsoControlType.msoControlButton, Type.Missing, // Type.Missing, Type.Missing, true); // _btnMinimize.Caption = "Minimizer"; // _btnMinimize.TooltipText = "This command transforms each test into a smaller one that still exhibits the same exception"; // //_btnLicensed.FaceId = 1845; // _btnMinimize.Click += new _CommandBarButtonEvents_ClickEventHandler(_btnMinimize_Click); // _btnToMSTest = (CommandBarButton)_cmdBarPopup.Controls.Add(MsoControlType.msoControlButton, Type.Missing, // Type.Missing, Type.Missing, true); // _btnToMSTest.Style = MsoButtonStyle.msoButtonIconAndCaption; // _btnToMSTest.Caption = "Converter to MSTest"; // _btnToMSTest.Click += new _CommandBarButtonEvents_ClickEventHandler(_btnMSTest_Click); //} #endregion post-randoop-functions } }
/// <summary>IDTExtensibility2 인터페이스의 OnConnection 메서드를 구현합니다. 추가 기능이 로드되고 있다는 알림 메시지를 받습니다.</summary> /// <param term='application'>호스트 응용 프로그램의 루트 개체입니다.</param> /// <param term='connectMode'>추가 기능이 로드되는 방법을 설명합니다.</param> /// <param term='addInInst'>이 추가 기능을 나타내는 개체입니다.</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { AddNewSubCommand("OpenSolutionFolderExplorer", "Open Solution Folder with Explorer", 65); AddNewSubCommand("OpenSolutionFolderCmd", "Open Command Prompt on Solution Folder", 65); AddNewSubCommand("OpenCorrespondingFile", "Toggle Source/Header", 65); AddNewSubCommand("OpenFileInSolution", "Quick Open File In Solution", 65); AddNewSubCommand("About", "About ZAssist...", 65); //AddNewSubCommand("QuickFindFunction", "Quick Find Function", 65); _applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; if (connectMode == ext_ConnectMode.ext_cm_UISetup || connectMode == ext_ConnectMode.ext_cm_Startup || connectMode == ext_ConnectMode.ext_cm_AfterStartup) { object[] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)_applicationObject.Commands; string toolsMenuName; try { //명령을 다른 메뉴로 이동하려면 "Tools"를 // 영어 버전의 메뉴로 변경합니다. 이 코드는 culture를 메뉴 이름에 추가한 다음 // 해당 메뉴에 명령을 추가합니다. 모든 최상위 메뉴의 목록을 확인하려면 // CommandBar.resx 파일을 참조하십시오. ResourceManager resourceManager = new ResourceManager("ZAssist.CommandBar", Assembly.GetExecutingAssembly()); CultureInfo cultureInfo = new System.Globalization.CultureInfo(_applicationObject.LocaleID); string resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools"); toolsMenuName = resourceManager.GetString(resourceName); } catch { //지역화된 버전의 'Tools'를 찾으려고 시도했지만 찾지 못했습니다. // 기본값을 현재 culture에서 작동할 수 있는 en-US로 지정합니다. toolsMenuName = "Tools"; } //도구 메뉴에 명령을 배치합니다. //주 메뉴 항목이 모두 들어 있는 최상위 명령 모음인 MenuBar 명령 모음 찾기: Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"]; //MenuBar 명령 모음에서 도구 명령 모음 찾기: CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName]; CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl; //추가 기능에서 처리할 명령을 여러 개 추가하면 이 try/catch 블록이 중복될 수 있습니다. // 이 경우 QueryStatus/Exec 메서드도 업데이트하여 새 명령 이름을 포함하기만 하면 됩니다. try { //명령 컬렉션에 명령 추가: CommandBar toolsMenu = ((CommandBars)(_applicationObject.CommandBars))["Tools"]; try { /// 아래 문장에서 catch 로 빠진다는 건 ZAssist 가 메뉴에 없다는 말이다. CommandBarPopup k = (CommandBarPopup)(toolsMenu.Controls["ZAssist"]); k.Caption = k.Caption + ""; } catch (ArgumentException) { CommandBarPopup commandBarPopup = (CommandBarPopup)toolsMenu.Controls.Add(MsoControlType.msoControlPopup, System.Reflection.Missing.Value, System.Reflection.Missing.Value, 1, true); subMenu = commandBarPopup; subMenu.Visible = true; subMenu.Caption = "ZAssist"; int iMenuIndex = 1; foreach (NewCommandData newCommData in m_commands) { Command newCommand = null; try { newCommand = commands.Item(_addInInstance.ProgID + "." + newCommData.GetCommandName(), -1); } catch (Exception ex) { System.Diagnostics.Debug.Print("이미 존재하는지 검사하는 곳에서 exception 발생 : ", ex.Message); } if (null == newCommand) { newCommand = commands.AddNamedCommand(_addInInstance, newCommData.GetCommandName(), newCommData.GetShowName(), newCommData.GetShowName(), true, newCommData.GetInconIndex(), ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled); } if (newCommand != null) { newCommand.AddControl(subMenu.CommandBar, iMenuIndex); } ++iMenuIndex; } } } catch (System.ArgumentException ex) { //이 경우, 같은 이름의 명령이 이미 있기 때문에 예외가 발생할 수 // 있습니다. 이 경우 명령을 다시 만들 필요가 없으며 예외를 무시해도 // 됩니다. System.Diagnostics.Debug.Print(ex.Message); } } }
void NetOffice.Tools.Native.IDTExtensibility2.OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { try { HandleOnConnection(application, connectMode, addInInst, ref custom); } catch (Exception exception) { Factory.Console.WriteException(exception); OnError(ErrorMethodKind.OnConnection, exception); } }
/// <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) { //var namesToLookFor = new List<string>() //{ // //"Cop&y", // //"Copy with Headers", // //"Select &All", // //"Sa&ve Results As", // "Page Set&up", // //"&Print" //}; _applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; if (connectMode == ext_ConnectMode.ext_cm_Startup) { object[] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)_applicationObject.Commands; string toolsMenuName = "Tools"; foreach (Command c in commands) { } //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"]; CommandBar resultGridCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["SQL Results Grid Tab Context"]; //var popup = resultGridCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 1, true) as CommandBarPopup; //popup.Caption = "TSET BUTTON"; //foreach (CommandBar commandBar in (Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars) //{ // if (commandBar.Controls.Cast<CommandBarControl>().Any(c => namesToLookFor.Any(n => c.Caption.Contains(n)))) // { // var commandNames = commandBar.Controls.Cast<CommandBarControl>().Select(c => c.Caption).ToList(); // int stop = 1; // stop = 2; // } //} //Find the Tools command bar on the MenuBar command bar: CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName]; CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl; _applicationObject.Events.WindowEvents.WindowCreated += WindowEvents_WindowCreated; //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, "ViewReferencedValue", "View Referenced Value", "Creates a new query to view the row of the referenced value", 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); //} //foreach (CommandBar commandBar in (Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars) //{ // //if (commandBar.Controls.Cast<CommandBarControl>().Any(c => namesToLookFor.Any(n => c.Caption.Contains(n)))) // //{ // // var commandNames = commandBar.Controls.Cast<CommandBarControl>().Select(c => c.Caption).ToList(); // // int stop = 1; // // stop = 2; // //} // command.AddControl(commandBar, 1); //} command.AddControl(resultGridCommandBar, 1); } catch (System.ArgumentException ex) { //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. } } }
public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { onApp = (Microsoft.Office.Interop.OneNote.Application)Application; }
/// <summary> /// Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded. /// </summary> /// <param name="Application">Root object of the host application.</param> /// <param name="ConnectMode">Describes how the Add-in is being loaded.</param> /// <param name="AddInInst">Object representing this Add-in.</param> /// <param name="custom"> Array of parameters that are host application specific.</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { this.visualStudio = (DTE2)Application; ////m_AddIn = (AddIn)AddInInst; }
void IDTExtensibility2.OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { this.Application = new Excel.Application(null, Application); RaiseOnConnection(Application, ConnectMode, AddInInst, ref custom); }
/// <summary> /// /// </summary> /// <param name="connectMode"></param> /// <returns></returns> public static bool uiSetUp(this ext_ConnectMode connectMode) { return(connectMode == ext_ConnectMode.ext_cm_UISetup); }
// ========================== // = Shared Addin Interface = // ========================== public void OnConnection(object application, ext_ConnectMode connect_mode, object addin_inst, ref Array custom) { connected_counter += 1; OnConnection2(application); }
public virtual void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { Debug.Print("ExcelComAddIn.OnConnection"); }
/// <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 = (AddIn)addInInst; if (connectMode == Extensibility.ext_ConnectMode.ext_cm_Startup) { Command command, commandS, commandC, commandX; CommandBar itemCmdBar; object[] contextGUIDS = new object[] { }; try { itemCmdBar = ((CommandBars)_applicationObject.CommandBars)["Item"]; if (itemCmdBar == null) { System.Windows.Forms.MessageBox.Show("Cannot get Solution Explorer Item menubar", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } else { // Create a Command with name Etch and then add it to the "Item" menubar for the SolutionExplorer if (!FindNamedCommand("Etch.Connect.Etch", out command)) { command = _applicationObject.Commands.AddNamedCommand(_addInInstance, "Etch", "Etch (Both)", "Generate Etch bindings", true, 6, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled); CommandBarControl cb = command.AddControl(itemCmdBar, 4) as CommandBarControl; cb.BeginGroup = true; } if (!FindNamedCommand("Etch.Connect.EtchS", out commandS)) { commandS = _applicationObject.Commands.AddNamedCommand(_addInInstance, "EtchS", "Etch (Server)", "Executes Etch server binding", true, 39, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled); commandS.AddControl(itemCmdBar, 5); } if (!FindNamedCommand("Etch.Connect.EtchC", out commandC)) { commandC = _applicationObject.Commands.AddNamedCommand(_addInInstance, "EtchC", "Etch (Client)", "Executes Etch client binding", true, 41, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled); commandC.AddControl(itemCmdBar, 6); } /* * if(!FindNamedCommand("Etch.Connect.EtchM", out commandM)) * { * commandM = _applicationObject.Commands.AddNamedCommand(_addInInstance, "EtchM", "Etch Mixin (Both)", "Executes Etch Mixin bindings", true, 6, ref contextGUIDS, (int) vsCommandStatus.vsCommandStatusSupported + (int) vsCommandStatus.vsCommandStatusEnabled); * commandM.AddControl(itemCmdBar, 7); * } * if(!FindNamedCommand("Etch.Connect.EtchMS", out commandMS)) * { * commandMS = _applicationObject.Commands.AddNamedCommand(_addInInstance, "EtchMS", "Etch Mixin (Server)", "Executes Etch Mixin server binding", true, 39, ref contextGUIDS, (int) vsCommandStatus.vsCommandStatusSupported + (int) vsCommandStatus.vsCommandStatusEnabled); * commandMS.AddControl(itemCmdBar, 8); * } * if(!FindNamedCommand("Etch.Connect.EtchMC", out commandMS)) * { * commandMC = _applicationObject.Commands.AddNamedCommand(_addInInstance, "EtchMC", "Etch Mixin (Client)", "Executes Etch Mixin client binding", true, 41, ref contextGUIDS, (int) vsCommandStatus.vsCommandStatusSupported + (int) vsCommandStatus.vsCommandStatusEnabled); * commandMC.AddControl(itemCmdBar, 9); * } */ if (!FindNamedCommand("Etch.Connect.EtchX", out commandX)) { commandX = _applicationObject.Commands.AddNamedCommand(_addInInstance, "EtchX", "Etch (XML)", "Executes Etch XML binding", true, 6, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled); commandX.AddControl(itemCmdBar, 10); } } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString(), "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } }
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { this._applicationObject = (DTE2)application; this._addInInstance = (AddIn)addInInst; if (connectMode == ext_ConnectMode.ext_cm_UISetup || connectMode == ext_ConnectMode.ext_cm_Startup) { object[] array = new object[0]; Commands2 commands = (Commands2)this._applicationObject.Commands; string index = "Tools"; CommandBar commandBar = ((CommandBars)this._applicationObject.CommandBars)["MenuBar"]; CommandBarControl commandBarControl = commandBar.Controls[index]; CommandBarPopup commandBarPopup = (CommandBarPopup)commandBarControl; CommandBars commandBars = (CommandBars)this._applicationObject.DTE.CommandBars; CommandBar commandBar2 = commandBars["Project"]; CommandBar commandBar3 = commandBars["Item"]; CommandBar commandBar4 = commandBars["Folder"]; try { CommandBarControl commandBarControl2 = commandBar2.Controls.Add(MsoControlType.msoControlButton, 1, "", 1, true); commandBarControl2.Tag = "ConnectConfig"; commandBarControl2.Caption = "wtf配置连接"; commandBarControl2.TooltipText = "ConnectConfig"; this.connectItemHandler = (CommandBarEvents)this._applicationObject.DTE.Events.get_CommandBarEvents(commandBarControl2); this.connectItemHandler.Click += ConnectItem_Click; CommandBarControl commandBarControl3 = commandBar2.Controls.Add(MsoControlType.msoControlButton, 1, "", 2, true); commandBarControl3.Tag = "AddRuleCode"; commandBarControl3.Caption = "wtf新增业务层"; commandBarControl3.TooltipText = "AddRuleCode"; this.addRuleCodeItemHandler = (CommandBarEvents)this._applicationObject.DTE.Events.get_CommandBarEvents(commandBarControl3); this.addRuleCodeItemHandler.Click += AddRuleCodeItem_Click; CommandBarControl commandBarControl4 = commandBar2.Controls.Add(MsoControlType.msoControlButton, 1, "", 3, true); commandBarControl4.Tag = "AddCodeConfig"; commandBarControl4.Caption = "wtf一键生成配置文件"; commandBarControl4.TooltipText = "AddCodeConfig"; this.AddCodeConfigItemHandler = (CommandBarEvents)this._applicationObject.DTE.Events.get_CommandBarEvents(commandBarControl4); this.AddCodeConfigItemHandler.Click += AddCodeConfigItem_Click; CommandBarControl commandBarControl5 = commandBar3.Controls.Add(MsoControlType.msoControlButton, 1, "", 1, true); commandBarControl5.Tag = "Update"; commandBarControl5.Caption = "wtf更新代码"; commandBarControl5.TooltipText = "Update"; this.updateHandler = (CommandBarEvents)this._applicationObject.DTE.Events.get_CommandBarEvents(commandBarControl5); this.updateHandler.Click += CSItem_Click; CommandBarControl commandBarControl6 = commandBar3.Controls.Add(MsoControlType.msoControlButton, 1, "", 2, true); commandBarControl6.Tag = "Update"; commandBarControl6.Caption = "wtf更新实体和访问层"; commandBarControl6.TooltipText = "Update"; this.updateEDHandler = (CommandBarEvents)this._applicationObject.DTE.Events.get_CommandBarEvents(commandBarControl6); this.updateEDHandler.Click += CSEDItem_Click; CommandBarControl commandBarControl7 = commandBar3.Controls.Add(MsoControlType.msoControlButton, 1, "", 3, true); commandBarControl7.Tag = "SqlEdit"; commandBarControl7.Caption = "wtf新增编辑页"; commandBarControl7.TooltipText = "SqlEdit"; this.SqlEditHandler = (CommandBarEvents)this._applicationObject.DTE.Events.get_CommandBarEvents(commandBarControl7); this.SqlEditHandler.Click += SqlEditItem_Click; CommandBarControl commandBarControl8 = commandBar3.Controls.Add(MsoControlType.msoControlButton, 1, "", 4, true); commandBarControl8.Tag = "SqlLsit"; commandBarControl8.Caption = "wtf新增列表页"; commandBarControl8.TooltipText = "SqlLsit"; this.SqlListHandler = (CommandBarEvents)this._applicationObject.DTE.Events.get_CommandBarEvents(commandBarControl8); this.SqlListHandler.Click += SqlListItem_Click; Command command = commands.AddNamedCommand2(this._addInInstance, "WTFCode", "WTFCode", "Executes the command for WTFCode", true, 59, ref array, 3, 3, vsCommandControlType.vsCommandControlTypeButton); if (command != null && commandBarPopup != null) { command.AddControl(commandBarPopup.CommandBar, 1); } } catch (ArgumentException) { } } }
public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { jjword = Application; app = jjword as Word.Application; }
void NetOffice.Tools.Native.IDTExtensibility2.OnConnection(object application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { try { if (null != custom && custom.Length > 0) { object firstCustomItem = custom.GetValue(1); string tryString = null != firstCustomItem?firstCustomItem.ToString() : String.Empty; System.Int32.TryParse(tryString, out _automationCode); } this.Application = new MSProject.Application(Factory, null, application); Utils = OnCreateUtils(); TryCreateCustomObject(AddInInst); RaiseOnConnection(this.Application, ConnectMode, AddInInst, ref custom); } catch (NetRuntimeSystem.Exception exception) { NetOffice.DebugConsole.Default.WriteException(exception); OnError(ErrorMethodKind.OnConnection, exception); } }
public override void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { base.OnConnection(Application, ConnectMode, AddInInst, ref custom); }
/// <summary> /// Occurs whenever an add-in is loaded into MS-Office /// </summary> /// <param name="application">A reference to an instance of the office application</param> /// <param name="connectMode">An ext_ConnectMode enumeration value that indicates the way the add-in was loaded into MS-Office</param> /// <param name="addInInst">An AddIn reference to the add-in's own instance. This is stored for later use, such as determining the parent collection for the add-in</param> /// <param name="custom">An empty array that you can use to pass host-specific data for use in the add-in</param> protected internal abstract void HandleOnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom);
public virtual void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom);
/// <summary>实现 IDTExtensibility2 接口的 OnConnection 方法。接收正在加载外接程序的通知。</summary> /// <param term='application'>宿主应用程序的根对象。</param> /// <param term='connectMode'>描述外接程序的加载方式。</param> /// <param term='addInInst'>表示此外接程序的对象。</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { m_applicationObject = (DTE2)application; m_addInInstance = (AddIn)addInInst; if ((connectMode == ext_ConnectMode.ext_cm_Startup || connectMode == ext_ConnectMode.ext_cm_AfterStartup) && m_socket == null) { initializeCallback(); object [] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)m_applicationObject.Commands; string toolsMenuName = "Tools"; //将此命令置于“工具”菜单上。 //查找 MenuBar 命令栏,该命令栏是容纳所有主菜单项的顶级命令栏: Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)m_applicationObject.CommandBars)["MenuBar"]; //在 MenuBar 命令栏上查找“工具”命令栏: // CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName]; // CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl; m_menuBarObj = menuBarCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, Type.Missing, true); m_menuBarObj.Caption = "Code Atlas"; CommandBarPopup toolsPopup = (CommandBarPopup)m_menuBarObj; // 增加工具栏 //m_toolBarObj = m_applicationObject.Commands.AddCommandBar("Code Atlas Tools", vsCommandBarType.vsCommandBarTypeToolbar); //如果希望添加多个由您的外接程序处理的命令,可以重复此 try/catch 块, // 只需确保更新 QueryStatus/Exec 方法,使其包含新的命令名。 try { foreach (Command cmd in commands) { foreach (CommandObj cmdObj in m_commandList) { if (cmd.Name == "CodeAtlas.Connect." + cmdObj.name) { cmdObj.command = cmd; } } } int nCommand = m_commandList.Length; for (int ithCmd = 0; ithCmd < nCommand; ++ithCmd) { if (m_commandList[ithCmd].command == null) { m_commandList[ithCmd].command = commands.AddNamedCommand2( m_addInInstance, m_commandList[ithCmd].name, m_commandList[ithCmd].displayName, "Executes the command for CodeAtlas", false, Type.Missing, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton); } Command cmd = m_commandList[ithCmd].command; //将对应于该命令的控件添加到“工具”菜单: cmd.AddControl(toolsPopup.CommandBar, ithCmd + 1); //cmd.AddControl(m_toolBarObj, ithCmd + 1); string key = m_commandList[ithCmd].key; if (key != null && key.Length > 0) { cmd.Bindings = key; //cmd.Bindings = "文本编辑器::alt+LEFT"; } } } catch (System.ArgumentException exception) { //如果出现此异常,原因很可能是由于具有该名称的命令 // 已存在。如果确实如此,则无需重新创建此命令,并且 // 可以放心忽略此异常。 } m_socket = new SocketThread("127.0.0.1", 12346, "127.0.0.1", 12345, onSocketCallback); m_socket.run(); } }
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = application; }
/// <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 = (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("TracExplorer.VSTrac.CommandBar", Assembly.GetExecutingAssembly()); CultureInfo cultureInfo = new CultureInfo(_applicationObject.LocaleID); if (cultureInfo.TwoLetterISOLanguageName == "zh") { System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent; resourceName = String.Concat(parentCultureInfo.Name, "View"); } else { resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "View"); } 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 = "View"; } //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: Command command = commands.AddNamedCommand2(_addInInstance, "TracExplorer", "Trac Explorer", "Opens The Trac Explorer Window", false, 1, 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); } } 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. } } }
/// <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 = (AddIn)addInInst; }
public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { app = Application; Console.WriteLine("插件已连接"); }
/// <summary> /// Called upon startup. /// Keeps a reference to the current OneNote application object. /// </summary> /// <param name="application"></param> /// <param name="connectMode"></param> /// <param name="addInInst"></param> /// <param name="custom"></param> public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { SetOneNoteApplication((Application)Application); }
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = ( DTE2 )application; _applicationObject.Events.SelectionEvents.OnChange += SelectionEvents_OnChange; }
public virtual void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { Logger.ComAddIn.Verbose("ExcelComAddIn.OnConnection"); }