Beispiel #1
0
        // constructor
        private SolutionEventHandlers(DTE dte, DTE2 dte2)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            _dte             = dte;
            _dte2            = dte2;
            myEvents         = dte.Events;
            myDocumentEvents = dte.Events.DocumentEvents;

            myDocumentEvents.DocumentOpened += (doc) =>
            {
                // The outer delegate is synchronous, but kicks off async work via a method that accepts an async delegate.
                _ = ThreadHelper.JoinableTaskFactory.RunAsync(async delegate
                {
                    await myDocumentEvents_DocumentOpenedAsync(doc);
                });
            };
            myDocumentEvents.DocumentSaved += (doc) =>
            {
                // The outer delegate is synchronous, but kicks off async work via a method that accepts an async delegate.
                _ = ThreadHelper.JoinableTaskFactory.RunAsync(async delegate
                {
                    await myDocumentEvents_DocumentSavedAsync(doc);
                });
            };
            CSharpProjectItemsEvents              = (ProjectItemsEvents)dte.Events.GetObject("CSharpProjectItemsEvents");
            CSharpProjectItemsEvents.ItemRenamed += CSharpItemRenamed;
            myEvents.SolutionEvents.Opened       += SolutionEvents_Opened;
            _VSOutputWindow = new VSOutputWindow(_dte2);
        }
Beispiel #2
0
        public void BindEvents()
        {
            EnvDTE.Events events = m_applicationObject.Events;

            m_solutionEvents = (EnvDTE.SolutionEvents)events.SolutionEvents;
            m_buildEvents    = (EnvDTE.BuildEvents)events.BuildEvents;
            m_dteEvents      = (EnvDTE.DTEEvents)events.DTEEvents;
            m_debuggerEvents = (EnvDTE.DebuggerEvents)events.DebuggerEvents;

            m_solutionEvents.AfterClosing       += new _dispSolutionEvents_AfterClosingEventHandler(this.AfterClosing);
            m_solutionEvents.BeforeClosing      += new _dispSolutionEvents_BeforeClosingEventHandler(this.BeforeClosing);
            m_solutionEvents.Opened             += new _dispSolutionEvents_OpenedEventHandler(this.Opened);
            m_solutionEvents.ProjectAdded       += new _dispSolutionEvents_ProjectAddedEventHandler(this.ProjectAdded);
            m_solutionEvents.ProjectRemoved     += new _dispSolutionEvents_ProjectRemovedEventHandler(this.ProjectRemoved);
            m_solutionEvents.ProjectRenamed     += new _dispSolutionEvents_ProjectRenamedEventHandler(this.ProjectRenamed);
            m_solutionEvents.QueryCloseSolution += new _dispSolutionEvents_QueryCloseSolutionEventHandler(this.QueryCloseSolution);
            m_solutionEvents.Renamed            += new _dispSolutionEvents_RenamedEventHandler(this.Renamed);

            m_buildEvents.OnBuildBegin           += new _dispBuildEvents_OnBuildBeginEventHandler(this.OnBuildBegin);
            m_buildEvents.OnBuildDone            += new _dispBuildEvents_OnBuildDoneEventHandler(this.OnBuildDone);
            m_buildEvents.OnBuildProjConfigBegin += new _dispBuildEvents_OnBuildProjConfigBeginEventHandler(this.OnBuildProjConfigBegin);
            m_buildEvents.OnBuildProjConfigDone  += new _dispBuildEvents_OnBuildProjConfigDoneEventHandler(this.OnBuildProjConfigDone);

            m_dteEvents.ModeChanged += new _dispDTEEvents_ModeChangedEventHandler(this.DTEModeChanged);

            m_debuggerEvents.OnEnterRunMode    += new _dispDebuggerEvents_OnEnterRunModeEventHandler(DebuggerOnEnterRunMode);
            m_debuggerEvents.OnEnterDesignMode += new _dispDebuggerEvents_OnEnterDesignModeEventHandler(DebuggerOnEnterDesignMode);
        }
        /// <summary>Initialization of the package; this method is called right after the package is sited, so this is the place where you can put all the initialization code that rely on services provided by VisualStudio.</summary>
        protected override void Initialize()
        {
            try
            {
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
                base.Initialize();

                // Add our command handlers for menu (commands must exist in the .vsct file)
                OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
                if (mcs != null)
                {
                    // Create the command for the tool window
                    CommandID   toolwndCommandID = new CommandID(GuidList.guidSpiraExplorerCmdSet, (int)PkgCmdIDList.cmdViewExplorerWindow);
                    MenuCommand menuToolWin      = new MenuCommand(ShowToolWindow, toolwndCommandID);
                    mcs.AddCommand(menuToolWin);
                }

                //Attach to the environment to get events..
                this._EnvironEvents = Business.StaticFuncs.GetEnvironment.Events;
                this._SolEvents     = Business.StaticFuncs.GetEnvironment.Events.SolutionEvents;
                if (this._EnvironEvents != null && this._SolEvents != null)
                {
                    this._SolEvents.Opened       += new EnvDTE._dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened);
                    this._SolEvents.AfterClosing += new EnvDTE._dispSolutionEvents_AfterClosingEventHandler(SolutionEvents_AfterClosing);
                    this._SolEvents.Renamed      += new EnvDTE._dispSolutionEvents_RenamedEventHandler(SolutionEvents_Renamed);
                }
            }
            catch (Exception ex)
            {
                Logger.LogMessage(ex, "Initialize()");
                MessageBox.Show(StaticFuncs.getCultureResource.GetString("app_General_UnexpectedError"), StaticFuncs.getCultureResource.GetString("app_General_ApplicationShortName"), MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Method for creating and writting to a debug window
        /// </summary>
        /// <param name="application"></param>
        /// <param name="message"></param>
        public void WriteToOutputWindow(DTE2 application, string message)
        {
            try
            {
                EnvDTE.Events events       = application.Events;
                OutputWindow  outputWindow = (OutputWindow)application.Windows.Item(Constants.vsWindowKindOutput).Object;

                // Find the "Test Pane" Output window pane; if it doesn't exist,
                // create it.
                OutputWindowPane pane = null;
                try
                {
                    pane = outputWindow.OutputWindowPanes.Item("Format SQL");
                }
                catch
                {
                    pane = outputWindow.OutputWindowPanes.Add("Format SQL");
                }

                // Show the Output window and activate the new pane.
                outputWindow.Parent.AutoHides = false;
                outputWindow.Parent.Activate();
                pane.Activate();

                // Add a line of text to the new pane.
                pane.OutputString(message + "\r\n");
            }
            catch
            {
                //MessageBox.Show(message, "T-SQL Tidy Error");
            }
        }
Beispiel #5
0
        /// <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;

            // Retrieve the event objects from the automation model.
            EnvDTE.Events events = _applicationObject.Events;
            // Send event messages to the Output window.
            OutputWindow outputWindow = (OutputWindow)_applicationObject.Windows.Item(Constants.vsWindowKindOutput).Object;

            //Constants.vsWindowKindMainWindow;

            outputWindowPane = outputWindow.OutputWindowPanes.Add("DTE Event Information");
            // Retrieve the event objects from the automation model.
            events.SelectionEvents.OnChange += new _dispSelectionEvents_OnChangeEventHandler(this.SelectionEvents_OnChange);
            events.get_CommandEvents("{00000000-0000-0000-0000-000000000000}", 0).AfterExecute += new _dispCommandEvents_AfterExecuteEventHandler(this.AfterExecuteEventHandler);
            winEvents =
                (EnvDTE.WindowEvents)events.get_WindowEvents(null);

            // Connect to each delegate exposed from each object
            // retrieved above.
            winEvents.WindowActivated += new
                                         _dispWindowEvents_WindowActivatedEventHandler
                                             (this.WindowActivated);
            winEvents.WindowClosing += new
                                       _dispWindowEvents_WindowClosingEventHandler
                                           (this.WindowClosing);
            winEvents.WindowCreated += new
                                       _dispWindowEvents_WindowCreatedEventHandler
                                           (this.WindowCreated);
            winEvents.WindowMoved += new
                                     _dispWindowEvents_WindowMovedEventHandler
                                         (this.WindowMoved);
        }
Beispiel #6
0
        public void OnConnection(object app, Extensibility.ext_ConnectMode mode, object addin, ref System.Array custom)
        {
            appobj_ = (_DTE)app;
            addin_  = (AddIn)addin;

            EnvDTE.Events events = appobj_.Events;
            events_  = (EnvDTE.WindowEvents)events.get_WindowEvents();
            handler_ = new _dispWindowEvents_WindowActivatedEventHandler(this.OnWindowActivated);
            events_.WindowActivated += handler_;
        }
Beispiel #7
0
 private Root(DTE dte)
 {
     _dte             = dte;
     myEvents         = dte.Events;
     myDocumentEvents = dte.Events.DocumentEvents;
     myDocumentEvents.DocumentSaved       += myDocumentEvents_DocumentSaved;
     myDocumentEvents.DocumentOpened      += MyDocumentEvents_DocumentOpened;
     CSharpProjectItemsEvents              = (ProjectItemsEvents)dte.Events.GetObject("CSharpProjectItemsEvents");
     CSharpProjectItemsEvents.ItemRenamed += CSharpItemRenamed;
 }
Beispiel #8
0
        public void ensureDTE()
        {
            if (_dte == null)
            {
                _dte         = (DTE2)GetService(typeof(DTE));
                _dteEvents   = _dte.Events;
                _buildEvents = _dteEvents.BuildEvents;

                _buildEvents.OnBuildBegin += BeforeBuild;
            }
        }
Beispiel #9
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            applicationObject = serviceProvider.GetService(typeof(SDTE)) as EnvDTE80.DTE2;//EnvDTE80.DTE2;

            //Need to keep strong reference to _events and _documentEvents otherwise they will be garbage collected
            _events         = applicationObject.Events;
            _documentEvents = _events.DocumentEvents;

            _documentEvents.DocumentSaved   += OnDocumentSaved;
            _documentEvents.DocumentClosing += OnDocumentClosing;
        }
