protected override IOleCommandTarget Connect()
        {
            IVsRegisterPriorityCommandTarget registerPct = (IVsRegisterPriorityCommandTarget)ServiceProvider.GetService(typeof(SVsRegisterPriorityCommandTarget));

            registerPct.RegisterPriorityCommandTarget(0, this, out _cookie);
            return(null);
        }
示例#2
0
        private void RegisterCommandMenuService()
        {
            IVsRegisterPriorityCommandTarget commandRegistry = GetService(typeof(SVsRegisterPriorityCommandTarget)) as IVsRegisterPriorityCommandTarget;

            _thirdPartyEditorCommands = new ClearableMenuCommandService(this);
            uint cookie = 0;

            commandRegistry.RegisterPriorityCommandTarget(0, _thirdPartyEditorCommands, out cookie);
        }
示例#3
0
        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);
        }
示例#4
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));
            }
        }
        internal virtual void Start()
        {
            Debug.Assert(!capturing);

            if (!catalogBuilt)
            {
                OnStatus("Building global command target catalog");

                BuildCatalog();
            }

            if (ErrorHandler.Failed(registerPriorityCommandTarget.RegisterPriorityCommandTarget(0, this, out commandTargetCookie)))
            {
                OnStatus("Attempt to register priority command target failed");
            }

            capturing = true;
        }
示例#7
0
        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;
                }
            }
        }
示例#8
0
        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);
            }
        }
示例#9
0
        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));
            }
        }
示例#10
0
        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);
            }
        }