Example #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);
        }
Example #2
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;
 }
Example #3
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);
 }
Example #4
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;
 }
Example #5
0
        public Watcher()
        {
            if (Instance.Solution != null)
            {
                Instance.Solution.AdviseSolutionEvents(this, out mSolutionCookie);
            }

            mDocumentEvents = Instance.DTE2.Events.DocumentEvents;
            mDocumentEvents.DocumentSaved += OnDocumentSaved;

            mSolutionItemsEvents              = Instance.DTE2.Events.SolutionItemsEvents;
            mSolutionItemsEvents.ItemAdded   += OnItemAdded;
            mSolutionItemsEvents.ItemRemoved += OnItemRemoved;
        }
Example #6
0
        public AddInEventHandler(DTE _dte)
        {
            simpleThreadMessenger = new SimpleThreadMessenger(this);
            dte = _dte;
            var events = dte.Events as Events;

            buildEvents = (EnvDTE.BuildEvents)events.BuildEvents;
            buildEvents.OnBuildBegin           += new _dispBuildEvents_OnBuildBeginEventHandler(buildEvents_OnBuildBegin);
            buildEvents.OnBuildProjConfigBegin += new _dispBuildEvents_OnBuildProjConfigBeginEventHandler(this.OnBuildProjConfigBegin);
            buildEvents.OnBuildDone            += new _dispBuildEvents_OnBuildDoneEventHandler(this.buildEvents_OnBuildDone);

            documentEvents = (EnvDTE.DocumentEvents)events.get_DocumentEvents(null);
            documentEvents.DocumentSaved += new _dispDocumentEvents_DocumentSavedEventHandler(this.DocumentSaved);

            projectItemsEvents              = events.SolutionItemsEvents;
            projectItemsEvents.ItemAdded   += new _dispProjectItemsEvents_ItemAddedEventHandler(this.ProjectItemsEvents_ItemAdded);
            projectItemsEvents.ItemRemoved += new _dispProjectItemsEvents_ItemRemovedEventHandler(this.ProjectItemsEvents_ItemRemoved);
            projectItemsEvents.ItemRenamed += new _dispProjectItemsEvents_ItemRenamedEventHandler(this.ProjectItemsEvents_ItemRenamed);

            solutionEvents = (SolutionEvents)events.SolutionEvents;
            solutionEvents.ProjectAdded   += new _dispSolutionEvents_ProjectAddedEventHandler(this.SolutionEvents_ProjectAdded);
            solutionEvents.ProjectRemoved += new _dispSolutionEvents_ProjectRemovedEventHandler(this.SolutionEvents_ProjectRemoved);
            solutionEvents.Opened         += new _dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened);
            solutionEvents.AfterClosing   += new _dispSolutionEvents_AfterClosingEventHandler(SolutionEvents_AfterClosing);

            const string debugCommandsGUID = "{5EFC7975-14BC-11CF-9B2B-00AA00573819}";

            debugStartEvents = events.get_CommandEvents(debugCommandsGUID, 295);
            debugStartEvents.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(debugStartEvents_BeforeExecute);

            debugStartWithoutDebuggingEvents = events.get_CommandEvents(debugCommandsGUID, 368);
            debugStartWithoutDebuggingEvents.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(debugStartWithoutDebuggingEvents_BeforeExecute);

            dispId_VCFileConfiguration_ExcludedFromBuild         = GetPropertyDispId(typeof(VCFileConfiguration), "ExcludedFromBuild");
            dispId_VCCLCompilerTool_UsePrecompiledHeader         = GetPropertyDispId(typeof(VCCLCompilerTool), "UsePrecompiledHeader");
            dispId_VCCLCompilerTool_PrecompiledHeaderThrough     = GetPropertyDispId(typeof(VCCLCompilerTool), "PrecompiledHeaderThrough");
            dispId_VCCLCompilerTool_PreprocessorDefinitions      = GetPropertyDispId(typeof(VCCLCompilerTool), "PreprocessorDefinitions");
            dispId_VCCLCompilerTool_AdditionalIncludeDirectories = GetPropertyDispId(typeof(VCCLCompilerTool), "AdditionalIncludeDirectories");
            RegisterVCProjectEngineEvents();

            appWrapperProcess = new System.Diagnostics.Process();
            appWrapperProcess.StartInfo.FileName = VSPackage.appWrapperPath;
            appWrapperThread      = new System.Threading.Thread(new System.Threading.ThreadStart(ListenForRequests));
            appWrapperThread.Name = "QtAppWrapperListener";
            appWrapperThread.Start();
        }