Beispiel #10
0
 // constructor
 private SolutionEventHandlers(DTE dte, DTE2 dte2)
 {
     _dte             = dte;
     _dte2            = dte2;
     myEvents         = dte.Events;
     myDocumentEvents = dte.Events.DocumentEvents;
     myDocumentEvents.DocumentSaved       += myDocumentEvents_DocumentSaved;
     CSharpProjectItemsEvents              = (ProjectItemsEvents)dte.Events.GetObject("CSharpProjectItemsEvents");
     CSharpProjectItemsEvents.ItemRenamed += CSharpItemRenamed;
     myEvents.SolutionEvents.Opened       += SolutionEvents_Opened;
     _VSOutputWindow = new VSOutputWindow(_dte2);
 }
Beispiel #11
0
 // constructor
 private Root(DTE dte)
 {
     _dte             = dte;
     myEvents         = dte.Events;
     myDocumentEvents = dte.Events.DocumentEvents;
     myDocumentEvents.DocumentSaved       += myDocumentEvents_DocumentSaved;
     myDocumentEvents.DocumentOpened      += MyDocumentEvents_DocumentOpened;
     CSharpProjectItemsEvents              = (ProjectItemsEvents)dte.Events.GetObject("CSharpProjectItemsEvents");
     CSharpProjectItemsEvents.ItemRenamed += CSharpItemRenamed;
     myEvents.SolutionEvents.Opened       += SolutionEvents_Opened;
     myEvents.BuildEvents.OnBuildBegin    += BuildEvents_OnBuildBegin;
 }
