void IVsTextViewEvents.OnSetFocus(IVsTextView pView)
        {
            IWpfTextView textView = pView != null?_editorAdaptersFactory.GetWpfTextView(pView) : null;

            if (textView == _currentTextView)
            {
                IVsTextView activeView = _codeWindow.GetLastActiveView();
                if (activeView != pView)
                {
                    return;
                }

                return;
            }

            if (_currentTextView != null)
            {
                _currentTextView.Caret.PositionChanged -= OnCaretPositionChanged;
            }

            _currentTextView = textView;

            if (_currentTextView != null)
            {
                _currentTextView.Caret.PositionChanged += OnCaretPositionChanged;
                foreach (var source in this._sources)
                {
                    UpdateNavigationTargets(source);
                }
            }
        }
Example #2
0
        ITextView INavigationBarPresenter.TryGetCurrentView()
        {
            IVsTextView lastActiveView;

            _codeWindow.GetLastActiveView(out lastActiveView);
            return(_editorAdaptersFactoryService.GetWpfTextView(lastActiveView));
        }
Example #3
0
        public static IVsTextView GetIvsTextView(IServiceProvider provider)
        {
            IVsMonitorSelection selection = provider.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection;
            object frameObj = null;

            ErrorHandler.ThrowOnFailure(selection.GetCurrentElementValue((uint)VSConstants.VSSELELEMID.SEID_DocumentFrame, out frameObj));

            IVsWindowFrame frame = frameObj as IVsWindowFrame;

            if (frame == null)
            {
            }

            object pvar;

            ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView,
                                                          out pvar));

            IVsTextView textView = pvar as IVsTextView;

            if (textView == null)
            {
                IVsCodeWindow codeWin = pvar as IVsCodeWindow;
                if (codeWin != null)
                {
                    ErrorHandler.ThrowOnFailure(codeWin.GetLastActiveView(out textView));
                }
            }
            return(textView);
        }
Example #4
0
        public static IVsTextView GetLastActiveView(this IVsCodeWindow codeWindow)
        {
            IVsTextView view;

            if (ErrorHandler.Failed(codeWindow.GetLastActiveView(out view)))
            {
                return(null);
            }

            return(view);
        }
Example #5
0
        public int GetLastActiveView(out IVsTextView ppView)
        {
            IVsCodeWindow vsCodeWindow = SourceCodeWindow;

            if (vsCodeWindow != null)
            {
                return(vsCodeWindow.GetLastActiveView(out ppView));
            }
            ppView = null;
            return(VSConstants.E_NOTIMPL);
        }
Example #6
0
        /// <summary>
        /// Get the last active view of the code window.
        /// </summary>
        public static Result <IVsTextView> GetLastActiveView(this IVsCodeWindow vsCodeWindow)
        {
            IVsTextView vsTextView;
            var         hr = vsCodeWindow.GetLastActiveView(out vsTextView);

            if (ErrorHandler.Failed(hr))
            {
                return(Result.CreateError(hr));
            }

            return(Result.CreateSuccessNonNull(vsTextView));
        }
        public static IVsTextView GetLastActiveView(this IVsCodeWindow codeWindow)
        {
            Contract.Requires <ArgumentNullException>(codeWindow != null, "codeWindow");

            IVsTextView view;

            if (ErrorHandler.Failed(codeWindow.GetLastActiveView(out view)))
            {
                return(null);
            }

            return(view);
        }
Example #8
0
        public static IVsTextView GetLastActiveView([NotNull] this IVsCodeWindow codeWindow)
        {
            Requires.NotNull(codeWindow, nameof(codeWindow));

            IVsTextView view;

            if (ErrorHandler.Failed(codeWindow.GetLastActiveView(out view)))
            {
                return(null);
            }

            return(view);
        }
