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); } }
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); } }
public void Install(Control control, System.ComponentModel.Design.CommandID command, EventHandler <Ankh.Commands.CommandEventArgs> handler, EventHandler <Ankh.Commands.CommandUpdateEventArgs> updateHandler) { if (control == null) { throw new ArgumentNullException("control"); } IAnkhCommandHookAccessor acc = null; Control ctrl = control; while (ctrl != null) { acc = ctrl as IAnkhCommandHookAccessor; if (acc != null) { break; } ctrl = ctrl.Parent; } if (acc == null) { return; // Can't install hook } if (acc.CommandHook != null) { acc.CommandHook.Install(control, command, handler, updateHandler); return; } Control topParent = control.TopLevelControl; if (topParent == null) { Control p = control; while (p != null) { topParent = p; p = p.Parent; } } IAnkhVSContainerForm ct = topParent as IAnkhVSContainerForm; if (ct != null) { ContextCommandHandler cx = new ContextCommandHandler(this, topParent); acc.CommandHook = cx; cx.Install(control, command, handler, updateHandler); ct.AddCommandTarget(cx); return; } IAnkhToolWindowControl toolWindow = topParent as IAnkhToolWindowControl; if (toolWindow != null && toolWindow.ToolWindowHost != null) { ContextCommandHandler cx = new ContextCommandHandler(this, topParent); acc.CommandHook = cx; cx.Install(control, command, handler, updateHandler); toolWindow.ToolWindowHost.AddCommandTarget(cx); return; } }