Beispiel #12
0
    public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
    {
        applicationObject = (_DTE)application;
        addInInstance     = (AddIn)addInInst;

        // Add code for How-To.
        // Initialize all the variables that contain the events we're looking for.
        // Get the events object that contains information about all of the
        //   extensibility events.
        m_Events = ((DTE)(application)).Events;
        // Initialize a variable to track SolutionEvents
        m_SolutionEvents = m_Events.SolutionEvents;
        // Initialize a variable to track BuildEvents
        m_BuildEvents = m_Events.BuildEvents;

        m_BuildEvents.OnBuildBegin      += new _dispBuildEvents_OnBuildBeginEventHandler(m_BuildEvents_OnBuildBegin);
        m_SolutionEvents.AfterClosing   += new _dispSolutionEvents_AfterClosingEventHandler(m_SolutionEvents_AfterClosing);
        m_SolutionEvents.Opened         += new _dispSolutionEvents_OpenedEventHandler(m_SolutionEvents_Opened);
        m_SolutionEvents.ProjectAdded   += new _dispSolutionEvents_ProjectAddedEventHandler(m_SolutionEvents_ProjectAdded);
        m_SolutionEvents.ProjectRemoved += new _dispSolutionEvents_ProjectRemovedEventHandler(m_SolutionEvents_ProjectRemoved);
        m_SolutionEvents.ProjectRenamed += new _dispSolutionEvents_ProjectRenamedEventHandler(m_SolutionEvents_ProjectRenamed);
    }
 /// <summary>
 /// Registers handlers for the Activated and Closing events from the text window.
 /// </summary>
 public void AddWindowEvents()
 {
     _events = (EnvDTE80.Events2)_dte.Events;
     _windowsEvents = (EnvDTE.WindowEvents)_events.get_WindowEvents(null);
     _windowsEvents.WindowActivated += new EnvDTE._dispWindowEvents_WindowActivatedEventHandler(windowsEvents_WindowActivated);
     _windowsEvents.WindowClosing += new EnvDTE._dispWindowEvents_WindowClosingEventHandler(windowsEvents_WindowClosing);
 }
 /// <summary>
 /// Registers handlers for certain solution events.
 /// </summary>
 public void AddSolutionEvents()
 {
     _events = (EnvDTE80.Events2)_dte.Events;
     _solnEvents = (EnvDTE.SolutionEvents)_events.SolutionEvents;
     _solnEvents.QueryCloseSolution += new _dispSolutionEvents_QueryCloseSolutionEventHandler(solnEvents_QueryCloseSolution);
     _solnEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(solnEvents_Opened);
 }
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage);

            Instance = this;

            //var componentModel = (IComponentModel)GetService(typeof(SComponentModel));

            // Add our command handlers for menu (commands must exist in the .vsct file)

            if (await GetServiceAsync(typeof(IMenuCommandService)) is OleMenuCommandService menuCommandService)
            {
                // //var mainMenu = new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet, (int)PkgCmdIDList.CmdidMainMenu);
                // //var founded = menuCommandService.FindCommand(mainMenu);
                // //if (founded == null)
                // //{
                // //    var menuCommand2 = new OleMenuCommand(null, mainMenu);
                // //    menuCommandService.AddCommand(menuCommand2);
                // //    menuCommand2.BeforeQueryStatus += MenuCommand2_BeforeQueryStatus;
                // //    menuCommand2.Visible = false;
                // //}
                var menuCommand = new OleMenuCommand(CallWebFileToggle, new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet, (int)PkgCmdIDList.CmdidWebFileToggle));
                menuCommand.BeforeQueryStatus += MenuCommand_BeforeQueryStatus;

                menuCommandService.AddCommand(menuCommand);

                menuCommandService.AddCommand(new MenuCommand(CallFixtureFileToggle,
                                                              new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet,
                                                                            (int)PkgCmdIDList.CmdidFixtureFileToggle)));

                menuCommandService.AddCommand(new MenuCommand(CallFileFinder,
                                                              new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet,
                                                                            (int)PkgCmdIDList.CmdidFileFinder)));

                menuCommandService.AddCommand(new MenuCommand(CallMemberFinder,
                                                              new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet,
                                                                            (int)PkgCmdIDList.CmdidMemberFinder)));

                menuCommandService.AddCommand(new MenuCommand(CallCssFinder,
                                                              new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet,
                                                                            (int)PkgCmdIDList.CmdidCSSFinder)));

                menuCommandService.AddCommand(new MenuCommand(CallGotoNextFoundItem,
                                                              new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet,
                                                                            (int)PkgCmdIDList.CmdidGotoNextFoundItem)));

                menuCommandService.AddCommand(new MenuCommand(CallGotoPreviousFoundItem,
                                                              new CommandID(GuidList.GuidGeeksProductivityToolsCmdSet,
                                                                            (int)PkgCmdIDList.CmdidGotoPreviousFoundItem)));
            }

            SetCommandBindings();

            // Hook up event handlers
            events            = App.DTE.Events;
            docEvents         = events.DocumentEvents;
            solEvents         = events.SolutionEvents;
            solEvents.Opened += delegate { App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage); };

            // //ServiceCreatorCallback callback = new ServiceCreatorCallback(CreateService);

            // //((IServiceContainer)this).AddService(typeof(SMyService), callback);
        }
