Exemplo n.º 1
0
        private bool IsViewOnScreen(ITextView view)
        {
            Contract.Requires <ArgumentNullException>(view != null, "view");

            IVsTextView      viewAdapter = VsEditorAdaptersFactoryService.GetViewAdapter(view);
            IServiceProvider sp          = viewAdapter as IServiceProvider;

            if (sp == null)
            {
                return(false);
            }

            IVsWindowFrame frame = sp.GetService(typeof(SVsWindowFrame)) as IVsWindowFrame;

            if (frame == null)
            {
                return(false);
            }

            int onScreen = 0;

            if (ErrorHandler.Succeeded(ErrorHandler.CallWithCOMConvention(() => frame.IsOnScreen(out onScreen))))
            {
                return(onScreen != 0);
            }

            return(false);
        }
Exemplo n.º 2
0
        int IVsCodeWindowEvents.OnCloseView(IVsTextView vsTextView)
        {
            var wpfTextView = VsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);

            if (wpfTextView != null)
            {
                wpfTextView.GotAggregateFocus -= OnTextViewGotAggregateFocus;
            }
            return(VSConstants.S_OK);
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            ITextView textView = VsEditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            if (textView == null)
            {
                return;
            }

            Func <SpringCompletionController> controllerCreator = delegate() { return(new SpringCompletionController(ServiceProvider, textViewAdapter, textView, CompletionBroker, TextStructureNavigatorSelectorService)); };

            textView.Properties.GetOrCreateSingletonProperty(controllerCreator);
        }
Exemplo n.º 4
0
        int IVsCodeWindowEvents.OnNewView(IVsTextView vsTextView)
        {
            var wpfTextView = VsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);

            if (wpfTextView != null)
            {
                var factory    = ComponentModel.GetService <IEditorOperationsFactoryService>();
                var editFilter = new EditFilter(wpfTextView, factory.GetEditorOperations(wpfTextView), ServiceProvider.GlobalProvider);
                editFilter.AttachKeyboardFilter(vsTextView);
                wpfTextView.GotAggregateFocus  += OnTextViewGotAggregateFocus;
                wpfTextView.LostAggregateFocus += OnTextViewLostAggregateFocus;
            }
            return(VSConstants.S_OK);
        }
Exemplo n.º 5
0
        int IVsCodeWindowEvents.OnNewView(IVsTextView vsTextView)
        {
            _viewCount++;
            var wpfTextView = VsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);

            if (wpfTextView != null)
            {
                var factory = ComponentModel.GetService <IEditorOperationsFactoryService>();
                EditFilter.GetOrCreate(_serviceProvider, ComponentModel, vsTextView);
                new TextViewFilter(_serviceProvider, vsTextView);
                wpfTextView.GotAggregateFocus  += OnTextViewGotAggregateFocus;
                wpfTextView.LostAggregateFocus += OnTextViewLostAggregateFocus;
            }
            return(VSConstants.S_OK);
        }
Exemplo n.º 6
0
        int IVsCodeWindowEvents.OnNewView(IVsTextView vsTextView)
        {
            _viewCount++;
            var wpfTextView = VsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);

            if (wpfTextView != null)
            {
                var services = ComponentModel.GetService <PythonEditorServices>();
                EditFilter.GetOrCreate(services, vsTextView);
                new TextViewFilter(services, vsTextView);
                wpfTextView.GotAggregateFocus  += OnTextViewGotAggregateFocus;
                wpfTextView.LostAggregateFocus += OnTextViewLostAggregateFocus;
            }
            return(VSConstants.S_OK);
        }
Exemplo n.º 7
0
        int IVsCodeWindowEvents.OnNewView(IVsTextView vsTextView)
        {
            var wpfTextView = VsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);

            if (wpfTextView != null)
            {
                var factory = BabePackage.ComponentModel.GetService <IEditorOperationsFactoryService>();
//                var editFilter = new EditFilter(wpfTextView, factory.GetEditorOperations(wpfTextView));
//                editFilter.AttachKeyboardFilter(vsTextView);
#if DEV11_OR_LATER
                new TextViewFilter(vsTextView);
#endif
                wpfTextView.GotAggregateFocus += OnTextViewGotAggregateFocus;
            }
            return(VSConstants.S_OK);
        }
