public IOleCommandTarget GetCommandTarget(IWpfTextView textView, IOleCommandTarget nextTarget)
 {
     var target = new ScriptingOleCommandTarget(textView, _commandHandlerServiceFactory, _editorAdaptersFactory, _serviceProvider);
     target.RefreshCommandFilters();
     target.NextCommandTarget = nextTarget;
     return target;
 }
        public IOleCommandTarget GetCommandTarget(IWpfTextView textView, IOleCommandTarget nextTarget) {
            IOleCommandTarget target = ServiceManager.GetService<IOleCommandTarget>(textView);
            if (target == null) {
                ReplCommandController controller = ReplCommandController.Attach(textView, textView.TextBuffer);

                // Wrap controller into OLE command target
                target = VsAppShell.Current.TranslateToHostCommandTarget(textView, controller) as IOleCommandTarget;
                Debug.Assert(target != null);

                ServiceManager.AddService(target, textView);

                // Wrap next OLE target in the chain into ICommandTarget so we can have 
                // chain like: OLE Target -> Shim -> ICommandTarget -> Shim -> Next OLE target
                ICommandTarget nextCommandTarget = VsAppShell.Current.TranslateCommandTarget(textView, nextTarget);
                controller.ChainedController = nextCommandTarget;

                // We need to listed when R projected buffer is attached and 
                // create R editor document over it.
                textView.BufferGraph.GraphBuffersChanged += OnGraphBuffersChanged;
                IProjectionBuffer pb = textView.TextBuffer as IProjectionBuffer;
                if (pb != null) {
                    pb.SourceBuffersChanged += OnSourceBuffersChanged;
                }

                textView.Closed += TextView_Closed;
            }

            return target;
        }
예제 #3
0
        public RebarController(QTTabBarClass tabbar, IntPtr hwndReBar, IOleCommandTarget bandObjectSite)
        {
            this.tabbar = tabbar;
            this.bandObjectSite = bandObjectSite;
            ExplorerHandle = PInvoke.GetAncestor(hwndReBar, 2);
            Handle = hwndReBar;
            rebarController = new NativeWindowController(hwndReBar);
            rebarController.MessageCaptured += RebarMessageCaptured;

            REBARBANDINFO structure = new REBARBANDINFO();
            structure.cbSize = Marshal.SizeOf(structure);
            structure.fMask = RBBIM.CHILD | RBBIM.ID;
            int num = (int)PInvoke.SendMessage(Handle, RB.GETBANDCOUNT, IntPtr.Zero, IntPtr.Zero);
            for(int i = 0; i < num; i++) {
                PInvoke.SendMessage(Handle, RB.GETBANDINFO, (IntPtr)i, ref structure);
                if(PInvoke.GetClassName(structure.hwndChild) == "ToolbarWindow32" && structure.wID == 1) {
                    menuController = new NativeWindowController(structure.hwndChild);
                    menuController.MessageCaptured += MenuMessageCaptured;
                    break;
                }
            }

            if(Config.Skin.UseRebarBGColor) {
                if(DefaultRebarCOLORREF == -1) {
                    DefaultRebarCOLORREF = (int)PInvoke.SendMessage(Handle, RB.GETBKCOLOR, IntPtr.Zero, IntPtr.Zero);
                }
                int num2 = QTUtility2.MakeCOLORREF(Config.Skin.RebarColor);
                PInvoke.SendMessage(Handle, RB.SETBKCOLOR, IntPtr.Zero, (IntPtr)num2);
            }

            EnsureMenuBarIsCorrect();
        }
예제 #4
0
    public static int WrapQueryStatus(
      IOleCommandTarget receiver,
      IOleCommandTarget implementer,
      ref System.Guid pguidCmdGroup,
      uint cCmds,
      OLECMD[] prgCmds,
      System.IntPtr pCmdText) {
      Debug.Assert(receiver != null);

      var commandId = new CommandID(pguidCmdGroup, (int)prgCmds[0].cmdID);
      if (LogCommand(commandId)) {
        Logger.LogInfo("WrapQueryStatus: => recv={0}, impl={1}, parent={2}",
          receiver,
          GetImplementerString(implementer),
          GetParentTargetString(implementer));
      }

      var hr = (implementer == null)
        ? (int)Constants.OLECMDERR_E_NOTSUPPORTED
        : implementer.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);

      if (LogCommand(commandId)) {
        Logger.LogInfo("WrapQueryStatus: <= recv={0}, impl={1}, parent={2}, hr={3}, cmdf={4}",
          receiver,
          GetImplementerString(implementer),
          GetParentTargetString(implementer),
          HrToString(hr),
          CmdFlagsToString(prgCmds));
      }
      return hr;
    }