Example #7
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView textView = editorFactory.GetWpfTextView(textViewAdapter);

            if (textView == null)
            {
                return;
            }

            AddCommandFilter(textViewAdapter, new KeyBindingCommandFilter(textView));

            // add Document saved event
            DTE dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE));

            events         = (Events)dte.Events;
            documentEvents = events.DocumentEvents;
            documentEvents.DocumentSaved += DocumentSaved;
        }
Example #8
0
        public CodeBeautifierEventHandler(IServiceProvider serviceProvider)
        {
            m_serviceProvider    = serviceProvider;
            m_hApplicationObject = serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2;

            m_settings.onOptionsChanged += new EventHandler(onConfigurationChanged);
            onConfigurationChanged(this, null);

            Command hCmdBuildSolution      = m_hApplicationObject.Commands.Item("Build.BuildSolution", 0);
            Command hCmdRebuildSolution    = m_hApplicationObject.Commands.Item("Build.RebuildSolution", 0);
            Command hCmdBuildOnlyProject   = m_hApplicationObject.Commands.Item("Build.BuildOnlyProject", 0);
            Command hCmdRebuildOnlyProject = m_hApplicationObject.Commands.Item("Build.RebuildOnlyProject", 0);

            Command hCmdBuildSelection   = m_hApplicationObject.Commands.Item("Build.BuildSelection", 886);
            Command hCmdRebuildSelection = m_hApplicationObject.Commands.Item("Build.RebuildSelection", 887);

            // BuildSolution
            m_hEventOnBuildSolution = m_hApplicationObject.Events.CommandEvents[hCmdBuildSolution.Guid, hCmdBuildSolution.ID] as CommandEvents;
            m_hEventOnBuildSolution.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(OnBuildSolution);

            m_hEventOnRebuildSolution = m_hApplicationObject.Events.CommandEvents[hCmdRebuildSolution.Guid, hCmdRebuildSolution.ID] as CommandEvents;
            m_hEventOnRebuildSolution.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(OnReBuildSolution);

            m_hEventOnBuildOnlyProject = m_hApplicationObject.Events.CommandEvents[hCmdBuildOnlyProject.Guid, hCmdBuildOnlyProject.ID] as CommandEvents;
            m_hEventOnBuildOnlyProject.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(OnBuildProject);

            m_hEventOnRebuildOnlyProject = m_hApplicationObject.Events.CommandEvents[hCmdRebuildOnlyProject.Guid, hCmdRebuildOnlyProject.ID] as CommandEvents;
            m_hEventOnRebuildOnlyProject.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(OnReBuildProject);


            m_hEventOnBuildSelected = m_hApplicationObject.Events.CommandEvents[hCmdBuildSelection.Guid, hCmdBuildSelection.ID] as CommandEvents;
            m_hEventOnBuildSelected.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(OnBuildProject);

            m_hEventOnRebuildSelected = m_hApplicationObject.Events.CommandEvents[hCmdRebuildSelection.Guid, hCmdRebuildSelection.ID] as CommandEvents;
            m_hEventOnRebuildSelected.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(OnReBuildProject);

            EnvDTE80.Events2 dteEvents2 = m_hApplicationObject.Events as EnvDTE80.Events2;
            m_textDocumentEvents = dteEvents2.get_TextDocumentKeyPressEvents();
            m_textDocumentEvents.AfterKeyPress += onTextDocumentKeyPressed;

            m_documentEvents = dteEvents2.get_DocumentEvents();
            m_documentEvents.DocumentSaved += onDocumentSaved;
        }