Beispiel #16
0
        /// <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)
        {
            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;

            OutputWindow outputWindow = (OutputWindow)_applicationObject.Windows.Item(Constants.vsWindowKindOutput).Object;

            bool bbuildok = true;

            try
            {
                m_OutputWindowPane = outputWindow.OutputWindowPanes.Item("生成");
            }
            catch
            {
                //我们试图查找“工具”一词的本地化版本,但未能找到。
                //  默认值为 en-US 单词,该值可能适用于当前区域性。
                bbuildok = false;
            }

            if (!bbuildok)
            {
                try
                {
                    m_OutputWindowPane = outputWindow.OutputWindowPanes.Item("Build");
                }
                catch
                {
                    //我们试图查找“工具”一词的本地化版本,但未能找到。
                    //  默认值为 en-US 单词,该值可能适用于当前区域性。
                    bbuildok = false;
                }
            }


            // Register for the various build events taht we're hooking in to
            EnvDTE.Events events = _applicationObject.Events;
            m_BuildEvents = (EnvDTE.BuildEvents)events.BuildEvents;
            m_BuildEvents.OnBuildProjConfigBegin += new _dispBuildEvents_OnBuildProjConfigBeginEventHandler(OnBuildProjConfigBegin);
            m_BuildEvents.OnBuildProjConfigDone  += new _dispBuildEvents_OnBuildProjConfigDoneEventHandler(OnBuildProjConfigDone);
            m_BuildEvents.OnBuildBegin           += new _dispBuildEvents_OnBuildBeginEventHandler(this.OnBuildBegin);
            m_BuildEvents.OnBuildDone            += new _dispBuildEvents_OnBuildDoneEventHandler(this.OnBuildDone);

            m_envcfgs = new ThkEnvCfgs();
            if (m_envcfgs.LoadConfig())
            {
                ThkEnvConfig enc = m_envcfgs.GetCurEnvConfig();
                if (enc != null)
                {
                    //if (m_OutputWindowPane != null)
                    //{
                    //    m_OutputWindowPane.OutputString("现在开始自动设置配置信息中的环境变量\n");
                    //}

                    ThkEnvCfgItem[] encitems = enc.EnvConfigItems;
                    foreach (ThkEnvCfgItem ci in encitems)
                    {
                        if (ci.EnvCfgFlatform == null || ci.EnvCfgFlatform.Length == 0 || ci.EnvCfgFlatform == "全部" || ci.EnvCfgFlatform == "")
                        {
                            Environment.SetEnvironmentVariable(ci.EnvCfgItem, ci.EnvCfgValue, EnvironmentVariableTarget.Process);
                            //if (m_OutputWindowPane !=null)
                            //{
                            //    m_OutputWindowPane.OutputString(ci.EnvCfgItem + ":" + ci.EnvCfgValue+"\n");
                            //}
                        }
                    }
                }
                else
                {
                    MessageBox.Show("获取配置中的环境变量信息失败");
                }
            }
            else
            {
                MessageBox.Show("加载配置变量配置文件失败");
            }
            {
                string   path       = System.Environment.CurrentDirectory;
                Assembly myAssembly = Assembly.GetEntryAssembly();
                if (myAssembly == null)
                {
                    myAssembly = Assembly.GetExecutingAssembly();
                }
                if (myAssembly != null)
                {
                    path = myAssembly.Location;
                    DirectoryInfo dr = new DirectoryInfo(path);
                    path = dr.Parent.FullName;  //当前目录的上一级目录
                }
                Environment.SetEnvironmentVariable("THK_VS_ADDIN_PATH", path, EnvironmentVariableTarget.Process);
            }

            //debug
            ThkVCDirSet vcset = m_envcfgs.GetVCConfig();

            if (vcset != null && vcset.EnvConfigItems.Length < 2)
            {
                //vcset.AddVcConfig("VC6", @"D:\develop\VS60\VC98\", "");
                //vcset.AddVcConfig("VC2003", @"D:\develop\vs2002\Vc7\", "");
                //vcset.AddVcConfig("VC2003", @"D:\develop\vs2003\Vc7\", "");
                //vcset.AddVcConfig("VC2005", @"D:\develop\vs2005\Vc\", "");
                //vcset.AddVcConfig("VC2008", @"D:\develop\vs2008\Vc\", "");
                //vcset.AddVcConfig("VC2010", @"D:\develop\vs2010\Vc\", "");
                //vcset.AddVcConfig("VC2012", @"D:\develop\vs2012\Vc\", "");
                //vcset.AddVcConfig("VC2013", @"D:\develop\vs2013\Vc\", "");


                //m_envcfgs.SaveConfig();
            }
            //end of debug

            if (connectMode == ext_ConnectMode.ext_cm_CommandLine || connectMode == ext_ConnectMode.ext_cm_AfterStartup || connectMode == ext_ConnectMode.ext_cm_UISetup ||
                connectMode == ext_ConnectMode.ext_cm_Startup)
            {
                object[]  contextGUIDS = new object[] { };
                Commands2 commands     = (Commands2)_applicationObject.Commands;
                string    toolsMenuName;



                try
                {
                    //若要将此命令移动到另一个菜单,则将“工具”一词更改为此菜单的英文版。
                    //  此代码将获取区域性,将其追加到菜单名中,然后将此命令添加到该菜单中。
                    //  您会在此文件中看到全部顶级菜单的列表
                    //  CommandBar.resx.
                    string          resourceName;
                    ResourceManager resourceManager = new ResourceManager("ThkDevEnc.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);
                    if (toolsMenuName == null || toolsMenuName.Length == 0)
                    {
                        toolsMenuName = "工具";
                    }
                }
                catch
                {
                    //我们试图查找“工具”一词的本地化版本,但未能找到。
                    //  默认值为 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
                //////////////{
                //////////////    //将一个命令添加到 Commands 集合:
                //////////////    Command command = commands.AddNamedCommand2(_addInInstance, "ProUnlock", "解锁ProE插件", "Executes the command for ProUnlock", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                //////////////    //将对应于该命令的控件添加到“工具”菜单:
                //////////////    if ((command != null) && (toolsPopup != null))
                //////////////    {
                //////////////        command.AddControl(toolsPopup.CommandBar, 1);
                //////////////    }
                //////////////}
                //////////////catch (System.ArgumentException)
                //////////////{
                //////////////    //如果出现此异常,原因很可能是由于具有该名称的命令
                //////////////    //  已存在。如果确实如此,则无需重新创建此命令,并且
                //////////////    //  可以放心忽略此异常。
                //////////////}
                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "ProeAttach", "调试ProE", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }
                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "CatiaAttach", "调试Catia", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }

                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "DevEnvCfg", "森科开发环境", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }
                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "VCSet", "当前编译环境", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }

                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "UnAttach", "全部分离调试", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }


                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "CopyFile", "文件拷贝", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }
            }
        }