예제 #5
0
        public VsCommandTargetTest()
        {
            _textView = CreateTextView("");
            _buffer = Vim.CreateVimBuffer(_textView);
            _bufferCoordinator = new VimBufferCoordinator(_buffer);
            _vim = _buffer.Vim;
            _factory = new MockRepository(MockBehavior.Strict);

            // By default Resharper isn't loaded
            _resharperUtil = _factory.Create<IResharperUtil>();
            _resharperUtil.SetupGet(x => x.IsInstalled).Returns(false);

            _nextTarget = _factory.Create<IOleCommandTarget>(MockBehavior.Strict);
            _vsAdapter = _factory.Create<IVsAdapter>();
            _vsAdapter.SetupGet(x => x.KeyboardDevice).Returns(InputManager.Current.PrimaryKeyboardDevice);
            _vsAdapter.Setup(x => x.InAutomationFunction).Returns(false);
            _vsAdapter.Setup(x => x.InDebugMode).Returns(false);
            _vsAdapter.Setup(x => x.IsIncrementalSearchActive(It.IsAny<ITextView>())).Returns(false);

            _broker = _factory.Create<IDisplayWindowBroker>(MockBehavior.Loose);

            var oldCommandFilter = _nextTarget.Object;
            var vsTextView = _factory.Create<IVsTextView>(MockBehavior.Loose);
            vsTextView.Setup(x => x.AddCommandFilter(It.IsAny<IOleCommandTarget>(), out oldCommandFilter)).Returns(0);
            var result = VsCommandTarget.Create(
                _bufferCoordinator,
                vsTextView.Object,
                _vsAdapter.Object,
                _broker.Object,
                _resharperUtil.Object,
                KeyUtil);
            Assert.True(result.IsSuccess);
            _targetRaw = result.Value;
            _target = _targetRaw;
        }
 ///<summary>Attempts to figure out whether the JSLS language service has been installed yet.</summary>
 static bool IsJSLSInstalled(IOleCommandTarget next)
 {
     Guid cmdGroup = VSConstants.VSStd2K;
     var cmds = new[] { new OLECMD { cmdID = (uint)VSConstants.VSStd2KCmdID.AUTOCOMPLETE } };
     ErrorHandler.ThrowOnFailure(next.QueryStatus(ref cmdGroup, 1, cmds, IntPtr.Zero));
     return cmds[0].cmdf == 3;
 }
        public VsInteractiveWindowCommandFilter(IVsEditorAdaptersFactoryService adapterFactory, IInteractiveWindow window, IVsTextView textViewAdapter, IVsTextBuffer bufferAdapter, IEnumerable<Lazy<IVsInteractiveWindowOleCommandTargetProvider, ContentTypeMetadata>> oleCommandTargetProviders, IContentTypeRegistryService contentTypeRegistry)
        {
            _window = window;
            _oleCommandTargetProviders = oleCommandTargetProviders;
            _contentTypeRegistry = contentTypeRegistry;

            this.textViewAdapter = textViewAdapter;

            // make us a code window so we'll have the same colors as a normal code window.
            IVsTextEditorPropertyContainer propContainer;
            ErrorHandler.ThrowOnFailure(((IVsTextEditorPropertyCategoryContainer)textViewAdapter).GetPropertyCategory(Microsoft.VisualStudio.Editor.DefGuidList.guidEditPropCategoryViewMasterSettings, out propContainer));
            propContainer.SetProperty(VSEDITPROPID.VSEDITPROPID_ViewComposite_AllCodeWindowDefaults, true);
            propContainer.SetProperty(VSEDITPROPID.VSEDITPROPID_ViewGlobalOpt_AutoScrollCaretOnTextEntry, true);

            // editor services are initialized in textViewAdapter.Initialize - hook underneath them:
            _preEditorCommandFilter = new CommandFilter(this, CommandFilterLayer.PreEditor);
            ErrorHandler.ThrowOnFailure(textViewAdapter.AddCommandFilter(_preEditorCommandFilter, out _editorCommandFilter));

            textViewAdapter.Initialize(
                (IVsTextLines)bufferAdapter,
                IntPtr.Zero,
                (uint)TextViewInitFlags.VIF_HSCROLL | (uint)TextViewInitFlags.VIF_VSCROLL | (uint)TextViewInitFlags3.VIF_NO_HWND_SUPPORT,
                new[] { new INITVIEW { fSelectionMargin = 0, fWidgetMargin = 0, fVirtualSpace = 0, fDragDropMove = 1 } });

            // disable change tracking because everything will be changed
            var textViewHost = adapterFactory.GetWpfTextViewHost(textViewAdapter);

            _preLanguageCommandFilter = new CommandFilter(this, CommandFilterLayer.PreLanguage);
            ErrorHandler.ThrowOnFailure(textViewAdapter.AddCommandFilter(_preLanguageCommandFilter, out _editorServicesCommandFilter));

            _textViewHost = textViewHost;
        }
        public VSCodeEditorWindow(ServiceBroker sb, UserControl parent)
        {
            services = sb;
            coreEditor = new VSCodeEditor(parent.Handle, services);

            //Create window            
            IVsCodeWindow win = coreEditor.CodeWindow;
            cmdTarget = win as IOleCommandTarget;

            IVsTextView textView;
            int hr = win.GetPrimaryView(out textView);
            if (hr != VSConstants.S_OK)
                Marshal.ThrowExceptionForHR(hr);

            // assign the window handle
            IntPtr commandHwnd = textView.GetWindowHandle();
            AssignHandle(commandHwnd);

            //Register priority command target
            hr = services.VsRegisterPriorityCommandTarget.RegisterPriorityCommandTarget(
                0, (IOleCommandTarget)this, out cmdTargetCookie);

            if (hr != VSConstants.S_OK)
                Marshal.ThrowExceptionForHR(hr);

            //Add message filter
            Application.AddMessageFilter((System.Windows.Forms.IMessageFilter)this);
        }
 public CommandTargetHelper(IOleCommandTarget commandTarget)
 {
     if (null == commandTarget)
     {
         throw new ArgumentNullException("commandTarget");
     }
     this.target = commandTarget;
 }
예제 #10
0
 public IntelliSenseManager(ICompletionBroker broker, SVsServiceProvider provider, IOleCommandTarget commandHandler, ITextView textView)
 {
     _broker = broker;
     NextCommandHandler = commandHandler;
     _textView = textView;
     _isRepl = _textView.Properties.ContainsProperty(BufferProperties.FromRepl);
     _serviceProvider = provider;
 }
예제 #11
0
        int IVsSmartTagData.GetContextMenuInfo(out Guid guidID, out int nMenuID, out IOleCommandTarget pCmdTarget)
        {
            guidID     = MenuCmd.guidNemerleProjectCmdSet;
            nMenuID    = (int)MenuCmd.CmdId.SmartTagContextMenu;
            pCmdTarget = this;

            return VSConstants.S_OK;
        }
예제 #12
0
        public void AddCommandTarget(Ankh.UI.VSContainerForm form, IOleCommandTarget commandTarget)
        {
            VSCommandRouting routing = VSCommandRouting.FromForm(form);

            if (routing != null)
                routing.AddCommandTarget(commandTarget);
            else
                throw new InvalidOperationException("Command routing not initialized yet");
        }
 /// <include file='doc\OleMenuCommandService.uex' path='docs/doc[@for="OleMenuCommandService.OleMenuCommandService1"]/*' />
 /// <devdoc>
 ///     Creates a new menu command service.
 /// </devdoc>
 public OleMenuCommandService(IServiceProvider serviceProvider, IOleCommandTarget parentCommandTarget)
     : base(serviceProvider)
 {
     if (parentCommandTarget == null) {
         throw new ArgumentNullException("parentCommandTarget");
     }
     _parentTarget = parentCommandTarget;
     _provider = serviceProvider;
 }
예제 #14
0
        ICommandTarget ICommandTargetFactory.CreateCommandTarget(IOleCommandTarget nextCommandTarget, IVimBufferCoordinator vimBufferCoordinator)
        {
            if (!_reSharperUtil.IsInstalled)
            {
                return null;
            }

            return ReSharperKeyUtil.GetOrCreate(vimBufferCoordinator);
        }
 internal TextViewWrapper(IVsContainedLanguageHost languageHost, IVsIntellisenseHost intellisenseHost, IVsTextBufferCoordinator coordinator, IOleCommandTarget nextTarget)
 {
     if (null == intellisenseHost) {
         throw new ArgumentNullException("buffer");
     }
     this.intellisenseHost = intellisenseHost;
     this.bufferCoordinator = coordinator;
     this.languageHost = languageHost;
     this.nextTarget = nextTarget;
 }
예제 #16
0
        public OleCommandFilter(IVsTextView vsTextView)
        {
            Debug.Assert(vsTextView != null);

            IOleCommandTarget _oldChain;
            ErrorHandler.ThrowOnFailure(vsTextView.AddCommandFilter(this, out _oldChain));
            Debug.Assert(_oldChain != null);

            this.OldChain = _oldChain;
        }
        /// <include file='doc\DialogContainerWithToolbar.uex' path='docs/doc[@for="DialogContainerWithToolbar.DialogContainerWithToolbar"]/*' />
        /// <devdoc>
        /// Constructor of the DialogContainerWithToolbar. This constructor allow the caller to set a IServiceProvider,
        /// the conatined control and an additional IOleCommandTarget implementation that will be chained to the one
        /// implemented by OleMenuCommandTarget.
        /// </devdoc>
        public DialogContainerWithToolbar(IServiceProvider sp, Control contained, IOleCommandTarget parentCommandTarget)
        {
            if (null == contained)
                throw new ArgumentNullException("contained");

            if (null == sp)
                throw new ArgumentNullException("sp");

            PrivateInit(sp, contained, parentCommandTarget);
        }