Example #9
0
        public void DetachFileEventListeners()
        {
            try
            {
                //IVsHierarchyEvents
                // ((Events2)dte.Events).SolutionEvents.

                projItemsEvents              = (EnvDTE.ProjectItemsEvents) this.DTE.Events.GetObject("CSharpProjectItemsEvents");
                projItemsEvents.ItemAdded   -= ProjItemAdded;
                projItemsEvents.ItemRemoved -= ProjItemRemoved;
                projItemsEvents.ItemRenamed -= ProjItemRenamed;

                docEvents = (EnvDTE.DocumentEvents) this.DTE.Events.DocumentEvents;
                docEvents.DocumentSaved -= DocEventsDocSaved;
            }
            catch (System.Exception ex)
            {
                LogService.Exception("Error unregistering file event handlers", ex);
            }
        }
        /// <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()
        {
            _instance = this;
            _dte      = GetService(typeof(DTE)) as DTE2;
            Package   = this;
            EnvDTE80.Events2 events = _dte.Events as Events2;
            Helper.Logger.Initialize(this, "NFinalCompiler");
            _documentEvents = events.DocumentEvents;
            _solutionEvents = events.SolutionEvents;
            events.BuildEvents.OnBuildBegin          += BuildEvents_OnBuildBegin;
            events.BuildEvents.OnBuildDone           += BuildEvents_OnBuildDone;
            events.BuildEvents.OnBuildProjConfigDone += BuildEvents_OnBuildProjConfigDone;
            _documentEvents.DocumentSaved            += DocumentEvents_DocumentSaved;
            _solutionEvents.AfterClosing             += _solutionEvents_AfterClosing;
            _solutionEvents.ProjectRemoved           += _solutionEvents_ProjectRemoved;

            componentModel =
                (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel));

            base.Initialize();
        }
Example #11
0
        private void LoadPluginFunction()
        {
            object[]  contextGUIDS = new object[] { };
            Commands2 commands     = (Commands2)_applicationObject.Commands;

            //将此命令置于“工具”菜单上。
            //查找 MenuBar 命令栏,该命令栏是容纳所有主菜单项的顶级命令栏:
            Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];

            //在 MenuBar 命令栏上查找“工具”命令栏:
            CommandBarControl toolsControl = menuBarCommandBar.Controls["工具"];
            CommandBarPopup   toolsPopup   = (CommandBarPopup)toolsControl;

            //如果希望添加多个由您的外接程序处理的命令,可以重复此 try/catch 块,
            //  只需确保更新 QueryStatus/Exec 方法,使其包含新的命令名。
            try
            {
                //将一个命令添加到 Commands 集合:
                MenubarCommand = commands.AddNamedCommand2(_addInInstance, "FileModifyRecorder", "文件修改记录...", "显示文件修改记录", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

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


            docEvents = (EnvDTE.DocumentEvents)_applicationObject.Events.get_DocumentEvents(null);
            docEvents.DocumentSaved -= saveHandler;
            docEvents.DocumentSaved += saveHandler;
            Loaded = true;
            OutPutLogToStatusBar(" 文件记录模块加载完毕", true);
        }
        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);
        }