Beispiel #17
0
        /// ------------------------------------------------------------------------------------
        /// <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, Extensibility.ext_ConnectMode connectMode,
                                 object addInInst, ref System.Array custom)
        {
            try
            {
                CheckForUpdates();

                m_dte              = (DTE2)application;
                m_nantCommands     = new CmdHandler();
                m_nantCommands.DTE = m_dte;

                m_addInInstance = (AddIn)addInInst;

                EnvDTE.Events events       = DTE.Events;
                OutputWindow  outputWindow = (OutputWindow)DTE.Windows.Item(Constants.vsWindowKindOutput).Object;

                m_solutionEvents = (EnvDTE.SolutionEvents)events.SolutionEvents;

                // Get the commands of the Build group
                RegisterCommandHandler(882,                 // build solution
                                       new _dispCommandEvents_BeforeExecuteEventHandler(m_nantCommands.OnBuildSolution));
                RegisterCommandHandler(883,                 // rebuild solution
                                       new _dispCommandEvents_BeforeExecuteEventHandler(m_nantCommands.OnBuildSolution));
                RegisterCommandHandler(886,                 // build project
                                       new _dispCommandEvents_BeforeExecuteEventHandler(m_nantCommands.OnBuildProject));
                RegisterCommandHandler(887,                 // rebuild project
                                       new _dispCommandEvents_BeforeExecuteEventHandler(m_nantCommands.OnBuildProject));
                RegisterCommandHandler(890,                 // Build Cancel
                                       new _dispCommandEvents_BeforeExecuteEventHandler(m_nantCommands.OnBuildCancel));
                RegisterCommandHandler(892,                 // build project (from context menu)
                                       new _dispCommandEvents_BeforeExecuteEventHandler(m_nantCommands.OnBuildProject));
                RegisterCommandHandler(893,                 // rebuild project (from context menu)
                                       new _dispCommandEvents_BeforeExecuteEventHandler(m_nantCommands.OnBuildProject));
                // 979-988 build project (from menu when no project item is selected)
                // 989-998 rebuild project (from menu when no project item is selected)
                for (int i = 979; i < 999; i++)
                {
                    RegisterCommandHandler(i,
                                           new _dispCommandEvents_BeforeExecuteEventHandler(m_nantCommands.OnBuildProject));
                }
                RegisterCommandHandler(295,                 // Debug Start
                                       new _dispCommandEvents_BeforeExecuteEventHandler(m_nantCommands.OnDebugStart));
                RegisterCommandHandler(356,                 // Debug/Start new instance (from context menu)
                                       new _dispCommandEvents_BeforeExecuteEventHandler(m_nantCommands.OnDebugStart));
                RegisterCommandHandler(368,                 // Debug Start without debugging
                                       new _dispCommandEvents_BeforeExecuteEventHandler(m_nantCommands.OnDebugStartWithoutDebugging));
//				RegisterCommandHandler(248, // Debug Step into
//					new _dispCommandEvents_BeforeExecuteEventHandler(m_nantCommands.OnDebugStepInto));
//				RegisterCommandHandler(357, // Debug Step into (from context menu)
//					new _dispCommandEvents_BeforeExecuteEventHandler(m_nantCommands.OnDebugStepInto));
//				RegisterCommandHandler(249, // Debug Step over
//					new _dispCommandEvents_BeforeExecuteEventHandler(m_nantCommands.OnDebugStepOver));
//				RegisterCommandHandler(251, // Debug Run to cursor
//					new _dispCommandEvents_BeforeExecuteEventHandler(m_nantCommands.OnDebugRunToCursor));
                // TODO: need to handle 891 Batch build!
                m_buildEvents = (EnvDTE.BuildEvents)events.BuildEvents;

                m_solutionEvents.Opened       += new _dispSolutionEvents_OpenedEventHandler(Opened);
                m_solutionEvents.ProjectAdded += new _dispSolutionEvents_ProjectAddedEventHandler(OnProjectAdded);
                m_buildEvents.OnBuildBegin    += new _dispBuildEvents_OnBuildBeginEventHandler(OnBuildBegin);

                // try to add the commands
                AddToolbar();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Got exception: " + e.Message);
            }
        }
        public void Attach(_DTE app)
        {
            applicationObject = app;

            EnvDTE.Events events       = applicationObject.Events;
            OutputWindow  outputWindow = (OutputWindow)applicationObject.Windows.Item(Constants.vsWindowKindOutput).Object;


            //IObjectExplorerService objectExplorer = ServiceCache.GetObjectExplorer();
            //var provider = (IObjectExplorerEventProvider)objectExplorer.GetService(typeof(IObjectExplorerEventProvider));

            //provider.SelectionChanged += new NodesChangedEventHandler(provider_SelectionChanged);

            _outputWindowPane = outputWindow.OutputWindowPanes.Add("DTE Event Information - C# Event Watcher");

            //Retrieve the event objects from the automation model
            _windowsEvents       = (EnvDTE.WindowEvents)events.get_WindowEvents(null);
            _textEditorEvents    = (EnvDTE.TextEditorEvents)events.get_TextEditorEvents(null);
            _taskListEvents      = (EnvDTE.TaskListEvents)events.get_TaskListEvents("");
            _solutionEvents      = (EnvDTE.SolutionEvents)events.SolutionEvents;
            _selectionEvents     = (EnvDTE.SelectionEvents)events.SelectionEvents;
            _outputWindowEvents  = (EnvDTE.OutputWindowEvents)events.get_OutputWindowEvents("");
            _findEvents          = (EnvDTE.FindEvents)events.FindEvents;
            _dteEvents           = (EnvDTE.DTEEvents)events.DTEEvents;
            _documentEvents      = (EnvDTE.DocumentEvents)events.get_DocumentEvents(null);
            _debuggerEvents      = (EnvDTE.DebuggerEvents)events.DebuggerEvents;
            _commandEvents       = (EnvDTE.CommandEvents)events.get_CommandEvents("{00000000-0000-0000-0000-000000000000}", 0);
            _buildEvents         = (EnvDTE.BuildEvents)events.BuildEvents;
            _miscFilesEvents     = (EnvDTE.ProjectItemsEvents)events.MiscFilesEvents;
            _solutionItemsEvents = (EnvDTE.ProjectItemsEvents)events.SolutionItemsEvents;

            _globalProjectItemsEvents           = ((EnvDTE80.Events2)events).ProjectItemsEvents;
            _globalProjectsEvents               = ((EnvDTE80.Events2)events).ProjectsEvents;
            _textDocumentKeyPressEvents         = ((EnvDTE80.Events2)events).get_TextDocumentKeyPressEvents(null);
            _codeModelEvents                    = ((EnvDTE80.Events2)events).get_CodeModelEvents(null);
            _windowVisibilityEvents             = ((EnvDTE80.Events2)events).get_WindowVisibilityEvents(null);
            _debuggerProcessEvents              = ((EnvDTE80.Events2)events).DebuggerProcessEvents;
            _debuggerExpressionEvaluationEvents = ((EnvDTE80.Events2)events).DebuggerExpressionEvaluationEvents;
            _publishEvents = ((EnvDTE80.Events2)events).PublishEvents;

            //Connect to each delegate exposed from each object retrieved above
            _windowsEvents.WindowActivated     += new _dispWindowEvents_WindowActivatedEventHandler(this.WindowActivated);
            _windowsEvents.WindowClosing       += new _dispWindowEvents_WindowClosingEventHandler(this.WindowClosing);
            _windowsEvents.WindowCreated       += new _dispWindowEvents_WindowCreatedEventHandler(this.WindowCreated);
            _windowsEvents.WindowMoved         += new _dispWindowEvents_WindowMovedEventHandler(this.WindowMoved);
            _textEditorEvents.LineChanged      += new _dispTextEditorEvents_LineChangedEventHandler(this.LineChanged);
            _taskListEvents.TaskAdded          += new _dispTaskListEvents_TaskAddedEventHandler(this.TaskAdded);
            _taskListEvents.TaskModified       += new _dispTaskListEvents_TaskModifiedEventHandler(this.TaskModified);
            _taskListEvents.TaskNavigated      += new _dispTaskListEvents_TaskNavigatedEventHandler(this.TaskNavigated);
            _taskListEvents.TaskRemoved        += new _dispTaskListEvents_TaskRemovedEventHandler(this.TaskRemoved);
            _solutionEvents.AfterClosing       += new _dispSolutionEvents_AfterClosingEventHandler(this.AfterClosing);
            _solutionEvents.BeforeClosing      += new _dispSolutionEvents_BeforeClosingEventHandler(this.BeforeClosing);
            _solutionEvents.Opened             += new _dispSolutionEvents_OpenedEventHandler(this.Opened);
            _solutionEvents.ProjectAdded       += new _dispSolutionEvents_ProjectAddedEventHandler(this.ProjectAdded);
            _solutionEvents.ProjectRemoved     += new _dispSolutionEvents_ProjectRemovedEventHandler(this.ProjectRemoved);
            _solutionEvents.ProjectRenamed     += new _dispSolutionEvents_ProjectRenamedEventHandler(this.ProjectRenamed);
            _solutionEvents.QueryCloseSolution += new _dispSolutionEvents_QueryCloseSolutionEventHandler(this.QueryCloseSolution);
            _solutionEvents.Renamed            += new _dispSolutionEvents_RenamedEventHandler(this.Renamed);
            _selectionEvents.OnChange          += new _dispSelectionEvents_OnChangeEventHandler(this.OnChange);
            _outputWindowEvents.PaneAdded      += new _dispOutputWindowEvents_PaneAddedEventHandler(this.PaneAdded);
            _outputWindowEvents.PaneClearing   += new _dispOutputWindowEvents_PaneClearingEventHandler(this.PaneClearing);
            _outputWindowEvents.PaneUpdated    += new _dispOutputWindowEvents_PaneUpdatedEventHandler(this.PaneUpdated);
            _findEvents.FindDone                       += new _dispFindEvents_FindDoneEventHandler(this.FindDone);
            _dteEvents.ModeChanged                     += new _dispDTEEvents_ModeChangedEventHandler(this.ModeChanged);
            _dteEvents.OnBeginShutdown                 += new _dispDTEEvents_OnBeginShutdownEventHandler(this.OnBeginShutdown);
            _dteEvents.OnMacrosRuntimeReset            += new _dispDTEEvents_OnMacrosRuntimeResetEventHandler(this.OnMacrosRuntimeReset);
            _dteEvents.OnStartupComplete               += new _dispDTEEvents_OnStartupCompleteEventHandler(this.OnStartupComplete);
            _documentEvents.DocumentClosing            += new _dispDocumentEvents_DocumentClosingEventHandler(this.DocumentClosing);
            _documentEvents.DocumentOpened             += new _dispDocumentEvents_DocumentOpenedEventHandler(this.DocumentOpened);
            _documentEvents.DocumentOpening            += new _dispDocumentEvents_DocumentOpeningEventHandler(this.DocumentOpening);
            _documentEvents.DocumentSaved              += new _dispDocumentEvents_DocumentSavedEventHandler(this.DocumentSaved);
            _debuggerEvents.OnContextChanged           += new _dispDebuggerEvents_OnContextChangedEventHandler(this.OnContextChanged);
            _debuggerEvents.OnEnterBreakMode           += new _dispDebuggerEvents_OnEnterBreakModeEventHandler(this.OnEnterBreakMode);
            _debuggerEvents.OnEnterDesignMode          += new _dispDebuggerEvents_OnEnterDesignModeEventHandler(this.OnEnterDesignMode);
            _debuggerEvents.OnEnterRunMode             += new _dispDebuggerEvents_OnEnterRunModeEventHandler(this.OnEnterRunMode);
            _debuggerEvents.OnExceptionNotHandled      += new _dispDebuggerEvents_OnExceptionNotHandledEventHandler(this.OnExceptionNotHandled);
            _debuggerEvents.OnExceptionThrown          += new _dispDebuggerEvents_OnExceptionThrownEventHandler(this.OnExceptionThrown);
            _commandEvents.AfterExecute                += new _dispCommandEvents_AfterExecuteEventHandler(this.AfterExecute);
            _commandEvents.BeforeExecute               += new _dispCommandEvents_BeforeExecuteEventHandler(this.BeforeExecute);
            _buildEvents.OnBuildBegin                  += new _dispBuildEvents_OnBuildBeginEventHandler(this.OnBuildBegin);
            _buildEvents.OnBuildDone                   += new _dispBuildEvents_OnBuildDoneEventHandler(this.OnBuildDone);
            _buildEvents.OnBuildProjConfigBegin        += new _dispBuildEvents_OnBuildProjConfigBeginEventHandler(this.OnBuildProjConfigBegin);
            _buildEvents.OnBuildProjConfigDone         += new _dispBuildEvents_OnBuildProjConfigDoneEventHandler(this.OnBuildProjConfigDone);
            _miscFilesEvents.ItemAdded                 += new _dispProjectItemsEvents_ItemAddedEventHandler(this.MiscFilesEvents_ItemAdded);
            _miscFilesEvents.ItemRemoved               += new _dispProjectItemsEvents_ItemRemovedEventHandler(this.MiscFilesEvents_ItemRemoved);
            _miscFilesEvents.ItemRenamed               += new _dispProjectItemsEvents_ItemRenamedEventHandler(this.MiscFilesEvents_ItemRenamed);
            _solutionItemsEvents.ItemAdded             += new _dispProjectItemsEvents_ItemAddedEventHandler(this.SolutionItemsEvents_ItemAdded);
            _solutionItemsEvents.ItemRemoved           += new _dispProjectItemsEvents_ItemRemovedEventHandler(this.SolutionItemsEvents_ItemRemoved);
            _solutionItemsEvents.ItemRenamed           += new _dispProjectItemsEvents_ItemRenamedEventHandler(this.SolutionItemsEvents_ItemRenamed);
            _globalProjectItemsEvents.ItemAdded        += new _dispProjectItemsEvents_ItemAddedEventHandler(GlobalProjectItemsEvents_ItemAdded);
            _globalProjectItemsEvents.ItemRemoved      += new _dispProjectItemsEvents_ItemRemovedEventHandler(GlobalProjectItemsEvents_ItemRemoved);
            _globalProjectItemsEvents.ItemRenamed      += new _dispProjectItemsEvents_ItemRenamedEventHandler(GlobalProjectItemsEvents_ItemRenamed);
            _globalProjectsEvents.ItemAdded            += new _dispProjectsEvents_ItemAddedEventHandler(GlobalProjectsEvents_ItemAdded);
            _globalProjectsEvents.ItemRemoved          += new _dispProjectsEvents_ItemRemovedEventHandler(GlobalProjectsEvents_ItemRemoved);
            _globalProjectsEvents.ItemRenamed          += new _dispProjectsEvents_ItemRenamedEventHandler(GlobalProjectsEvents_ItemRenamed);
            _textDocumentKeyPressEvents.AfterKeyPress  += new _dispTextDocumentKeyPressEvents_AfterKeyPressEventHandler(AfterKeyPress);
            _textDocumentKeyPressEvents.BeforeKeyPress += new _dispTextDocumentKeyPressEvents_BeforeKeyPressEventHandler(BeforeKeyPress);
            _codeModelEvents.ElementAdded              += new _dispCodeModelEvents_ElementAddedEventHandler(ElementAdded);
            _codeModelEvents.ElementChanged            += new _dispCodeModelEvents_ElementChangedEventHandler(ElementChanged);
            _codeModelEvents.ElementDeleted            += new _dispCodeModelEvents_ElementDeletedEventHandler(ElementDeleted);
            _windowVisibilityEvents.WindowHiding       += new _dispWindowVisibilityEvents_WindowHidingEventHandler(WindowHiding);
            _windowVisibilityEvents.WindowShowing      += new _dispWindowVisibilityEvents_WindowShowingEventHandler(WindowShowing);
            _debuggerExpressionEvaluationEvents.OnExpressionEvaluation += new _dispDebuggerExpressionEvaluationEvents_OnExpressionEvaluationEventHandler(OnExpressionEvaluation);
            _debuggerProcessEvents.OnProcessStateChanged += new _dispDebuggerProcessEvents_OnProcessStateChangedEventHandler(OnProcessStateChanged);
            _publishEvents.OnPublishBegin += new _dispPublishEvents_OnPublishBeginEventHandler(OnPublishBegin);
            _publishEvents.OnPublishDone  += new _dispPublishEvents_OnPublishDoneEventHandler(OnPublishDone);
        }