예제 #18
0
 internal VsCommandTarget(
     IVimBufferCoordinator vimBufferCoordinator,
     ITextManager textManager,
     IVsAdapter vsAdapter,
     IDisplayWindowBroker broker,
     IKeyUtil keyUtil,
     IOleCommandTarget nextTarget,
     ReadOnlyCollection<ICommandTarget> commandTargets)
     : this(vimBufferCoordinator, textManager, vsAdapter, broker, keyUtil)
 {
     CompleteInit(nextTarget, commandTargets);
 }
예제 #19
0
 internal StandardCommandTarget(
     IVimBufferCoordinator vimBufferCoordinator,
     ITextManager textManager,
     IDisplayWindowBroker broker,
     IOleCommandTarget nextOleCommandTarget)
 {
     _vimBuffer = vimBufferCoordinator.VimBuffer;
     _vimBufferCoordinator = vimBufferCoordinator;
     _textBuffer = _vimBuffer.TextBuffer;
     _textView = _vimBuffer.TextView;
     _textManager = textManager;
     _broker = broker;
     _nextOleCommandTarget = nextOleCommandTarget;
 }
        static bool IsJSLSInstalled(IOleCommandTarget next)
        {
            Guid cmdGroup = VSConstants.VSStd2K;
            var cmds = new[] { new OLECMD { cmdID = (uint)VSConstants.VSStd2KCmdID.AUTOCOMPLETE } };

            try
            {
                next.QueryStatus(ref cmdGroup, 1, cmds, IntPtr.Zero);
                return cmds[0].cmdf == 3;
            }
            catch
            {
                return false;
            }
        }
예제 #21
0
        internal AbstractOleCommandTarget AttachToVsTextView()
        {
            var vsTextView = _editorAdaptersFactory.GetViewAdapter(_wpfTextView);

            // Add command filter to IVsTextView. If something goes wrong, throw.
            IOleCommandTarget nextCommandTarget;
            int returnValue = vsTextView.AddCommandFilter(this, out nextCommandTarget);
            Marshal.ThrowExceptionForHR(returnValue);
            Contract.ThrowIfNull(nextCommandTarget);

            CurrentHandlers = _commandHandlerServiceFactory.GetService(WpfTextView);
            NextCommandTarget = nextCommandTarget;

            return this;
        }
예제 #22
0
        internal CompletionCommandHandler(IVsTextView textViewAdapter, ITextView textView,
            CompletionHandlerProvider provider)
        {
            this._textView = textView;
            this._provider = provider;

            //add the command to the command chain
            textViewAdapter.AddCommandFilter(this, out _nextCommandHandler);
            var nextProp = _nextCommandHandler.GetType().GetProperty("Next");
            var filterObjectProp = _nextCommandHandler.GetType().GetProperty("FilterObject");

            _realCommandHandler =
                (IOleCommandTarget)
                    filterObjectProp.GetValue(nextProp.GetValue(nextProp.GetValue(_nextCommandHandler)));
            textView.Properties[typeof (CompletionCommandHandler)] = this;
        }
예제 #23
0
    private void AddCommandFilter(IVsTextView viewAdapter)
    {
      if (IsAdded)
        return;
        
      //get the view adapter from the editor factory
      IOleCommandTarget next;
      var hr = viewAdapter.AddCommandFilter(this, out next);

      if (hr == S_OK)
      {
        IsAdded = true;
        //you'll need the next target for Exec and QueryStatus
        if (next != null)
          _nextTarget = next;
      }
    }
        internal FSharpCompletionCommandHandler(IVsTextView textViewAdapter, ITextView textView, FSharpCompletionHandlerProvider fsharpCompletionHandlerProvider)
        {
            this.m_textView = textView;
            this.m_provider = fsharpCompletionHandlerProvider;

            this.dte = this.m_provider.ServiceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            textViewAdapter.AddCommandFilter(this, out m_nextCommandHandler);

            Task.Delay(2000).ContinueWith((a) =>
            {
                // Probably it is possible to find it through package as well.
                this.fsiToolWindow = CommandChainNodeWrapper.GetFilterByFullClassName(textViewAdapter, 
                    FsiLanguageServiceHelper.FsiToolWindowClassName);
            });

            this.textViewAdapter = textViewAdapter;
        }
예제 #25
0
        public CommandHelper(System.IServiceProvider serviceProvider)
        {
            var rot = this.GetRunningObjectTable();

            System.Runtime.InteropServices.ComTypes.IMoniker cmdDispatchMoniker = this.GetCmdDispatcherMoniker();
            System.Runtime.InteropServices.ComTypes.IMoniker cmdNameMoniker = this.GetCmdNameMoniker();

            var cmdDispatchObject = this.GetObjectFromRot(rot, cmdDispatchMoniker);
            var cmdNameObject = this.GetObjectFromRot(rot, cmdNameMoniker);

            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            this.shellCmdTarget = (IOleCommandTarget)cmdDispatchObject;
            this.cmdNameMapping = (IVsCmdNameMapping)cmdNameObject;
        }
예제 #26
0
        public RebarController(QTTabBarClass tabbar, IntPtr hwndReBar, IOleCommandTarget bandObjectSite) {
            this.tabbar = tabbar;
            this.bandObjectSite = bandObjectSite;
            ExplorerHandle = PInvoke.GetAncestor(hwndReBar, 2);
            Handle = hwndReBar;
            rebarController = new NativeWindowController(hwndReBar);
            rebarController.MessageCaptured += MessageCaptured;

            if(QTUtility.CheckConfig(Settings.ToolbarBGColor)) {
                if(QTUtility.DefaultRebarCOLORREF == -1) {
                    QTUtility.DefaultRebarCOLORREF = (int)PInvoke.SendMessage(Handle, RB.GETBKCOLOR, IntPtr.Zero, IntPtr.Zero);
                }
                int num2 = QTUtility2.MakeCOLORREF(QTUtility.RebarBGColor);
                PInvoke.SendMessage(Handle, RB.SETBKCOLOR, IntPtr.Zero, (IntPtr)num2);
            }

            EnsureMenuBarIsCorrect();
        }
예제 #27
0
        /// <include file='doc\FlavoredProject.uex' path='docs/doc[@for="FlavoredProject.SetInnerProject"]/*' />
        /// <devdoc>
        /// This is were all QI for interface on the inner object should happen
        /// Then set the inner project
        /// wait for InitializeForOuter to be called to do the real initialization
        /// </devdoc>
        protected virtual void SetInnerProject(object inner)
        {
            // Keep a reference to each interface we want to call on the inner project
            // we must do it now as once we call SetInner the AddRef would be forwarded to ourselves
            innerVsAggregatableProject = (IVsAggregatableProject)inner;
            innerVsHierarchy = (IVsHierarchy)inner;
            innerVsUIHierarchy = (IVsUIHierarchy)inner;
            // As should return null without throwing in the event the base project does not implement the interface
            innerOleCommandTarget = inner as IOleCommandTarget;

            // Setup our menu command service
            if (this.serviceProvider == null)
                throw new NotSupportedException("serviceProvider should have been set before SetInnerProject gets called.");
            menuService = new OleMenuCommandService(this, innerOleCommandTarget);

            // Aggregate the project
            this.SetInner(inner);
        }