Exemplo n.º 8
0
        int IVsCodeWindowEvents.OnCloseView(IVsTextView vsTextView)
        {
            _viewCount--;
            if (_viewCount == 0)
            {
                _pyService.CodeWindowClosed(_window);
            }
            _pyService.OnIdle -= OnIdle;
            var wpfTextView = VsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);

            if (wpfTextView != null)
            {
                wpfTextView.GotAggregateFocus  -= OnTextViewGotAggregateFocus;
                wpfTextView.LostAggregateFocus -= OnTextViewLostAggregateFocus;
            }
            return(VSConstants.S_OK);
        }
Exemplo n.º 9
0
        private int AddDropDownBar(bool refresh)
        {
            var cpc = (IConnectionPointContainer)_window;

            if (cpc != null)
            {
                IConnectionPoint cp;
                cpc.FindConnectionPoint(typeof(IVsCodeWindowEvents).GUID, out cp);
                if (cp != null)
                {
                    cp.Advise(this, out _cookieVsCodeWindowEvents);
                }
            }

            IWpfTextView wpfTextView = null;
            IVsTextView  vsTextView;

            if (ErrorHandler.Succeeded(_window.GetLastActiveView(out vsTextView)) && vsTextView != null)
            {
                wpfTextView = VsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);
            }
            if (wpfTextView == null)
            {
                return(VSConstants.E_FAIL);
            }

            _client = new DropDownBarClient(_serviceProvider, wpfTextView);
            var result = _client.Register((IVsDropdownBarManager)_window);

            if (refresh)
            {
                var entry = wpfTextView.TryGetAnalysisEntry(_serviceProvider);
                if (entry != null && entry.IsAnalyzed)
                {
                    _client.RefreshNavigationsFromAnalysisEntry(entry)
                    .HandleAllExceptions(_serviceProvider, GetType())
                    .DoNotWait();
                }
            }

            return(result);
        }
Exemplo n.º 10
0
        private bool TryGetTextView(IVsTextView vsTextView, out IWpfTextView view)
        {
            if (vsTextView == null)
            {
                view = null;
                return(false);
            }
            view = VsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);
            if (view == null)
            {
                return(false);
            }

            if (view.TextBuffer.ContentType.IsOfType(CodeRemoteContentDefinition.CodeRemoteContentTypeName))
            {
                // This is not really our text view
                view = null;
                return(false);
            }

            return(true);
        }
Exemplo n.º 11
0
        private int AddDropDownBar()
        {
            var cpc = (IConnectionPointContainer)_window;

            if (cpc != null)
            {
                IConnectionPoint cp;
                cpc.FindConnectionPoint(typeof(IVsCodeWindowEvents).GUID, out cp);
                if (cp != null)
                {
                    cp.Advise(this, out _cookieVsCodeWindowEvents);
                }
            }

            IWpfTextView wpfTextView = null;
            IVsTextView  vsTextView;

            if (ErrorHandler.Succeeded(_window.GetLastActiveView(out vsTextView)) && vsTextView != null)
            {
                wpfTextView = VsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);
            }
            if (wpfTextView == null)
            {
                return(VSConstants.E_FAIL);
            }

            AnalysisEntry entry;
            var           entryService = _serviceProvider.GetEntryService();

            if (entryService == null || !entryService.TryGetAnalysisEntry(wpfTextView, wpfTextView.TextBuffer, out entry))
            {
                return(VSConstants.E_FAIL);
            }

            _client = new DropDownBarClient(_serviceProvider, wpfTextView, entry);
            return(_client.Register((IVsDropdownBarManager)_window));
        }