Example #13
0
        public AddInEventHandler(DTE _dte)
        {
            simpleThreadMessenger = new SimpleThreadMessenger(this);
            dte = _dte;
            Events2 events = dte.Events as Events2;

            buildEvents = (EnvDTE.BuildEvents)events.BuildEvents;
            buildEvents.OnBuildBegin += new _dispBuildEvents_OnBuildBeginEventHandler(buildEvents_OnBuildBegin);
            buildEvents.OnBuildProjConfigBegin += new _dispBuildEvents_OnBuildProjConfigBeginEventHandler(this.OnBuildProjConfigBegin);
            buildEvents.OnBuildDone += new _dispBuildEvents_OnBuildDoneEventHandler(this.buildEvents_OnBuildDone);

            documentEvents = (EnvDTE.DocumentEvents)events.get_DocumentEvents(null);
            documentEvents.DocumentSaved += new _dispDocumentEvents_DocumentSavedEventHandler(this.DocumentSaved);

            projectItemsEvents = (ProjectItemsEvents)events.ProjectItemsEvents;
            projectItemsEvents.ItemAdded += new _dispProjectItemsEvents_ItemAddedEventHandler(this.ProjectItemsEvents_ItemAdded);
            projectItemsEvents.ItemRemoved += new _dispProjectItemsEvents_ItemRemovedEventHandler(this.ProjectItemsEvents_ItemRemoved);
            projectItemsEvents.ItemRenamed += new _dispProjectItemsEvents_ItemRenamedEventHandler(this.ProjectItemsEvents_ItemRenamed);

            solutionEvents = (SolutionEvents)events.SolutionEvents;
            solutionEvents.ProjectAdded += new _dispSolutionEvents_ProjectAddedEventHandler(this.SolutionEvents_ProjectAdded);
            solutionEvents.ProjectRemoved += new _dispSolutionEvents_ProjectRemovedEventHandler(this.SolutionEvents_ProjectRemoved);
            solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened);
            solutionEvents.AfterClosing += new _dispSolutionEvents_AfterClosingEventHandler(SolutionEvents_AfterClosing);

            const string debugCommandsGUID = "{5EFC7975-14BC-11CF-9B2B-00AA00573819}";
            debugStartEvents = events.get_CommandEvents(debugCommandsGUID, 295);
            debugStartEvents.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(debugStartEvents_BeforeExecute);

            debugStartWithoutDebuggingEvents = events.get_CommandEvents(debugCommandsGUID, 368);
            debugStartWithoutDebuggingEvents.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(debugStartWithoutDebuggingEvents_BeforeExecute);

            dispId_VCFileConfiguration_ExcludedFromBuild = GetPropertyDispId(typeof(VCFileConfiguration), "ExcludedFromBuild");
            dispId_VCCLCompilerTool_UsePrecompiledHeader = GetPropertyDispId(typeof(VCCLCompilerTool), "UsePrecompiledHeader");
            dispId_VCCLCompilerTool_PrecompiledHeaderThrough = GetPropertyDispId(typeof(VCCLCompilerTool), "PrecompiledHeaderThrough");
            dispId_VCCLCompilerTool_PreprocessorDefinitions = GetPropertyDispId(typeof(VCCLCompilerTool), "PreprocessorDefinitions");
            dispId_VCCLCompilerTool_AdditionalIncludeDirectories = GetPropertyDispId(typeof(VCCLCompilerTool), "AdditionalIncludeDirectories");
            RegisterVCProjectEngineEvents();

            if (Connect.Instance().AppWrapperPath == null)
            {
                Messages.DisplayCriticalErrorMessage("QtAppWrapper can't be found in the installation directory.");
            }
            else
            {
                appWrapperProcess = new System.Diagnostics.Process();
                appWrapperProcess.StartInfo.FileName = Connect.Instance().AppWrapperPath;
            }
            appWrapperThread = new System.Threading.Thread(new System.Threading.ThreadStart(ListenForRequests));
            appWrapperThread.Name = "QtAppWrapperListener";
            appWrapperThread.Start();
        }