예제 #28
0
        protected VsCommandTargetTest(bool isReSharperInstalled)
        {
            _textView          = CreateTextView("");
            _textBuffer        = _textView.TextBuffer;
            _vimBuffer         = Vim.CreateVimBuffer(_textView);
            _bufferCoordinator = new VimBufferCoordinator(_vimBuffer);
            _vim     = _vimBuffer.Vim;
            _factory = new MockRepository(MockBehavior.Strict);

            _nextTarget = _factory.Create <IOleCommandTarget>(MockBehavior.Strict);
            _vsAdapter  = _factory.Create <IVsAdapter>();
            _vsAdapter.SetupGet(x => x.KeyboardDevice).Returns(InputManager.Current.PrimaryKeyboardDevice);
            _vsAdapter.Setup(x => x.InAutomationFunction).Returns(false);
            _vsAdapter.Setup(x => x.InDebugMode).Returns(false);
            _vsAdapter.Setup(x => x.IsIncrementalSearchActive(It.IsAny <ITextView>())).Returns(false);

            _broker                 = _factory.Create <IDisplayWindowBroker>(MockBehavior.Loose);
            _textManager            = _factory.Create <ITextManager>();
            _vimApplicationSettings = _factory.Create <IVimApplicationSettings>();

            var commandTargets = new List <ICommandTarget>();

            if (isReSharperInstalled)
            {
                commandTargets.Add(ReSharperKeyUtil.GetOrCreate(_bufferCoordinator));
            }
            commandTargets.Add(new StandardCommandTarget(_bufferCoordinator, _textManager.Object, _broker.Object, _nextTarget.Object));

            var oldCommandFilter = _nextTarget.Object;

            _targetRaw = new VsCommandTarget(
                _bufferCoordinator,
                _textManager.Object,
                _vsAdapter.Object,
                _broker.Object,
                KeyUtil,
                _vimApplicationSettings.Object,
                _nextTarget.Object,
                commandTargets.ToReadOnlyCollectionShallow());
            _target = _targetRaw;
        }
예제 #29
0
        public VenusCommandFilter(
            TLanguageService languageService,
            IWpfTextView wpfTextView,
            ITextBuffer subjectBuffer,
            IOleCommandTarget nextCommandTarget,
            IVsEditorAdaptersFactoryService editorAdaptersFactoryService)
            : base(languageService, wpfTextView, editorAdaptersFactoryService)
        {
            Contract.ThrowIfNull(wpfTextView);
            Contract.ThrowIfNull(subjectBuffer);
            Contract.ThrowIfNull(nextCommandTarget);

            _subjectBuffer = subjectBuffer;

            // Chain in editor command handler service. It will execute all our command handlers migrated to the modern editor commanding.
            var componentModel = (IComponentModel)languageService.SystemServiceProvider.GetService(typeof(SComponentModel));
            var vsCommandHandlerServiceAdapterFactory = componentModel.GetService <IVsCommandHandlerServiceAdapterFactory>();
            var vsCommandHandlerServiceAdapter        = vsCommandHandlerServiceAdapterFactory.Create(wpfTextView, _subjectBuffer, nextCommandTarget);

            NextCommandTarget = vsCommandHandlerServiceAdapter;
        }
예제 #30
0
        private EditFilter(
            IVsTextView vsTextView,
            ITextView textView,
            IEditorOperations editorOps,
            IServiceProvider serviceProvider,
            IOleCommandTarget next
        ) {
            _vsTextView = vsTextView;
            _textView = textView;
            _editorOps = editorOps;
            _serviceProvider = serviceProvider;
            _componentModel = _serviceProvider.GetComponentModel();
            _pyService = _serviceProvider.GetPythonToolsService();
            _next = next;

            BraceMatcher.WatchBraceHighlights(textView, _componentModel);

            if (_next == null) {
                ErrorHandler.ThrowOnFailure(vsTextView.AddCommandFilter(this, out _next));
            }
        }
예제 #31
0
        private void AddCommandFilter(IVsTextView viewAdapter)
        {
            if (IsAdded)
            {
                return;
            }

            //get the view adapter from the editor factory
            IOleCommandTarget next;
            var hr = viewAdapter.AddCommandFilter(this, out next);

            if (hr == S_OK)
            {
                IsAdded = true;
                //you'll need the next target for Exec and QueryStatus
                if (next != null)
                {
                    _nextTarget = next;
                }
            }
        }
예제 #32
0
        /// <summary>
        /// Override to forward to editor or handle accordingly if supported by this tool window.
        /// </summary>
        int IOleCommandTarget.Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            int hr = OleCommandFilter.OLECMDERR_E_NOTSUPPORTED;

            if (this.VsTextView != null)
            {
                IOleCommandTarget cmdTarget = (IOleCommandTarget)VsTextView;
                hr = cmdTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
            }

            if (hr == OleCommandFilter.OLECMDERR_E_NOTSUPPORTED)
            {
                IOleCommandTarget target = this.GetService(typeof(IOleCommandTarget)) as IOleCommandTarget;
                if (target != null)
                {
                    hr = target.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
                }
            }

            return(hr);
        }
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <returns>Returns <see langword="true"/> if the command was succesfully executed; otherwise <see langword="false"/>.</returns>
        public static async Task <bool> ExecuteAsync(this CommandID cmd, string argument = "")
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IOleCommandTarget cs = await VS.GetRequiredServiceAsync <SUIHostCommandDispatcher, IOleCommandTarget>();

            int    argByteCount = Encoding.Unicode.GetByteCount(argument);
            IntPtr inArgPtr     = Marshal.AllocCoTaskMem(argByteCount);

            try
            {
                Marshal.GetNativeVariantForObject(argument, inArgPtr);
                int result = cs.Exec(cmd.Guid, (uint)cmd.ID, (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, inArgPtr, IntPtr.Zero);

                return(result == VSConstants.S_OK);
            }
            finally
            {
                Marshal.Release(inArgPtr);
            }
        }
예제 #34
0
        public IMouseProcessor GetAssociatedProcessor(IWpfTextView view)
        {
            //AsmDudeToolsStatic.Output("INFO: AsmDocMouseHandlerProvider:GetAssociatedProcessor: file=" + AsmDudeToolsStatic.GetFileName(view.TextBuffer));

            var buffer = view.TextBuffer;

            IOleCommandTarget shellCommandDispatcher = GetShellCommandDispatcher(view);

            if (shellCommandDispatcher == null)
            {
                return(null);
            }

            return(new AsmDocMouseHandler(
                       view,
                       shellCommandDispatcher,
                       this.AggregatorFactory.GetClassifier(buffer),
                       this.NavigatorService.GetTextStructureNavigator(buffer),
                       CtrlKeyState.GetStateForView(view),
                       AsmDudeTools.Instance));
        }