Exemplo n.º 12
0
        private int AddDropDownBar()
        {
            var cpc = (IConnectionPointContainer)_window;

            if (cpc != null)
            {
                IConnectionPoint cp;
                cpc.FindConnectionPoint(typeof(IVsCodeWindowEvents).GUID, out cp);
                if (cp != null)
                {
                    cp.Advise(this, out _cookieVsCodeWindowEvents);
                }
            }

            IPythonProjectEntry pythonProjectEntry;

            if (!_textBuffer.TryGetPythonProjectEntry(out pythonProjectEntry))
            {
                return(VSConstants.E_FAIL);
            }

            IWpfTextView wpfTextView = null;
            IVsTextView  vsTextView;

            if (ErrorHandler.Succeeded(_window.GetLastActiveView(out vsTextView)) && vsTextView != null)
            {
                wpfTextView = VsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);
            }
            if (wpfTextView == null)
            {
                return(VSConstants.E_FAIL);
            }

            _client = new DropDownBarClient(_serviceProvider, wpfTextView, pythonProjectEntry);

            IVsDropdownBarManager manager = (IVsDropdownBarManager)_window;

            IVsDropdownBar dropDownBar;
            int            hr = manager.GetDropdownBar(out dropDownBar);

            if (ErrorHandler.Succeeded(hr) && dropDownBar != null)
            {
                hr = manager.RemoveDropdownBar();
                if (!ErrorHandler.Succeeded(hr))
                {
                    return(hr);
                }
            }

            int res = manager.AddDropdownBar(2, _client);

            if (ErrorHandler.Succeeded(res))
            {
                // A buffer may have multiple DropDownBarClients, given one may open multiple CodeWindows
                // over a single buffer using Window/New Window
                List <DropDownBarClient> listDropDownBarClient;
                if (!_textBuffer.Properties.TryGetProperty(typeof(DropDownBarClient), out listDropDownBarClient) || listDropDownBarClient == null)
                {
                    listDropDownBarClient = new List <DropDownBarClient>();
                    _textBuffer.Properties[typeof(DropDownBarClient)] = listDropDownBarClient;
                }
                listDropDownBarClient.Add(_client);
            }
            return(res);
        }
Exemplo n.º 13
0
        private int AddDropDownBar()
        {
            var cpc = (IConnectionPointContainer)_window;

            if (cpc != null)
            {
                IConnectionPoint cp;
                cpc.FindConnectionPoint(typeof(IVsCodeWindowEvents).GUID, out cp);
                if (cp != null)
                {
                    cp.Advise(this, out _cookieVsCodeWindowEvents);
                }
            }

            var pythonProjectEntry = _textBuffer.GetAnalysis() as IGeneroProjectEntry;

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

            IWpfTextView wpfTextView = null;
            IVsTextView  vsTextView;

            if (ErrorHandler.Succeeded(_window.GetLastActiveView(out vsTextView)) && vsTextView != null)
            {
                wpfTextView = VsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);
            }
            if (wpfTextView == null)
            {
                return(VSConstants.E_FAIL);
            }

            // pass on the text view
            //GeneroFileParserManager fpm = VSGeneroPackage.Instance.UpdateBufferFileParserManager(_textBuffer);
            _client = new DropDownBarClient(wpfTextView, pythonProjectEntry);

            IVsDropdownBarManager manager = (IVsDropdownBarManager)_window;

            int instancesOpen = 0;

            if (!_textBuffer.Properties.TryGetProperty <int>("InstancesOpen", out instancesOpen))
            {
                _textBuffer.Properties.AddProperty("InstancesOpen", 1);
            }
            else
            {
                _textBuffer.Properties["InstancesOpen"] = instancesOpen + 1;
            }

            IVsDropdownBar dropDownBar;
            int            hr = manager.GetDropdownBar(out dropDownBar);

            if (ErrorHandler.Succeeded(hr) && dropDownBar != null)
            {
                hr = manager.RemoveDropdownBar();
                if (!ErrorHandler.Succeeded(hr))
                {
                    return(hr);
                }
            }

            int res = manager.AddDropdownBar(1, _client);

            if (ErrorHandler.Succeeded(res))
            {
                // A buffer may have multiple DropDownBarClients, given one may open multiple CodeWindows
                // over a single buffer using Window/New Window
                List <DropDownBarClient> listDropDownBarClient;
                if (!_textBuffer.Properties.TryGetProperty(typeof(DropDownBarClient), out listDropDownBarClient) || listDropDownBarClient == null)
                {
                    listDropDownBarClient = new List <DropDownBarClient>();
                    _textBuffer.Properties[typeof(DropDownBarClient)] = listDropDownBarClient;
                }
                listDropDownBarClient.Add(_client);
            }
            return(res);
        }