Beispiel #19
0
        /// <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, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
        {
            Mfconsulting.Vsprj2make.RegistryHelper regHlpr = new RegistryHelper();
            string [] monoVersions = null;

            try
            {
                monoVersions = regHlpr.GetMonoVersions();
            }
            catch (Exception exc)
            {
                // Mono may not be installed
                MessageBox.Show(exc.Message, "Prj2make Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;                 // Pull the cord and discontinue loading the add-in
            }

            applicationObject = (_DTE)application;
            addInInstance     = (AddIn)addInInst;
            int selectedIndexForComboBox = 1;

            EnvDTE.Events events       = applicationObject.Events;
            OutputWindow  outputWindow = (OutputWindow)applicationObject.Windows.Item(Constants.vsWindowKindOutput).Object;

            outputWindowPane = outputWindow.OutputWindowPanes.Add("Prj2Make Messages");

            object []    contextGUIDS = new object[] { };
            Commands     commands     = applicationObject.Commands;
            _CommandBars commandBars  = applicationObject.CommandBars;
            CommandBar   cmdBarMonoBarra;

            CommandBar      commandBar = (CommandBar)commandBars["Tools"];
            CommandBarPopup popMenu;                    // Prj2Make popupmenu
            CommandBarPopup popMenu2;                   // Explorer Current Project

            // Creates a more legible representation of the
            // command bar control collection contained in
            // the Tools command bar
            CommandBarControls commandBarControls;

            commandBarControls = commandBar.Controls;

            // Create Makefile
            Command command1 = null;
            // Generate MonoDevelop files
            Command command2 = null;
            // Import MonoDevelop Solutions
            Command command3 = null;
            // Run on Mono
            Command command5 = null;
            // vsprj2make Options
            Command command6 = null;
            // Generate a distribution unit
            Command command7 = null;
            // Explore current solution
            Command command8 = null;
            // Explore current Project
            Command command9 = null;


            // ------------- Add Pop-up menu ----------------
            popMenu2 = (CommandBarPopup)commandBarControls.Add(
                MsoControlType.msoControlPopup,
                System.Reflection.Missing.Value, // Object ID
                System.Reflection.Missing.Value, // Object parameters
                1,                               // Object before
                true);

            popMenu2.Caption = "&Windows Explore";

            // ------------- Add Pop-up menu ----------------
            popMenu = (CommandBarPopup)commandBarControls.Add(
                MsoControlType.msoControlPopup,
                System.Reflection.Missing.Value, // Object ID
                System.Reflection.Missing.Value, // Object parameters
                1,                               // Object before
                true);

            popMenu.Caption = "Prj&2Make";

            // Add the create makefile command -- command1
            command1 = CreateNamedCommand(
                addInInstance,
                commands,
                "CreateMake",
                "Create &Makefile",
                "Generate Makefile",
                ref contextGUIDS
                );

            if (command1 == null)
            {
                command1 = GetExistingNamedCommand(commands, "vsprj2make.Connect.CreateMake");
            }

            try
            {
                command1.AddControl(popMenu.CommandBar, 1);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Add the generate a dist unit command -- command7
            command7 = CreateNamedCommand(
                addInInstance,
                commands,
                "GenDistUnit",
                "Generate Distribution &Unit",
                "Generates a distribution unit (zip file)",
                ref contextGUIDS
                );

            if (command7 == null)
            {
                command7 = GetExistingNamedCommand(commands, "vsprj2make.Connect.GenDistUnit");
            }

            try
            {
                command7.AddControl(popMenu.CommandBar, 2);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Add the GenMDFiles command -- command2
            command2 = CreateNamedCommand(
                addInInstance,
                commands,
                "GenMDFiles",
                "Create Mono&Develop Solution",
                "Generate MonoDevelop Solution",
                ref contextGUIDS
                );

            if (command2 == null)
            {
                command2 = GetExistingNamedCommand(commands, "vsprj2make.Connect.GenMDFiles");
            }

            try
            {
                command2.AddControl(popMenu.CommandBar, 3);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Add the PrjxToCsproj command -- command3
            command3 = CreateNamedCommand(
                addInInstance,
                commands,
                "PrjxToCsproj",
                "&Import MonoDevelop Solution...",
                "Imports a MonoDevelop Solution",
                ref contextGUIDS
                );

            if (command3 == null)
            {
                command3 = GetExistingNamedCommand(commands, "vsprj2make.Connect.PrjxToCsproj");
            }

            try
            {
                command3.AddControl(popMenu.CommandBar, 4);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Add the Ron on Mono command -- command5
            command5 = CreateNamedCommand(
                addInInstance,
                commands,
                "RunOnMono",
                "&Run on Mono",
                "Run solution on mono",
                ref contextGUIDS
                );

            if (command5 == null)
            {
                command5 = GetExistingNamedCommand(commands, "vsprj2make.Connect.RunOnMono");
            }

            try
            {
                command5.AddControl(popMenu.CommandBar, 5);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Add the Options command -- command6
            command6 = CreateNamedCommand(
                addInInstance,
                commands,
                "Options",
                "&Options...",
                "Options for prj2make Add-in",
                ref contextGUIDS
                );

            if (command6 == null)
            {
                command6 = GetExistingNamedCommand(commands, "vsprj2make.Connect.Options");
            }

            try
            {
                command6.AddControl(popMenu.CommandBar, 6);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Add the ExploreCurrSln command -- command8
            command8 = CreateNamedCommand(
                addInInstance,
                commands,
                "ExploreCurrSln",
                "Current &Solution",
                "Explore the current solution",
                ref contextGUIDS
                );

            if (command8 == null)
            {
                command8 = GetExistingNamedCommand(commands, "vsprj2make.Connect.ExploreCurrSln");
            }

            try
            {
                command8.AddControl(popMenu2.CommandBar, 1);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Add the ExploreCurrDoc command -- command9
            command9 = CreateNamedCommand(
                addInInstance,
                commands,
                "ExploreCurrDoc",
                "Current &Document",
                "Explore the current Document",
                ref contextGUIDS
                );

            if (command9 == null)
            {
                command9 = GetExistingNamedCommand(commands, "vsprj2make.Connect.ExploreCurrDoc");
            }

            try
            {
                command9.AddControl(popMenu2.CommandBar, 2);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Mono Toolbar
            CommandBar cmdBarBuild = (CommandBar)commandBars["Build"];

            try
            {
                cmdBarMonoBarra = (CommandBar)commandBars["MonoBarra"];
            }
            catch (Exception)
            {
                commands.AddCommandBar("MonoBarra",
                                       vsCommandBarType.vsCommandBarTypeToolbar,
                                       cmdBarBuild,
                                       1
                                       );

                cmdBarMonoBarra         = (CommandBar)commandBars["MonoBarra"];
                cmdBarMonoBarra.Visible = true;
            }

            if (testInMonoCommandBarButton == null)
            {
                // Create the Ron on Mono Button
                testInMonoCommandBarButton = (CommandBarButton)cmdBarMonoBarra.Controls.Add(
                    Microsoft.Office.Core.MsoControlType.msoControlButton,
                    System.Reflection.Missing.Value,
                    System.Reflection.Missing.Value,
                    1,
                    false
                    );

                testInMonoCommandBarButton.Caption         = "Run on &Mono";
                testInMonoCommandBarButton.DescriptionText = "Run solution with the mono runtime";
                testInMonoCommandBarButton.TooltipText     = "Run on mono";
                testInMonoCommandBarButton.ShortcutText    = "Run on &Mono";
                testInMonoCommandBarButton.Style           = MsoButtonStyle.msoButtonCaption;
                testInMonoCommandBarButton.Click          += new _CommandBarButtonEvents_ClickEventHandler(testInMonoCommandBarButton_Click);
            }

            if (versionComboBox == null)
            {
                // Create the combobox
                versionComboBox = (CommandBarComboBox)cmdBarMonoBarra.Controls.Add(
                    Microsoft.Office.Core.MsoControlType.msoControlDropdown,
                    System.Reflection.Missing.Value,
                    System.Reflection.Missing.Value,
                    2,
                    false
                    );

                for (int i = 0; i < monoVersions.Length; i++)
                {
                    versionComboBox.AddItem(monoVersions[i], i + 1);
                    if (monoVersions[i].CompareTo(regHlpr.GetDefaultClr()) == 0)
                    {
                        selectedIndexForComboBox = i + 1;
                    }
                }

                versionComboBox.Change += new _CommandBarComboBoxEvents_ChangeEventHandler(versionComboBox_Change);

                // Select the active index based on
                // the current mono version
                versionComboBox.ListIndex = selectedIndexForComboBox;
            }
        }