예제 #35
0
        public RebarController(QTTabBarClass tabbar, IntPtr hwndReBar, IOleCommandTarget bandObjectSite)
        {
            this.tabbar         = tabbar;
            this.bandObjectSite = bandObjectSite;
            ExplorerHandle      = PInvoke.GetAncestor(hwndReBar, 2);
            Handle          = hwndReBar;
            rebarController = new NativeWindowController(hwndReBar);
            rebarController.MessageCaptured += MessageCaptured;

            if (QTUtility.CheckConfig(Settings.ToolbarBGColor))
            {
                if (QTUtility.DefaultRebarCOLORREF == -1)
                {
                    QTUtility.DefaultRebarCOLORREF = (int)PInvoke.SendMessage(Handle, RB.GETBKCOLOR, IntPtr.Zero, IntPtr.Zero);
                }
                int num2 = QTUtility2.MakeCOLORREF(QTUtility.RebarBGColor);
                PInvoke.SendMessage(Handle, RB.SETBKCOLOR, IntPtr.Zero, (IntPtr)num2);
            }

            EnsureMenuBarIsCorrect();
        }
예제 #36
0
        public virtual void FreeInterfaces()
        {
            this._menuService = null;

            if (_innerOleCommandTarget != null)
            {
                if (Marshal.IsComObject(_innerOleCommandTarget))
                {
                    Marshal.ReleaseComObject(_innerOleCommandTarget);
                }
                _innerOleCommandTarget = null;
            }

            if (_innerVsAggregatableProject != null)
            {
                if (Marshal.IsComObject(_innerVsAggregatableProject))
                {
                    Marshal.ReleaseComObject(_innerVsAggregatableProject);
                }
                _innerVsAggregatableProject = null;
            }

            if (_innerVsUIHierarchy != null)
            {
                if (Marshal.IsComObject(_innerVsUIHierarchy))
                {
                    Marshal.ReleaseComObject(_innerVsUIHierarchy);
                }
                _innerVsUIHierarchy = null;
            }

            if (_innerVsHierarchy != null)
            {
                if (Marshal.IsComObject(_innerVsHierarchy))
                {
                    Marshal.ReleaseComObject(_innerVsHierarchy);
                }
                _innerVsHierarchy = null;
            }
        }
예제 #37
0
        public void FormatDocument(string filePath)
        {
            IVsTextView    vsTextView;
            IVsUIHierarchy uiHierarchy;
            uint           itemID;
            IVsWindowFrame windowFrame;

            if (VsShellUtilities.IsDocumentOpen(visualStudio.ServiceProvider, filePath, Guid.Empty, out uiHierarchy, out itemID, out windowFrame))
            {
                vsTextView = VsShellUtilities.GetTextView(windowFrame);
            }
            else
            {
                Contract.Assert(false, "Failed to get the IVsTextView, is the document open in VS?");
                return;
            }

            IOleCommandTarget commandTarget = (IOleCommandTarget)vsTextView;

            Guid guid = typeof(VSConstants.VSStd2KCmdID).GUID;

            OLECMD[] commandStatus = new OLECMD[] { new OLECMD()
                                                    {
                                                        cmdID = (uint)VSConstants.VSStd2KCmdID.FORMATDOCUMENT
                                                    } };

            int hr = commandTarget.QueryStatus(ref guid, 1, commandStatus, IntPtr.Zero);

            Marshal.ThrowExceptionForHR(hr);

            if (commandStatus[0].cmdf == (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED))
            {
                hr = commandTarget.Exec(ref guid, (uint)VSConstants.VSStd2KCmdID.FORMATDOCUMENT, 0u, IntPtr.Zero, IntPtr.Zero);
                Marshal.ThrowExceptionForHR(hr);
            }
            else
            {
                Contract.Assert(false, "The format command can't be executed right now, we don't expect this to happen.");
            }
        }
예제 #38
0
        protected VsCommandTargetTest()
        {
            _textView          = CreateTextView("");
            _textBuffer        = _textView.TextBuffer;
            _vimBuffer         = Vim.CreateVimBuffer(_textView);
            _bufferCoordinator = new VimBufferCoordinator(_vimBuffer);
            _vim     = _vimBuffer.Vim;
            _factory = new MockRepository(MockBehavior.Strict);

            // By default Resharper isn't loaded
            _resharperUtil = _factory.Create <IReSharperUtil>();
            _resharperUtil.SetupGet(x => x.IsInstalled).Returns(false);

            _nextTarget = _factory.Create <IOleCommandTarget>(MockBehavior.Strict);
            _vsAdapter  = _factory.Create <IVsAdapter>();
            _vsAdapter.SetupGet(x => x.KeyboardDevice).Returns(InputManager.Current.PrimaryKeyboardDevice);
            _vsAdapter.Setup(x => x.InAutomationFunction).Returns(false);
            _vsAdapter.Setup(x => x.InDebugMode).Returns(false);
            _vsAdapter.Setup(x => x.IsIncrementalSearchActive(It.IsAny <ITextView>())).Returns(false);

            _broker      = _factory.Create <IDisplayWindowBroker>(MockBehavior.Loose);
            _textManager = _factory.Create <ITextManager>();

            var oldCommandFilter = _nextTarget.Object;
            var vsTextView       = _factory.Create <IVsTextView>(MockBehavior.Loose);

            vsTextView.Setup(x => x.AddCommandFilter(It.IsAny <IOleCommandTarget>(), out oldCommandFilter)).Returns(0);
            var result = VsCommandTarget.Create(
                _bufferCoordinator,
                vsTextView.Object,
                _textManager.Object,
                _vsAdapter.Object,
                _broker.Object,
                _resharperUtil.Object,
                KeyUtil);

            Assert.True(result.IsSuccess);
            _targetRaw = result.Value;
            _target    = _targetRaw;
        }
예제 #39
0
        public RebarController(QTTabBarClass tabbar, IntPtr hwndReBar, IOleCommandTarget bandObjectSite)
        {
            BandObjectLib.Logging.Add_DEBUG("Constructor.log", "RebarController");
            this.tabbar         = tabbar;
            this.bandObjectSite = bandObjectSite;
            ExplorerHandle      = PInvoke.GetAncestor(hwndReBar, 2);
            Handle          = hwndReBar;
            rebarController = new NativeWindowController(hwndReBar);
            rebarController.MessageCaptured += RebarMessageCaptured;

            REBARBANDINFO structure = new REBARBANDINFO();

            structure.cbSize = Marshal.SizeOf(structure);
            structure.fMask  = RBBIM.CHILD | RBBIM.ID;
            int num = (int)PInvoke.SendMessage(Handle, RB.GETBANDCOUNT, IntPtr.Zero, IntPtr.Zero);

            for (int i = 0; i < num; i++)
            {
                PInvoke.SendMessage(Handle, RB.GETBANDINFO, (IntPtr)i, ref structure);
                if (PInvoke.GetClassName(structure.hwndChild) == "ToolbarWindow32" && structure.wID == 1)
                {
                    menuController = new NativeWindowController(structure.hwndChild);
                    menuController.MessageCaptured += MenuMessageCaptured;
                    break;
                }
            }

            if (Config.Skin.UseRebarBGColor)
            {
                if (DefaultRebarCOLORREF == -1)
                {
                    DefaultRebarCOLORREF = (int)PInvoke.SendMessage(Handle, RB.GETBKCOLOR, IntPtr.Zero, IntPtr.Zero);
                }
                int num2 = QTUtility2.MakeCOLORREF(Config.Skin.RebarColor);
                PInvoke.SendMessage(Handle, RB.SETBKCOLOR, IntPtr.Zero, (IntPtr)num2);
            }

            EnsureMenuBarIsCorrect();
        }
