protected override void Initialize() { base.Initialize(); this.dte = (EnvDTE80.DTE2)GetService(typeof(EnvDTE.DTE)); this.event2 = (EnvDTE80.Events2) this.dte.Events; this.keyPressEvents = this.event2.TextDocumentKeyPressEvents; this.keyPressEvents.AfterKeyPress += TextDocumentKeyPressEvents_AfterKeyPress; }
public AutoCheckoutTextEdit(Plugin plugin) : base(plugin, "AutoCheckoutTextEdit", "Automatically checks out the text file on edits") { if(!Singleton<Config>.Instance.autoCheckoutOnEdit) return; Log.Info("Adding handlers for automatically checking out text files as you edit them"); mTextDocEvents = ((EnvDTE80.Events2)plugin.App.Events).get_TextDocumentKeyPressEvents(null); mTextDocEvents.BeforeKeyPress += new _dispTextDocumentKeyPressEvents_BeforeKeyPressEventHandler(OnBeforeKeyPress); mTextEditorEvents = ((EnvDTE80.Events2)plugin.App.Events).get_TextEditorEvents(null); mTextEditorEvents.LineChanged += new _dispTextEditorEvents_LineChangedEventHandler(OnLineChanged); RegisterHandler("Edit.Delete", OnCheckoutCurrentDocument); RegisterHandler("Edit.DeleteBackwards", OnCheckoutCurrentDocument); RegisterHandler("Edit.Paste", OnCheckoutCurrentDocument); }
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); } }