Example #14
0
        private void LoadPluginFunction()
        {
            object[] contextGUIDS = new object[] { };
            Commands2 commands = (Commands2)_applicationObject.Commands;

            //将此命令置于“工具”菜单上。
            //查找 MenuBar 命令栏,该命令栏是容纳所有主菜单项的顶级命令栏:
            Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];

            //在 MenuBar 命令栏上查找“工具”命令栏:
            CommandBarControl toolsControl = menuBarCommandBar.Controls["工具"];
            CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;

            //如果希望添加多个由您的外接程序处理的命令,可以重复此 try/catch 块,
            //  只需确保更新 QueryStatus/Exec 方法,使其包含新的命令名。
            try
            {
                //将一个命令添加到 Commands 集合:
                MenubarCommand = commands.AddNamedCommand2(_addInInstance, "FileModifyRecorder", "文件修改记录...", "显示文件修改记录", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

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

            docEvents = (EnvDTE.DocumentEvents)_applicationObject.Events.get_DocumentEvents(null);
            docEvents.DocumentSaved -= saveHandler;
            docEvents.DocumentSaved += saveHandler;
            Loaded = true;
            OutPutLogToStatusBar(" 文件记录模块加载完毕",true);
        }
Example #15
0
        public void DetachFileEventListeners()
        {
            try
            {
                //IVsHierarchyEvents
                // ((Events2)dte.Events).SolutionEvents.

                projItemsEvents = (EnvDTE.ProjectItemsEvents)this.DTE.Events.GetObject("CSharpProjectItemsEvents");
                projItemsEvents.ItemAdded -= ProjItemAdded;
                projItemsEvents.ItemRemoved -= ProjItemRemoved;
                projItemsEvents.ItemRenamed -= ProjItemRenamed;

                docEvents = (EnvDTE.DocumentEvents)this.DTE.Events.DocumentEvents;
                docEvents.DocumentSaved -= DocEventsDocSaved;
            }
            catch (System.Exception ex)
            {
                LogService.Exception("Error unregistering file event handlers", ex);
            }
        }
Example #16
0
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);

            m_settings.onOptionsChanged += new EventHandler(onConfigurationChanged);

            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = await  GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                // Register new command
                CommandID cmdOptions          = new CommandID(GuidList.guidCodeBeautifierCmdSet, (int)PkgCmdIDList.cmdOptions);
                CommandID cmdAbout            = new CommandID(GuidList.guidCodeBeautifierCmdSet, (int)PkgCmdIDList.cmdAbout);
                CommandID cmdCurrentDocument  = new CommandID(GuidList.guidCodeBeautifierCmdSet, (int)PkgCmdIDList.cmdCurrentDocument);
                CommandID cmdAllOpenDocuments = new CommandID(GuidList.guidCodeBeautifierCmdSet, (int)PkgCmdIDList.cmdAllOpenDocuments);
                CommandID cmdSelectedProject  = new CommandID(GuidList.guidCodeBeautifierCmdSet, (int)PkgCmdIDList.cmdSelectedProject);
                CommandID cmdSelectedSolution = new CommandID(GuidList.guidCodeBeautifierCmdSet, (int)PkgCmdIDList.cmdSelectedSolution);

                MenuCommand    menuOptions          = new MenuCommand(menuOptionsCallback, cmdOptions);
                MenuCommand    menuAbout            = new MenuCommand(menuAboutCallback, cmdAbout);
                OleMenuCommand menuCurrentDocument  = new OleMenuCommand(callbackCurrentCallback, cmdCurrentDocument);
                OleMenuCommand menuAllOpenDocuments = new OleMenuCommand(callbackAllOpenDocuments, cmdAllOpenDocuments);
                OleMenuCommand menuSelectedProject  = new OleMenuCommand(callbackSelectedProject, cmdSelectedProject);
                OleMenuCommand menuSolution         = new OleMenuCommand(callbackSolution, cmdSelectedSolution);

                menuCurrentDocument.BeforeQueryStatus  += new EventHandler(onBeforeQueryStatusCurrentDocument);
                menuAllOpenDocuments.BeforeQueryStatus += new EventHandler(onBeforeQueryStatusAllOpenDocuments);
                menuSelectedProject.BeforeQueryStatus  += new EventHandler(onBeforeQueryStatusSelectedProject);
                menuSolution.BeforeQueryStatus         += new EventHandler(onBeforeQueryStatusSolution);

                mcs.AddCommand(menuOptions);
                mcs.AddCommand(menuAbout);
                mcs.AddCommand(menuCurrentDocument);
                mcs.AddCommand(menuAllOpenDocuments);
                mcs.AddCommand(menuSelectedProject);
                mcs.AddCommand(menuSolution);

                m_dte2 = await GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2;

                beforeExecute("{5EFC7975-14BC-11CF-9B2B-00AA00573819}", 882).BeforeExecute  += onBuildSolution;
                beforeExecute("{5EFC7975-14BC-11CF-9B2B-00AA00573819}", 883).BeforeExecute  += onReBuildSolution;
                beforeExecute("{5EFC7975-14BC-11CF-9B2B-00AA00573819}", 886).BeforeExecute  += onBuildSelected;
                beforeExecute("{5EFC7975-14BC-11CF-9B2B-00AA00573819}", 887).BeforeExecute  += onReBuildSelected;
                beforeExecute("{1496A755-94DE-11D0-8C3F-00C04FC2AAE2}", 1603).BeforeExecute += onBuildSelected;
                beforeExecute("{1496A755-94DE-11D0-8C3F-00C04FC2AAE2}", 1604).BeforeExecute += onReBuildSelected;

                EnvDTE80.Events2 dteEvents2 = m_dte2.Events as EnvDTE80.Events2;
                m_documentEvents = dteEvents2.get_DocumentEvents();
                m_documentEvents.DocumentSaved += onDocumentSaved;

                m_textDocumentEvents = dteEvents2.get_TextDocumentKeyPressEvents();
                m_textDocumentEvents.AfterKeyPress += onTextDocumentKeyPressed;

                onConfigurationChanged(null, null);
            }
        }
Example #17
0
        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);
        }