Example #9
0
        public EditorNavigationDropdownBarClient(IVsCodeWindow codeWindow, IVsEditorAdaptersFactoryService editorAdaptersFactory, EditorNavigationSource source, IBufferGraphFactoryService bufferGraphFactoryService)
        {
            _codeWindow            = codeWindow;
            _editorAdaptersFactory = editorAdaptersFactory;
            _source = source;
            _bufferGraphFactoryService = bufferGraphFactoryService;
            _currentTextView           = editorAdaptersFactory.GetWpfTextView(codeWindow.GetLastActiveView());
            _dispatcher = _currentTextView.VisualElement.Dispatcher;
            _imageList  = new ImageList
            {
                ColorDepth = ColorDepth.Depth32Bit
            };

            var connectionPointContainer = codeWindow as IConnectionPointContainer;

            if (connectionPointContainer != null)
            {
                var textViewEventsGuid = typeof(IVsCodeWindowEvents).GUID;
                IConnectionPoint connectionPoint;
                connectionPointContainer.FindConnectionPoint(ref textViewEventsGuid, out connectionPoint);
                connectionPoint?.Advise(this, out _codeWindowEventsCookie);
            }

            var primaryView = codeWindow.GetPrimaryView();

            if (primaryView != null)
            {
                ((IVsCodeWindowEvents)this).OnNewView(primaryView);
            }

            var secondaryView = codeWindow.GetSecondaryView();

            if (secondaryView != null)
            {
                ((IVsCodeWindowEvents)this).OnNewView(secondaryView);
            }

            _navigationItems = new List <EditorTypeNavigationTarget>();

            source.NavigationTargetsChanged += OnNavigationTargetsChanged;
            UpdateNavigationTargets();

            _currentTextView.Caret.PositionChanged += OnCaretPositionChanged;
        }
Example #10
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);
        }
        private IVsTextView GetTextViewFromFrame(IVsWindowFrame frame)
        {
            // Get the document view from the window frame, then get the text view
            object docView;
            int    hr = frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView);

            if ((hr != 0 && hr != 1) || docView == null)
            {
                return(null);
            }

            IVsCodeWindow codeWindow = docView as IVsCodeWindow;
            IVsTextView   textView;

            codeWindow.GetLastActiveView(out textView);
            if (textView == null)
            {
                codeWindow.GetPrimaryView(out textView);
            }

            return(textView);
        }
Example #12
0
        private static IVsTextView GetActiveView(IVsWindowFrame windowFrame)
        {
            if (windowFrame == null)
            {
                throw new ArgumentException("windowFrame");
            }

            object pvar;

            ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out pvar));

            IVsTextView textView = pvar as IVsTextView;

            if (textView == null)
            {
                IVsCodeWindow codeWin = pvar as IVsCodeWindow;
                if (codeWin != null)
                {
                    ErrorHandler.ThrowOnFailure(codeWin.GetLastActiveView(out textView));
                }
            }
            return(textView);
        }
        public EditorNavigationDropdownBarClient(IVsCodeWindow codeWindow, IVsEditorAdaptersFactoryService editorAdaptersFactory, EditorNavigationSource source, IBufferGraphFactoryService bufferGraphFactoryService)
        {
            _codeWindow = codeWindow;
            _editorAdaptersFactory = editorAdaptersFactory;
            _source = source;
            _bufferGraphFactoryService = bufferGraphFactoryService;
            _currentTextView = editorAdaptersFactory.GetWpfTextView(codeWindow.GetLastActiveView());
            _dispatcher = _currentTextView.VisualElement.Dispatcher;
            _imageList = new ImageList
            {
                ColorDepth = ColorDepth.Depth32Bit
            };

            var connectionPointContainer = codeWindow as IConnectionPointContainer;
            if (connectionPointContainer != null)
            {
                var textViewEventsGuid = typeof(IVsCodeWindowEvents).GUID;
                IConnectionPoint connectionPoint;
                connectionPointContainer.FindConnectionPoint(ref textViewEventsGuid, out connectionPoint);
                connectionPoint?.Advise(this, out _codeWindowEventsCookie);
            }

            var primaryView = codeWindow.GetPrimaryView();
            if (primaryView != null)
                ((IVsCodeWindowEvents)this).OnNewView(primaryView);

            var secondaryView = codeWindow.GetSecondaryView();
            if (secondaryView != null)
                ((IVsCodeWindowEvents)this).OnNewView(secondaryView);

            _navigationItems = new List<EditorTypeNavigationTarget>();

            source.NavigationTargetsChanged += OnNavigationTargetsChanged;
            UpdateNavigationTargets();

            _currentTextView.Caret.PositionChanged += OnCaretPositionChanged;
        }