예제 #40
0
        /*
         * internal ICompletionBroker CompletionBroker {
         *  get {
         *      return _nsicprovider._completionbroker;
         *  }
         * }
         *
         * internal IVsEditorAdaptersFactoryService AdaptersFactory {
         *  get {
         *      return _nsicprovider._adaptersfactory;
         *  }
         * }
         *
         * internal ISignatureHelpBroker SignatureBroker {
         *  get {
         *      return _nsicprovider._signaturehelpbroker;
         *  }
         * }
         */

        public void Detach(ITextView textView)
        {
            if (_textview == null)
            {
                throw new InvalidOperationException("Already detached from text view");
            }
            if (textView != _textview)
            {
                throw new ArgumentException("Not attached to specified text view", "textView");
            }

            //_textview.MouseHover -= _textview;
            _textview.Properties.RemoveProperty(typeof(NSIntellisenseController));

            if (m_commandhandler_next != null)
            {
                ErrorHandler.ThrowOnFailure(_ivstextview.RemoveCommandFilter(this));
                m_commandhandler_next = null;
            }
            //_bufferParser = null;
            //_textdocument.DirtyStateChanged -= OnDocumentDirtyStateChanged;
        }
예제 #41
0
 /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.Dispose"]/*' />
 public virtual void Dispose()
 {
     if (this.textView != null)
     {
         Marshal.ReleaseComObject(this.textView);
         this.textView = null;
     }
     this.service = null;
     if (this.nextTarget != null)
     {
         Marshal.ReleaseComObject(this.nextTarget);
         this.nextTarget = null;
     }
     this.textTipData = null;
     this.mgr         = null;
     if (this.pvaChar != IntPtr.Zero)
     {
         Marshal.FreeCoTaskMem(pvaChar);
         pvaChar = IntPtr.Zero;
     }
     GC.SuppressFinalize(this);
 }
예제 #42
0
        public IMouseProcessor GetAssociatedProcessor(IWpfTextView view)
        {
            //AsmDudeToolsStatic.Output_INFO("AsmDocMouseHandlerProvider:GetAssociatedProcessor: file=" + AsmDudeToolsStatic.GetFileName(view.TextBuffer));

            IOleCommandTarget shellCommandDispatcher = this._globalServiceProvider.GetService(typeof(SUIHostCommandDispatcher)) as IOleCommandTarget;

            if (shellCommandDispatcher == null)
            {
                return(null);
            }
            else
            {
                var buffer = view.TextBuffer;
                return(new AsmDocMouseHandler(
                           view,
                           shellCommandDispatcher,
                           this._aggregatorFactory.GetClassifier(buffer),
                           this._navigatorService.GetTextStructureNavigator(buffer),
                           CtrlKeyState.GetStateForView(view),
                           AsmDudeTools.Instance));
            }
        }
