Beispiel #1
0
        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;
            }
        }
Beispiel #2
0
        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;
            }
        }