public void Dispose() { //Remove message filter Application.RemoveMessageFilter((System.Windows.Forms.IMessageFilter) this); if (services != null) { // Remove this object from the list of the priority command targets. if (cmdTargetCookie != 0) { IVsRegisterPriorityCommandTarget register = services.VsRegisterPriorityCommandTarget; if (null != register) { int hr = register.UnregisterPriorityCommandTarget(cmdTargetCookie); if (hr != VSConstants.S_OK) { Marshal.ThrowExceptionForHR(hr); } } cmdTargetCookie = 0; } services = null; } if (coreEditor != null) { IVsCodeWindow win = coreEditor.CodeWindow; win.Close(); coreEditor = null; } }
private void OnClosing(object sender, System.ComponentModel.CancelEventArgs e) { // Close the toolbar host. if (null != toolbarHost) { toolbarHost.Close(0); toolbarHost = null; } // Close and dispose the main pane. if (null != containedForm) { ((IVsWindowPane)containedForm).ClosePane(); containedForm = null; } // Check if we are still registered as priority command target if ((0 != commandTargetCookie) && (null != provider)) { IVsRegisterPriorityCommandTarget registerCommandTarget = GetService(typeof(SVsRegisterPriorityCommandTarget)) as IVsRegisterPriorityCommandTarget; if (null != registerCommandTarget) { registerCommandTarget.UnregisterPriorityCommandTarget(commandTargetCookie); } commandTargetCookie = 0; } if (null != e) { e.Cancel = false; } }
protected override IOleCommandTarget Connect() { IVsRegisterPriorityCommandTarget registerPct = (IVsRegisterPriorityCommandTarget)ServiceProvider.GetService(typeof(SVsRegisterPriorityCommandTarget)); registerPct.RegisterPriorityCommandTarget(0, this, out _cookie); return(null); }
private void RegisterCommandMenuService() { IVsRegisterPriorityCommandTarget commandRegistry = GetService(typeof(SVsRegisterPriorityCommandTarget)) as IVsRegisterPriorityCommandTarget; _thirdPartyEditorCommands = new ClearableMenuCommandService(this); uint cookie = 0; commandRegistry.RegisterPriorityCommandTarget(0, _thirdPartyEditorCommands, out cookie); }
private BuildCommandIntercepter(IServiceProvider serviceProvider) { if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } this.registerCommandTarget = serviceProvider.GetService <IVsRegisterPriorityCommandTarget>(typeof(SVsRegisterPriorityCommandTarget)); ErrorHandler.ThrowOnFailure(this.registerCommandTarget.RegisterPriorityCommandTarget(0U, (IOleCommandTarget)this, out this.cookie)); }
protected override void Initialize() { CmdToggleOmniView.Initialize(this); CmdToggleConsole.Initialize(this); base.Initialize(); IVsRegisterPriorityCommandTarget ip = (IVsRegisterPriorityCommandTarget)GetService(typeof(SVsRegisterPriorityCommandTarget)); uint cookie; ip.RegisterPriorityCommandTarget(0, new CommandTargetGlobal(), out cookie); }
protected override void Disconnect() { try { if (_cookie != 0) { IVsRegisterPriorityCommandTarget registerPct = (IVsRegisterPriorityCommandTarget)ServiceProvider.GetService(typeof(SVsRegisterPriorityCommandTarget)); registerPct.UnregisterPriorityCommandTarget(_cookie); } } finally { _cookie = 0; } }
/// <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> /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param> /// <param name="progress">A provider for progress updates.</param> /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns> protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { // When initialized asynchronously, the current thread may be a background thread at this point. // Do any initialization that requires the UI thread after switching to the UI thread. await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); CmdToggleOmniView.Initialize(this); CmdToggleConsole.Initialize(this); base.Initialize(); IVsRegisterPriorityCommandTarget ip = (IVsRegisterPriorityCommandTarget)GetService(typeof(SVsRegisterPriorityCommandTarget)); uint cookie; ip.RegisterPriorityCommandTarget(0, new CommandTargetGlobal(), out cookie); //await ToolWindow1Command.InitializeAsync(this); }
private void RegisterCommandTarget() { if (null == provider) { throw new InvalidOperationException(); } IVsRegisterPriorityCommandTarget registerCommandTarget = (IVsRegisterPriorityCommandTarget)provider.GetService(typeof(SVsRegisterPriorityCommandTarget)); if (null != registerCommandTarget) { NativeMethods.ThrowOnFailure( registerCommandTarget.RegisterPriorityCommandTarget( 0, (IOleCommandTarget)commandService, out commandTargetCookie)); } }
public void HookCommand(System.ComponentModel.Design.CommandID command, EventHandler handler) { ThreadHelper.ThrowIfNotOnUIThread(); if (command == null) { throw new ArgumentNullException("command"); } else if (handler == null) { throw new ArgumentNullException("handler"); } Dictionary <int, EventHandler> map; if (!_commandMap.TryGetValue(command.Guid, out map)) { map = new Dictionary <int, EventHandler>(); _commandMap[command.Guid] = map; } EventHandler handlers; if (!map.TryGetValue(command.ID, out handlers)) { handlers = null; } map[command.ID] = (handlers + handler); if (!_hooked) { IVsRegisterPriorityCommandTarget svc = GetService <IVsRegisterPriorityCommandTarget>(typeof(SVsRegisterPriorityCommandTarget)); if (svc != null && VSErr.Succeeded(svc.RegisterPriorityCommandTarget(0, this, out _cookie))) { _hooked = true; } } }
public VSCommandRouting(IAnkhServiceProvider context, VSContainerForm form) : base(context) { ThreadHelper.ThrowIfNotOnUIThread(); if (form == null) { throw new ArgumentNullException("form"); } _form = form; _vsForm = form; if (_routers.Count > 0) { _routers.Peek().Enabled = false; } Application.AddMessageFilter(this); _routers.Push(this); _installed = true; _vsWpf = !VSVersion.VS2008OrOlder; _map.Add(form, this); _priorityCommandTarget = GetService <IVsRegisterPriorityCommandTarget>(typeof(SVsRegisterPriorityCommandTarget)); if (_priorityCommandTarget != null) { if (!VSErr.Succeeded(_priorityCommandTarget.RegisterPriorityCommandTarget(0, this, out _csCookie))) { _priorityCommandTarget = null; } } ISelectionContextEx sel = GetService <ISelectionContextEx>(typeof(ISelectionContext)); if (sel != null) { _activeStack = sel.PushPopupContext(form); } }
//uint pdwCookie; ///////////////////////////////////////////////////////////////////////////// // Overriden Package Implementation #region Package Members /// <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 initilaization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { //Trace.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); base.Initialize(); IVsRegisterPriorityCommandTarget cmdTarget = GetService(typeof(SVsRegisterPriorityCommandTarget)) as IVsRegisterPriorityCommandTarget; //var id = new CommandID(GuidList.guidNumberedBookmarksCmdSet, 0x101); //var cmd = new KeyBindingCommandFilter(null); //cmdTarget.RegisterPriorityCommandTarget(0, cmd, out pdwCookie); OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { //var oldTarget = mcs.ParentTarget; //mcs.ParentTarget = new MyParentOleCommandTarget() { m_nextTarget = oldTarget }; RegisterCommand(mcs, PkgCmdIDList.cmdOne, (sender, e) => { SetBookmark(1); }); RegisterCommand(mcs, PkgCmdIDList.cmdTwo, (sender, e) => { SetBookmark(2); }); RegisterCommand(mcs, PkgCmdIDList.cmdThree, (sender, e) => { SetBookmark(3); }); RegisterCommand(mcs, PkgCmdIDList.cmdFour, (sender, e) => { SetBookmark(4); }); RegisterCommand(mcs, PkgCmdIDList.cmdFive, (sender, e) => { SetBookmark(5); }); RegisterCommand(mcs, PkgCmdIDList.cmdSix, (sender, e) => { SetBookmark(6); }); RegisterCommand(mcs, PkgCmdIDList.cmdSeven, (sender, e) => { SetBookmark(7); }); RegisterCommand(mcs, PkgCmdIDList.cmdEight, (sender, e) => { SetBookmark(8); }); RegisterCommand(mcs, PkgCmdIDList.cmdNine, (sender, e) => { SetBookmark(9); }); //CommandID menuCommandID = new CommandID(GuidList.guidFirstLookCmdSet, // (int)PkgCmdIDList.cmdOne); //MenuCommand menuItem = new MenuCommand(CommandCallback, menuCommandID); //mcs.AddCommand(menuItem); RegisterCommand(mcs, PkgCmdIDList.cmdGotoOne, (sender, e) => { GotoBookmark(1); }); RegisterCommand(mcs, PkgCmdIDList.cmdGotoTwo, (sender, e) => { GotoBookmark(2); }); RegisterCommand(mcs, PkgCmdIDList.cmdGotoThree, (sender, e) => { GotoBookmark(3); }); RegisterCommand(mcs, PkgCmdIDList.cmdGotoFour, (sender, e) => { GotoBookmark(4); }); RegisterCommand(mcs, PkgCmdIDList.cmdGotoFive, (sender, e) => { GotoBookmark(5); }); RegisterCommand(mcs, PkgCmdIDList.cmdGotoSix, (sender, e) => { GotoBookmark(6); }); RegisterCommand(mcs, PkgCmdIDList.cmdGotoSeven, (sender, e) => { GotoBookmark(7); }); RegisterCommand(mcs, PkgCmdIDList.cmdGotoEight, (sender, e) => { GotoBookmark(8); }); RegisterCommand(mcs, PkgCmdIDList.cmdGotoNine, (sender, e) => { GotoBookmark(9); }); } this.IsAcrossDocuments = GeneralPage.Options.UseBoomarkAcrossDocument; }
public bool?ShowModalWithEditorHooked() { //Hook ourselves into the command chain IVsRegisterPriorityCommandTarget rpct = (IVsRegisterPriorityCommandTarget)ServiceProvider.GlobalProvider.GetService(typeof(SVsRegisterPriorityCommandTarget)); uint pctCookie; ErrorHandler.ThrowOnFailure(rpct.RegisterPriorityCommandTarget(dwReserved: 0, pCmdTrgt: this, pdwCookie: out pctCookie)); //Hook into WPFs thread message handling so we can handle WM_KEYDOWN messages ComponentDispatcher.ThreadFilterMessage += FilterThreadMessage; try { return(ShowModal()); } finally { //unhook from WPF's thread message handling. ComponentDispatcher.ThreadFilterMessage -= FilterThreadMessage; //Unhook ourselves from the command chain ErrorHandler.ThrowOnFailure(rpct.UnregisterPriorityCommandTarget(pctCookie)); } }
public GlobalCommandTargetBase() { registerPriorityCommandTarget = (IVsRegisterPriorityCommandTarget)Package.GetGlobalService(typeof(IVsRegisterPriorityCommandTarget)); CommandSets = new Dictionary <Guid, CommandSet>(); }
protected override void Dispose(bool disposing) { try { if (_priorityCommandTarget != null) { try { _priorityCommandTarget.UnregisterPriorityCommandTarget(_csCookie); } finally { _priorityCommandTarget = null; } } if (_activeStack != null) { try { _activeStack.Dispose(); } finally { _activeStack = null; } } if (_panel != null) { RestoreLayout(); } if (_pane != null) { _pane.Dispose(); // Unhook _pane = null; } if (_panel != null) { _panel.Dispose(); _panel = null; } } finally { _map.Remove(_form); if (_installed) { _installed = false; Application.RemoveMessageFilter(this); VSCommandRouting cr = _routers.Pop(); Debug.Assert(cr == this, "Pop routing in the right order"); if (_routers.Count > 0) { _routers.Peek().Enabled = true; } } base.Dispose(disposing); } }
public VSCommandRouting(IAnkhServiceProvider context, VSContainerForm form) : base(context) { if (form == null) throw new ArgumentNullException("form"); _form = form; _vsForm = form; if (_routers.Count > 0) _routers.Peek().Enabled = false; Application.AddMessageFilter(this); _routers.Push(this); _installed = true; _vsWpf = !VSVersion.VS2008OrOlder; _map.Add(form, this); _rPct = GetService<IVsRegisterPriorityCommandTarget>(typeof(SVsRegisterPriorityCommandTarget)); if(_rPct != null) { Marshal.ThrowExceptionForHR(_rPct.RegisterPriorityCommandTarget(0, this, out _csCookie)); } ISelectionContextEx sel = GetService<ISelectionContextEx>(typeof(ISelectionContext)); if (sel != null) { _activeStack = sel.PushPopupContext(form); } }