예제 #43
0
        /// <summary>
        /// Execute a VS command on the wpfTextView CommandTarget.
        /// </summary>
        public static void Execute(this IOleCommandTarget target, Guid guidCommand, uint idCommand, object args = null)
        {
            IntPtr varIn = IntPtr.Zero;

            try {
                if (args != null)
                {
                    varIn = Marshal.AllocHGlobal(NuGetConsole.NativeMethods.VariantSize);
                    Marshal.GetNativeVariantForObject(args, varIn);
                }

                int hr = target.Exec(ref guidCommand, idCommand, (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, varIn, IntPtr.Zero);
                ErrorHandler.ThrowOnFailure(hr);
            }
            finally {
                if (varIn != IntPtr.Zero)
                {
                    NuGetConsole.NativeMethods.VariantClear(varIn);
                    Marshal.FreeHGlobal(varIn);
                }
            }
        }
예제 #44
0
        protected override bool Execute(uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut, IOleCommandTarget nextCommandTarget)
        {
            var groupId = CommandGroupId;
            if (nextCommandTarget.Exec(ref groupId, nCmdID, nCmdexecopt, pvaIn, pvaOut) == VSConstants.S_OK)
            {
                // parse the content
                var tokenizer = new RwHtmlTokenizer();
                var text = TextView.TextSnapshot.GetText();
                tokenizer.Tokenize(new StringReader(text));
                var parser = new RwHtmlParser();
                var node = parser.Parse(tokenizer.Tokens);

                // prepare the metadata control resolver
                var completionSource = TextView.TextBuffer.Properties.GetProperty<RwHtmlCompletionSource>(typeof(RwHtmlCompletionSource));
                var metadataControlResolver = completionSource.MetadataControlResolver;
                metadataControlResolver.ReloadAllControls(completionSource.GetCompletionContext());

                try
                {
                    CompletionHelper.DTE.UndoContext.Open("Format RWHTML document");
                    var edit = TextView.TextBuffer.CreateEdit(EditOptions.None, null, null);

                    // fix the casing of all elements
                    var editText = new StringBuilder(text);
                    foreach (var element in node.EnumerateNodes().OfType<RwHtmlElementNode>())
                    {
                        FixElement(editText, metadataControlResolver, TextView.TextBuffer, element);
                    }
                    edit.Replace(0, editText.Length, editText.ToString());
                    edit.Apply();
                }
                finally
                {
                    CompletionHelper.DTE.UndoContext.Close();
                }
            }

            return true;
        }
예제 #45
0
        public GoToDefMouseHandler(IWpfTextView view, IOleCommandTarget commandTarget, IClassifier aggregator,
                                   ITextStructureNavigator navigator, CtrlKeyState state)
        {
            _view = view;
            _commandTarget = commandTarget;
            _state = state;
            _aggregator = aggregator;
            _navigator = navigator;

            _state.CtrlKeyStateChanged += (sender, args) =>
            {
                if (_state.Enabled)
                    this.TryHighlightItemUnderMouse(RelativeToView(Mouse.PrimaryDevice.GetPosition(_view.VisualElement)));
                else
                    this.SetHighlightSpan(null);
            };

            // Some other points to clear the highlight span:

            _view.LostAggregateFocus += (sender, args) => this.SetHighlightSpan(null);
            _view.VisualElement.MouseLeave += (sender, args) => this.SetHighlightSpan(null);
        }
예제 #46
0
        protected VsCommandTargetTest(bool isReSharperInstalled)
        {
            _textView = CreateTextView("");
            _textBuffer = _textView.TextBuffer;
            _vimBuffer = Vim.CreateVimBuffer(_textView);
            _bufferCoordinator = new VimBufferCoordinator(_vimBuffer);
            _vim = _vimBuffer.Vim;
            _factory = new MockRepository(MockBehavior.Strict);

            _nextTarget = _factory.Create<IOleCommandTarget>(MockBehavior.Strict);
            _vsAdapter = _factory.Create<IVsAdapter>();
            _vsAdapter.SetupGet(x => x.KeyboardDevice).Returns(InputManager.Current.PrimaryKeyboardDevice);
            _vsAdapter.Setup(x => x.InAutomationFunction).Returns(false);
            _vsAdapter.Setup(x => x.InDebugMode).Returns(false);
            _vsAdapter.Setup(x => x.IsIncrementalSearchActive(It.IsAny<ITextView>())).Returns(false);

            _broker = _factory.Create<IDisplayWindowBroker>(MockBehavior.Loose);
            _textManager = _factory.Create<ITextManager>();
            _vimApplicationSettings = _factory.Create<IVimApplicationSettings>();

            var commandTargets = new List<ICommandTarget>();
            if (isReSharperInstalled)
            {
                commandTargets.Add(ReSharperKeyUtil.GetOrCreate(_bufferCoordinator));
            }
            commandTargets.Add(new StandardCommandTarget(_bufferCoordinator, _textManager.Object, _broker.Object, _nextTarget.Object));

            var oldCommandFilter = _nextTarget.Object;
            _targetRaw = new VsCommandTarget(
                _bufferCoordinator,
                _textManager.Object,
                _vsAdapter.Object,
                _broker.Object,
                KeyUtil,
                _vimApplicationSettings.Object,
                _nextTarget.Object,
                commandTargets.ToReadOnlyCollectionShallow());
            _target = _targetRaw;
        }
예제 #47
0
        public bool OleCommandExec(bool bTopLevel, MSHTML_COMMAND_IDS CmdID, IHTMLDocument2 doc2)
        {
            IOleCommandTarget m_Doc2OleCommandTraget = null;
            IntPtr            m_Guid_MSHTML          = m_NullPointer;
            bool bret = false;

            try
            {
                byte[] guidbytes = Iid_Clsids.Guid_MSHTML.ToByteArray();
                m_Guid_MSHTML = Marshal.AllocCoTaskMem((int)(guidbytes.Length * 2));
                Marshal.Copy(guidbytes, 0, m_Guid_MSHTML, guidbytes.Length);

                if (doc2 == null)
                {
                    return(false);
                }
                m_Doc2OleCommandTraget = doc2 as IOleCommandTarget;
                if (m_Doc2OleCommandTraget == null)
                {
                    return(false);
                }

                bret = (m_Doc2OleCommandTraget.Exec(m_Guid_MSHTML, (uint)CmdID,
                                                    (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT,
                                                    m_NullPointer, m_NullPointer) == Hresults.S_OK) ? true : false;

                Marshal.FreeCoTaskMem(m_Guid_MSHTML);
                m_Guid_MSHTML = m_NullPointer;
            }
            finally
            {
                if (m_Guid_MSHTML != m_NullPointer)
                {
                    Marshal.FreeCoTaskMem(m_Guid_MSHTML);
                }
            }
            return(bret);
        }
예제 #48
0
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            int hr = VSErr.OLECMDERR_E_NOTSUPPORTED;

            foreach (IOleCommandTarget target in _targets)
            {
                hr = target.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);

                if (hr != VSErr.OLECMDERR_E_NOTSUPPORTED && hr != VSErr.OLECMDERR_E_UNKNOWNGROUP)
                {
                    return(hr);
                }
            }

            IOleCommandTarget t = BaseTarget;

            if (t != null)
            {
                hr = t.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
            }

            return(hr);
        }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            foreach (IOleCommandTarget target in _targets)
            {
                int hr = target.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);

                if (hr != VSErr.OLECMDERR_E_NOTSUPPORTED && hr != VSErr.OLECMDERR_E_UNKNOWNGROUP)
                {
                    return(hr);
                }
            }

            IOleCommandTarget t = _baseTarget ?? (_baseTarget = (IOleCommandTarget)_pane.BaseGetService(typeof(IOleCommandTarget)));

            if (t != null)
            {
                return(t.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }
            else
            {
                return(VSErr.OLECMDERR_E_NOTSUPPORTED);
            }
        }
        public int GetTextViewFilter(
            IVsIntellisenseHost intellisenseHost,
            IOleCommandTarget nextCmdTarget,
            out IVsTextViewFilter textViewFilter
            )
        {
            var wpfTextView = GetViewFromIVsIntellisenseHost(intellisenseHost);

            if (wpfTextView == null)
            {
                textViewFilter = null;
                return(VSConstants.E_FAIL);
            }

            textViewFilter = new VenusCommandFilter(
                wpfTextView,
                SubjectBuffer,
                nextCmdTarget,
                ComponentModel
                );

            return(VSConstants.S_OK);
        }
예제 #51
0
        public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
        {
            int hr = VSErr.OLECMDERR_E_NOTSUPPORTED;

            foreach (IOleCommandTarget target in _targets)
            {
                hr = target.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);

                if (hr != VSErr.OLECMDERR_E_NOTSUPPORTED && hr != VSErr.OLECMDERR_E_UNKNOWNGROUP)
                {
                    return(hr);
                }
            }

            IOleCommandTarget t = BaseTarget;

            if (t != null)
            {
                hr = t.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
            }

            return(hr);
        }
예제 #52
0
        protected override void OnCreate()
        {
            var controller      = new AsyncCommandController();
            var visualComponent = new RPlotDeviceVisualComponent(_plotManager, controller, _instanceId, this, _coreShell);
            var commands        = new RPlotDeviceCommands(_plotManager.InteractiveWorkflow, visualComponent);

            controller.AddCommand(RGuidList.RCmdSetGuid, RPackageCommandId.icmdActivatePlotWindow, commands.ActivatePlotDevice);
            controller.AddCommand(RGuidList.RCmdSetGuid, RPackageCommandId.icmdClearPlots, commands.RemoveAllPlots);
            controller.AddCommand(RGuidList.RCmdSetGuid, RPackageCommandId.icmdRemovePlot, commands.RemoveCurrentPlot);
            controller.AddCommand(RGuidList.RCmdSetGuid, RPackageCommandId.icmdNextPlot, commands.NextPlot);
            controller.AddCommand(RGuidList.RCmdSetGuid, RPackageCommandId.icmdPrevPlot, commands.PreviousPlot);
            controller.AddCommand(RGuidList.RCmdSetGuid, RPackageCommandId.icmdExportPlotAsImage, commands.ExportAsImage);
            controller.AddCommand(RGuidList.RCmdSetGuid, RPackageCommandId.icmdExportPlotAsPdf, commands.ExportAsPdf);
            controller.AddCommand(VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.Copy, commands.Copy);
            controller.AddCommand(VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.Cut, commands.Cut);
            controller.AddCommand(VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.Paste, commands.Paste);
            controller.AddCommand(RGuidList.RCmdSetGuid, RPackageCommandId.icmdCopyPlotAsBitmap, commands.CopyAsBitmap);
            controller.AddCommand(RGuidList.RCmdSetGuid, RPackageCommandId.icmdCopyPlotAsMetafile, commands.CopyAsMetafile);
            controller.AddCommand(RGuidList.RCmdSetGuid, RPackageCommandId.icmdEndLocator, commands.EndLocator);
            Component = visualComponent;
            _plotManager.RegisterVisualComponent(Component);
            _commandTarget = new CommandTargetToOleShim(null, Component.Controller);
            base.OnCreate();
        }