Example #14
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));
        }
        public static bool OpenFile(IVsUIShellOpenDocument open_document, IVsEditorAdaptersFactoryService adapters_factory, string full_path, int start, int length)
        {
            // 判断文件是否存在
            if (!File.Exists(full_path))
            {
                return(false);
            }

            if (open_document == null)
            {
                open_document = s_service_provider.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
            }
            if (open_document == null)
            {
                return(false);
            }

            // 打开文档
            IVsUIHierarchy project;
            uint           item_id;
            IVsWindowFrame frame;

            Microsoft.VisualStudio.OLE.Interop.IServiceProvider provider;
            open_document.OpenDocumentViaProject(full_path, VSConstants.LOGVIEWID.TextView_guid
                                                 , out provider, out project, out item_id, out frame);
            if (frame == null)
            {
                return(false);
            }

            // 显示界面
            frame.Show();
            object code_window_object;

            frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out code_window_object);
            if (code_window_object == null)
            {
                return(false);
            }
            IVsCodeWindow code_window = code_window_object as IVsCodeWindow;

            if (code_window == null)
            {
                return(false);
            }
            IVsTextView view;

            code_window.GetLastActiveView(out view);
            if (view == null)
            {
                code_window.GetPrimaryView(out view);
            }
            if (view == null)
            {
                return(false);
            }

            if (adapters_factory == null)
            {
                return(false);
            }
            if (length <= 0)
            {
                return(false);
            }

            // 跳转到对应的位置
            var wpf = adapters_factory.GetWpfTextView(view);

            if (wpf == null)
            {
                return(false);
            }
            wpf.Caret.MoveTo(new SnapshotPoint(wpf.TextBuffer.CurrentSnapshot, start));
            wpf.ViewScroller.EnsureSpanVisible(new SnapshotSpan(wpf.TextBuffer.CurrentSnapshot, start, length), EnsureSpanVisibleOptions.AlwaysCenter);

            // 获取视窗
            if (wpf.Properties.TryGetProperty(nameof(ALanguageHighlightWordTagger), out ALanguageHighlightWordTagger tagger))
            {
                tagger.ShowHighlightWord(start, length);
            }
            return(true);
        }
        public EditorNavigationDropdownBar(IVsCodeWindow codeWindow, IVsEditorAdaptersFactoryService editorAdaptersFactory, IEnumerable <IEditorNavigationSource> sources, IBufferGraphFactoryService bufferGraphFactoryService, IEditorNavigationTypeRegistryService editorNavigationTypeRegistryService)
        {
            Contract.Requires <ArgumentNullException>(codeWindow != null, "codeWindow");
            Contract.Requires <ArgumentNullException>(editorAdaptersFactory != null, "editorAdaptersFactory");
            Contract.Requires <ArgumentNullException>(sources != null, "sources");
            Contract.Requires <ArgumentNullException>(bufferGraphFactoryService != null, "bufferGraphFactoryService");
            Contract.Requires <ArgumentNullException>(editorNavigationTypeRegistryService != null, "editorNavigationTypeRegistryService");

            this._codeWindow            = codeWindow;
            this._editorAdaptersFactory = editorAdaptersFactory;
            this._sources = sources;
            this._bufferGraphFactoryService           = bufferGraphFactoryService;
            this._editorNavigationTypeRegistryService = editorNavigationTypeRegistryService;
            this._currentTextView = editorAdaptersFactory.GetWpfTextView(codeWindow.GetLastActiveView());
            this._dispatcher      = this._currentTextView.VisualElement.Dispatcher;
            this._imageList       = new ImageList()
            {
                ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit
            };

            _navigationControls =
                this._sources
                .SelectMany(source => source.GetNavigationTypes())
                .Distinct()
                //.OrderBy(...)
                .Select(type => Tuple.Create(type, new List <IEditorNavigationTarget>()))
                .ToArray();

            _selectedItem = new IEditorNavigationTarget[_navigationControls.Length];

            if (this._navigationControls.Length == 0)
            {
                return;
            }

            IConnectionPointContainer connectionPointContainer = codeWindow as IConnectionPointContainer;

            if (connectionPointContainer != null)
            {
                Guid             textViewEventsGuid = typeof(IVsCodeWindowEvents).GUID;
                IConnectionPoint connectionPoint;
                connectionPointContainer.FindConnectionPoint(ref textViewEventsGuid, out connectionPoint);
                if (connectionPoint != null)
                {
                    connectionPoint.Advise(this, out _codeWindowEventsCookie);
                }
            }

            IVsTextView primaryView = codeWindow.GetPrimaryView();

            if (primaryView != null)
            {
                ((IVsCodeWindowEvents)this).OnNewView(primaryView);
            }

            IVsTextView secondaryView = codeWindow.GetSecondaryView();

            if (secondaryView != null)
            {
                ((IVsCodeWindowEvents)this).OnNewView(secondaryView);
            }

            foreach (var source in this._sources)
            {
                source.NavigationTargetsChanged += WeakEvents.AsWeak(OnNavigationTargetsChanged, eh => source.NavigationTargetsChanged -= eh);
                UpdateNavigationTargets(source);
            }

            _currentTextView.Caret.PositionChanged += OnCaretPositionChanged;
        }
        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);
        }
        public EditorNavigationDropdownBar(IVsCodeWindow codeWindow, IVsEditorAdaptersFactoryService editorAdaptersFactory, IEnumerable<IEditorNavigationSource> sources, IBufferGraphFactoryService bufferGraphFactoryService, IJavaEditorNavigationTypeRegistryService editorNavigationTypeRegistryService)
        {
            Contract.Requires<ArgumentNullException>(codeWindow != null, "codeWindow");
            Contract.Requires<ArgumentNullException>(editorAdaptersFactory != null, "editorAdaptersFactory");
            Contract.Requires<ArgumentNullException>(sources != null, "sources");
            Contract.Requires<ArgumentNullException>(bufferGraphFactoryService != null, "bufferGraphFactoryService");
            Contract.Requires<ArgumentNullException>(editorNavigationTypeRegistryService != null, "editorNavigationTypeRegistryService");

            this._codeWindow = codeWindow;
            this._editorAdaptersFactory = editorAdaptersFactory;
            this._sources = sources;
            this._bufferGraphFactoryService = bufferGraphFactoryService;
            this._editorNavigationTypeRegistryService = editorNavigationTypeRegistryService;
            this._currentTextView = editorAdaptersFactory.GetWpfTextView(codeWindow.GetLastActiveView());
            this._dispatcher = this._currentTextView.VisualElement.Dispatcher;
            this._imageList = new ImageList()
                {
                    ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit
                };

            _navigationControls =
                this._sources
                .SelectMany(source => source.GetNavigationTypes())
                .Distinct()
                //.OrderBy(...)
                .Select(type => Tuple.Create(type, new List<IEditorNavigationTarget>()))
                .ToArray();

            _selectedItem = new IEditorNavigationTarget[_navigationControls.Length];

            if (this._navigationControls.Length == 0)
            {
                return;
            }

            IConnectionPointContainer connectionPointContainer = codeWindow as IConnectionPointContainer;
            if (connectionPointContainer != null)
            {
                Guid textViewEventsGuid = typeof(IVsCodeWindowEvents).GUID;
                IConnectionPoint connectionPoint;
                connectionPointContainer.FindConnectionPoint(ref textViewEventsGuid, out connectionPoint);
                if (connectionPoint != null)
                    connectionPoint.Advise(this, out _codeWindowEventsCookie);
            }

            IVsTextView primaryView = codeWindow.GetPrimaryView();
            if (primaryView != null)
                ((IVsCodeWindowEvents)this).OnNewView(primaryView);

            IVsTextView secondaryView = codeWindow.GetSecondaryView();
            if (secondaryView != null)
                ((IVsCodeWindowEvents)this).OnNewView(secondaryView);

            foreach (var source in this._sources)
            {
                source.NavigationTargetsChanged += WeakEvents.AsWeak(OnNavigationTargetsChanged, eh => source.NavigationTargetsChanged -= eh);
                UpdateNavigationTargets(source);
            }

            _currentTextView.Caret.PositionChanged += OnCaretPositionChanged;
        }
Example #19
0
 public int GetLastActiveView(out IVsTextView ppView)
 {
     return(codeWindow.GetLastActiveView(out ppView));
 }
Example #20
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);
        }
Example #21
0
 int IVsCodeWindow.GetLastActiveView(out IVsTextView ppView) => _editorWindow.GetLastActiveView(out ppView);