public void Run(IVisualStudioPackage package) {
      // Create an IOleCommandTarget wrapping all the priority command handlers
      var commandTargets = _commandHandlers
        .Select(c => new SimpleCommandTarget(
          c.CommandId,
          () => c.Execute(this, new EventArgs()),
          () => c.Supported,
          () => c.Enabled));
      var aggregate = new AggregateCommandTarget(commandTargets);
      var oleCommandTarget = new OleCommandTarget("PackagePriority", aggregate);

      // Register the ole command target as a VS priority command target
      var registerPriorityCommandTarget = package.VsRegisterPriorityCommandTarget;
      uint cookie;
      int hr = registerPriorityCommandTarget.RegisterPriorityCommandTarget(0, oleCommandTarget, out cookie);
      try {
        ErrorHandler.ThrowOnFailure(hr);
      }
      catch (Exception e) {
        Logger.LogError(e, "Error registering priority command handler.");
        return;
      }

      package.DisposeContainer.Add(() => registerPriorityCommandTarget.UnregisterPriorityCommandTarget(cookie));
    }
Exemplo n.º 2
0
        public void Attach(IVsTextView textViewAdapter)
        {
            if (_textViewAdapter != null)
            {
                throw new InvalidOperationException("ViewHandler instance is already attached to a view. Create a new instance?");
            }
            _textViewAdapter = textViewAdapter;
            _textView        = _adaptersFactoryService.GetWpfTextView(textViewAdapter);

            var target        = new SimpleCommandTarget(new CommandID(GuidList.GuidVsChromiumCmdSet, PkgCmdIdList.CmdidFormatComment), Execute);
            var targetWrapper = new OleCommandTarget(target);

            _textViewAdapter.AddCommandFilter(targetWrapper, out targetWrapper.NextCommandTarget);
        }
Exemplo n.º 3
0
        public void Attach(IVsTextView textViewAdapter)
        {
            if (!ApplyToView(textViewAdapter))
            {
                return;
            }

            if (_textViewAdapter != null)
            {
                throw new InvalidOperationException("ViewHandler instance is already attached to a view. Create a new instance?");
            }
            _textViewAdapter = textViewAdapter;
            _textView        = _adaptersFactoryService.GetWpfTextView(textViewAdapter);

            var target        = new SimpleCommandTarget(new CommandID(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.ECMD_LEFTCLICK), Execute, HandlesCommand);
            var targetWrapper = new OleCommandTarget(target);

            _textViewAdapter.AddCommandFilter(targetWrapper, out targetWrapper.NextCommandTarget);
        }