예제 #53
0
        public static ReplEditFilter GetOrCreate(
            IServiceProvider serviceProvider,
            IComponentModel componentModel,
            IVsTextView vsTextView,
            IOleCommandTarget next = null
            )
        {
            var editorFactory = componentModel.GetService <IVsEditorAdaptersFactoryService>();
            var opsFactory    = componentModel.GetService <IEditorOperationsFactoryService>();
            var textView      = editorFactory.GetWpfTextView(vsTextView);

            if (textView.TextBuffer.GetInteractiveWindow() == null)
            {
                return(null);
            }

            return(textView.Properties.GetOrCreateSingletonProperty(() => new ReplEditFilter(
                                                                        vsTextView,
                                                                        textView,
                                                                        opsFactory.GetEditorOperations(textView),
                                                                        serviceProvider,
                                                                        next
                                                                        )));
        }
        public IMouseProcessor GetAssociatedProcessor(IWpfTextView view)
        {
            if (App.OptionsPage?.DisableShiftClick == null)
            {
                return(null);
            }

            var buffer = view.TextBuffer;

            IOleCommandTarget shellCommandDispatcher = GetShellCommandDispatcher(view);

            if (shellCommandDispatcher == null)
            {
                return(null);
            }

            return(new GoToModuleMouseHandler(
                       (DTE2)GlobalServiceProvider.GetService(typeof(SDTE)),
                       view,
                       shellCommandDispatcher,
                       AggregatorFactory.GetClassifier(buffer),
                       NavigatorService.GetTextStructureNavigator(buffer),
                       CtrlKeyState.GetStateForView(view)));
        }
예제 #55
0
        public VenusCommandFilter(
            IWpfTextView wpfTextView,
            ITextBuffer subjectBuffer,
            IOleCommandTarget nextCommandTarget,
            IComponentModel componentModel
            ) : base(wpfTextView, componentModel)
        {
            Contract.ThrowIfNull(wpfTextView);
            Contract.ThrowIfNull(subjectBuffer);
            Contract.ThrowIfNull(nextCommandTarget);

            _subjectBuffer = subjectBuffer;

            // Chain in editor command handler service. It will execute all our command handlers migrated to the modern editor commanding.
            var vsCommandHandlerServiceAdapterFactory =
                componentModel.GetService <IVsCommandHandlerServiceAdapterFactory>();
            var vsCommandHandlerServiceAdapter = vsCommandHandlerServiceAdapterFactory.Create(
                wpfTextView,
                _subjectBuffer,
                nextCommandTarget
                );

            NextCommandTarget = vsCommandHandlerServiceAdapter;
        }
예제 #56
0
        private void CreateHostedEditor()
        {
            //Get the component model so we can request the editor adapter factory which we can use to spin up an editor instance.
            IComponentModel componentModel = (IComponentModel)ServiceProvider.GlobalProvider.GetService(typeof(SComponentModel));

            IContentTypeRegistryService contentTypeRegistry = componentModel.GetService <IContentTypeRegistryService>();
            IContentType contentType = contentTypeRegistry.GetContentType("CSharp");

            IVsEditorAdaptersFactoryService editorAdapterFactory = componentModel.GetService <IVsEditorAdaptersFactoryService>();

            this.textBuffer = editorAdapterFactory.CreateVsTextBufferAdapter(OleServiceProvider);
            Guid CSharpLanguageService = new Guid("{694DD9B6-B865-4C5B-AD85-86356E9C88DC}");

            ErrorHandler.ThrowOnFailure(textBuffer.SetLanguageServiceID(ref CSharpLanguageService));

            string initialContents = String.Format("using System;{0}{0}namespace Lazers{0}{{{0}{1}public class Awesome{0}{1}{{{0}{1}}}{0}}}", Environment.NewLine, "    ");

            ErrorHandler.ThrowOnFailure(textBuffer.InitializeContent(initialContents, initialContents.Length));

            //Disable the splitter due to a crashing bug if we don't :(
            this.codeWindow = editorAdapterFactory.CreateVsCodeWindowAdapter(OleServiceProvider);
            ((IVsCodeWindowEx)this.codeWindow).Initialize((uint)_codewindowbehaviorflags.CWB_DISABLESPLITTER,
                                                          VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter,
                                                          "",
                                                          "",
                                                          0,
                                                          new INITVIEW[1]);

            this.codeWindow.SetBuffer((IVsTextLines)this.textBuffer);

            ErrorHandler.ThrowOnFailure(this.codeWindow.GetPrimaryView(out this.textView));
            this.textViewHost = editorAdapterFactory.GetWpfTextViewHost(this.textView);

            this.Content             = textViewHost.HostControl;
            this.editorCommandTarget = (IOleCommandTarget)this.textView;
        }
예제 #57
0
        private ReplEditFilter(
            IVsTextView vsTextView,
            ITextView textView,
            IEditorOperations editorOps,
            IServiceProvider serviceProvider,
            IOleCommandTarget next
        ) {
            _vsTextView = vsTextView;
            _textView = textView;
            _editorOps = editorOps;
            _serviceProvider = serviceProvider;
            _componentModel = _serviceProvider.GetComponentModel();
            _pyService = _serviceProvider.GetPythonToolsService();
            _interactive = _textView.TextBuffer.GetInteractiveWindow();
            _next = next;

            if (_interactive != null) {
                _selectEval = _interactive.Evaluator as SelectableReplEvaluator;
            }

            if (_selectEval != null) {
                _selectEval.EvaluatorChanged += EvaluatorChanged;
                _selectEval.AvailableEvaluatorsChanged += AvailableEvaluatorsChanged;
            }

            var mse = _interactive?.Evaluator as IMultipleScopeEvaluator;
            if (mse != null) {
                _scopeListVisible = mse.EnableMultipleScopes;
                mse.AvailableScopesChanged += AvailableScopesChanged;
                mse.MultipleScopeSupportChanged += MultipleScopeSupportChanged;
            }

            if (_next == null && _interactive != null) {
                ErrorHandler.ThrowOnFailure(vsTextView.AddCommandFilter(this, out _next));
            }
        }
        /// <summary>
        /// Checks if a command is enabled and supported.
        /// </summary>
        public static async Task <bool> IsAvailableAsync(this CommandID cmd)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IOleCommandTarget cs = await VS.GetRequiredServiceAsync <SUIHostCommandDispatcher, IOleCommandTarget>();

            Guid guid = cmd.Guid;

            OLECMD[]? cmds = new OLECMD[1];
            cmds[0].cmdID  = (uint)cmd.ID;
            cmds[0].cmdf   = 0;

            int hr = cs.QueryStatus(ref guid, (uint)cmds.Length, cmds, IntPtr.Zero);

            if (ErrorHandler.Succeeded(hr))
            {
                if (((OLECMDF)cmds[0].cmdf).HasFlag(OLECMDF.OLECMDF_ENABLED))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #59
0
 public int ShowUI(int dwID, IOleInPlaceActiveObject activeObject,
                   IOleCommandTarget commandTarget, IOleInPlaceFrame frame, IOleInPlaceUIWindow doc)
 {
     //Debug.WriteLine("ShowUI");
     return(HRESULT.S_OK);
 }
예제 #60
0
 public void AddCommandTarget(IOleCommandTarget target)
 {
     _pane.AddCommandTarget(target);
 }