예제 #1
0
    public void VsTextViewCreated(IVsTextView textViewAdapter)
    {
        IComponentModel componentModel = (IComponentModel)ServiceProvider.GlobalProvider.GetService(typeof(SComponentModel));

        if (componentModel != null)
        {
            IOutliningManagerService outliningManagerService = componentModel.GetService <IOutliningManagerService>();
            _editorAdaptersFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>();
            if (outliningManagerService != null)
            {
                if (textViewAdapter != null && _editorAdaptersFactoryService != null)
                {
                    var textView     = _editorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
                    var snapshot     = textView.TextSnapshot;
                    var snapshotSpan = new Microsoft.VisualStudio.Text.SnapshotSpan(snapshot, new Microsoft.VisualStudio.Text.Span(0, snapshot.Length));
                    _outliningManager = outliningManagerService.GetOutliningManager(textView);
                    var regions = _outliningManager.GetAllRegions(snapshotSpan);
                    foreach (var reg in regions)
                    {
                        _outliningManager.TryCollapse(reg);
                    }
                }
            }
        }
    }
 public NavigateToHighlightReferenceCommandHandler(
     IOutliningManagerService outliningManagerService,
     IViewTagAggregatorFactoryService tagAggregatorFactory)
 {
     _outliningManagerService = outliningManagerService ?? throw new ArgumentNullException(nameof(outliningManagerService));
     _tagAggregatorFactory    = tagAggregatorFactory ?? throw new ArgumentNullException(nameof(tagAggregatorFactory));
 }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OutliningSynchronizationManager" /> class.
        /// </summary>
        /// <param name="package">The hosting package.</param>
        public OutliningSynchronizationManager(CodeMaidPackage package)
        {
            _package = package;

            // Retrieve services needed for outlining from the package.
            _editorAdaptersFactoryService = _package.ComponentModel.GetService <IVsEditorAdaptersFactoryService>();
            _outliningManagerService      = _package.ComponentModel.GetService <IOutliningManagerService>();
        }
예제 #4
0
 public FoldingManagerAdapter(
     IWpfTextView textView,
     IOutliningManagerService outliningManagerService)
 {
     _outliningManager = outliningManagerService.GetOutliningManager(textView);
     _outliningManager.RegionsExpanded  += OnExpanded;
     _outliningManager.RegionsCollapsed += OnCollapsed;
 }
예제 #5
0
 public static IOutliningManager GetOutliningManager(IOutliningManagerService outliningManagerService, ITextView textView)
 {
     if (outliningManagerService == null)
     {
         return(null);
     }
     return(outliningManagerService.GetOutliningManager(textView));
 }
 public InlineCommentPeekService(
     IApiClientFactory apiClientFactory,
     IOutliningManagerService outliningManager,
     IPeekBroker peekBroker)
 {
     this.apiClientFactory = apiClientFactory;
     this.outliningService = outliningManager;
     this.peekBroker       = peekBroker;
 }
예제 #7
0
 public static void SelectSpan(
     this ITextView textView,
     SnapshotSpan span,
     IOutliningManagerService outliningManagerService  = null,
     EnsureSpanVisibleOptions ensureSpanVisibleOptions = EnsureSpanVisibleOptions.None)
 {
     textView.TryMoveCaretToAndEnsureVisible(span.Start, outliningManagerService, ensureSpanVisibleOptions);
     textView.Selection.Select(span, isReversed: false);
 }
 public InlineCommentPeekService(
     IOutliningManagerService outliningManager,
     IPeekBroker peekBroker,
     IUsageTracker usageTracker)
 {
     this.outliningService = outliningManager;
     this.peekBroker = peekBroker;
     this.usageTracker = usageTracker;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="OutliningSynchronizationManager" /> class.
        /// </summary>
        /// <param name="package">The hosting package.</param>
        public OutliningSynchronizationManager(CodeMaidPackage package)
        {
            _package = package;

            // Retrieve services needed for outlining from the package.
            _editorAdaptersFactoryService = _package.ComponentModel.GetService<IVsEditorAdaptersFactoryService>();
            _outliningManagerService = _package.ComponentModel.GetService<IOutliningManagerService>();
            _serviceProvider = new ServiceProvider((IServiceProvider)_package.IDE);
        }
 public DocumentNavigator([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
                          IVsEditorAdaptersFactoryService editorAdaptersFactory,
                          IOutliningManagerService outliningManagerService,
                          IEditorOperationsFactoryService editorOperationsFactory)
 {
     this.serviceProvider         = serviceProvider;
     this.editorAdaptersFactory   = editorAdaptersFactory;
     this.outliningManagerService = outliningManagerService;
     this.editorOperationsFactory = editorOperationsFactory;
 }
예제 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WpfTextViewAdapter"/> class.
        /// </summary>
        /// <param name="textView">The <see cref="IWpfTextView"/>.</param>
        /// <param name="outliningManagerService">The <see cref="IOutliningManagerService"/>.</param>
        /// <param name="foldingManager">The <see cref="IFoldingManager"/>.</param>
        public WpfTextViewAdapter(
            IWpfTextView textView,
            IOutliningManagerService outliningManagerService,
            IFoldingManager foldingManager)
        {
            _textView = textView ?? throw new ArgumentNullException(nameof(textView));
            _outliningManagerService = outliningManagerService ?? throw new ArgumentNullException(nameof(outliningManagerService));
            FoldingManager           = foldingManager ?? throw new ArgumentNullException(nameof(foldingManager));

            WeakEventManager <ITextBuffer, EventArgs> .AddHandler(_textView.TextBuffer, nameof(ITextBuffer.PostChanged), OnTextPostChanged);
        }
예제 #12
0
 public static bool TryMoveCaretToAndEnsureVisible(
     this ITextView textView,
     SnapshotPoint point,
     IOutliningManagerService outliningManagerService  = null,
     EnsureSpanVisibleOptions ensureSpanVisibleOptions = EnsureSpanVisibleOptions.None)
 {
     return(textView.TryMoveCaretToAndEnsureVisible(
                new VirtualSnapshotPoint(point),
                outliningManagerService,
                ensureSpanVisibleOptions));
 }
        public OutliningCommandTarget(IVsTextView adapter, IWpfTextView textView, IOutliningManagerService outliningManagerService)
        {
            _textView = textView;
            _outliningManagerService = outliningManagerService;

            Dispatcher.CurrentDispatcher.InvokeAsync(() =>
            {
                // Add the target later to make sure it makes it in before other command handlers
                ErrorHandler.ThrowOnFailure(adapter.AddCommandFilter(this, out _nextCommandTarget));
            }, DispatcherPriority.ApplicationIdle);
        }
예제 #14
0
        public OutliningCommandTarget(IVsTextView adapter, IWpfTextView textView, IOutliningManagerService outliningManagerService)
        {
            _textView = textView;
            _outliningManagerService = outliningManagerService;

            Dispatcher.CurrentDispatcher.InvokeAsync(() =>
            {
                // Add the target later to make sure it makes it in before other command handlers
                ErrorHandler.ThrowOnFailure(adapter.AddCommandFilter(this, out _nextCommandTarget));
            }, DispatcherPriority.ApplicationIdle);
        }
예제 #15
0
        private RegionTextViewHandler(IWpfTextView textView, IOutliningManagerService outliningManagerService)
        {
            _outliningManager = outliningManagerService.GetOutliningManager(textView);

            if (_outliningManager == null)
            {
                return;
            }

            _textView = textView;
            _outliningManager.RegionsCollapsed += OnRegionsCollapsed;
            _textView.Closed += OnClosed;
        }
예제 #16
0
        public async Task R_OutlineToggleAll()
        {
            string text = _files.LoadDestinationFile("lsfit.r");

            using (var script = await _editorHost.StartScript(_exportProvider, text, "filename", RContentTypeDefinition.ContentType, null)) {
                script.DoIdle(500);

                IOutliningManagerService svc = _exportProvider.GetExportedValue <IOutliningManagerService>();
                IOutliningManager        mgr = svc.GetOutliningManager(script.View);
                var snapshot = script.TextBuffer.CurrentSnapshot;

                var viewLines = script.View.TextViewLines;
                viewLines.Count.Should().Be(22);
                script.DoIdle(500);

                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_ALL);
                script.DoIdle(1000);

                IEnumerable <ICollapsed> collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(20);

                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_ALL);
                script.DoIdle(500);

                viewLines = script.View.TextViewLines;
                viewLines.Count.Should().Be(22);

                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_STOP_HIDING_ALL);
                script.DoIdle(200);
                mgr.Enabled.Should().Be(false);

                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_START_AUTOHIDING);
                script.DoIdle(200);
                mgr.Enabled.Should().Be(true);

                script.MoveDown(9);
                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_CURRENT);
                script.DoIdle(500);

                collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(1);

                script.Execute(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_CURRENT);
                script.DoIdle(200);

                collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(0);
            }
        }
예제 #17
0
파일: OutlineTest.cs 프로젝트: xoriath/RTVS
        public void R_OutlineToggleAll()
        {
            string text = _files.LoadDestinationFile("lsfit.r");

            using (var script = new TestScript(text, RContentTypeDefinition.ContentType)) {
                script.DoIdle(500);

                IOutliningManagerService svc = EditorShell.Current.ExportProvider.GetExportedValue <IOutliningManagerService>();
                IOutliningManager        mgr = svc.GetOutliningManager(EditorWindow.CoreEditor.View);
                var snapshot = EditorWindow.TextBuffer.CurrentSnapshot;

                var viewLines = EditorWindow.CoreEditor.View.TextViewLines;
                viewLines.Count.Should().Be(40);
                script.DoIdle(500);

                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_ALL);
                script.DoIdle(1000);

                IEnumerable <ICollapsed> collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(20);

                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_ALL);
                script.DoIdle(500);

                viewLines = EditorWindow.CoreEditor.View.TextViewLines;
                viewLines.Count.Should().Be(40);

                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_STOP_HIDING_ALL);
                script.DoIdle(200);
                mgr.Enabled.Should().Be(false);

                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_START_AUTOHIDING);
                script.DoIdle(200);
                mgr.Enabled.Should().Be(true);

                script.MoveDown(9);
                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_CURRENT);
                script.DoIdle(500);

                collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(1);

                EditorWindow.ExecCommand(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.OUTLN_TOGGLE_CURRENT);
                script.DoIdle(200);

                collapsed = mgr.GetCollapsedRegions(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                collapsed.Count().Should().Be(0);
            }
        }
예제 #18
0
 public OutliningTaggerProvider(
     [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
     ITextDocumentFactoryService textDocumentFactoryService,
     ITextEditorFactoryService textEditorFactoryService,
     IProjectionBufferFactoryService projectionBufferFactoryService,
     IOutliningManagerService outliningManagerService,
     ProjectFactory projectFactory,
     VSLanguageService vsLanguageService)
 {
     _serviceProvider = serviceProvider;
     _textDocumentFactoryService = textDocumentFactoryService;
     _textEditorFactoryService = textEditorFactoryService;
     _projectionBufferFactoryService = projectionBufferFactoryService;
     _outliningManagerService = outliningManagerService;
     _projectFactory = projectFactory;
     _vsLanguageService = vsLanguageService;
 }
예제 #19
0
        internal static IOutliningManager GetOutliningManager(this IServiceProvider serviceProvider, ITextView textView)
        {
            if (serviceProvider == null || textView == null)
            {
                return(null);
            }

            IComponentModel          componentModel          = serviceProvider.GetService <SComponentModel, IComponentModel>();
            IOutliningManagerService outliningManagerService = componentModel?.GetService <IOutliningManagerService>();

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

            return(outliningManagerService.GetOutliningManager(textView));
        }
예제 #20
0
        public NavigateToHighlightReferenceCommandHandler(
            IOutliningManagerService outliningManagerService,
            IViewTagAggregatorFactoryService tagAggregatorFactory)
        {
            if (outliningManagerService == null)
            {
                throw new ArgumentNullException("outliningManagerService");
            }

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

            _outliningManagerService = outliningManagerService;
            _tagAggregatorFactory    = tagAggregatorFactory;
        }
예제 #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DiagnosticInfosViewModel"/> class.
        /// </summary>
        /// <param name="textView">The <see cref="IQualityTextView"/>.</param>
        /// <param name="diagnosticProvider">The <see cref="IDiagnosticProvider"/>.</param>
        /// <param name="outliningManagerService">THe <see cref="IOutliningManagerService"/> for the <paramref name="textView"/>.</param>
        /// <param name="adornmentSpaceReservation">The <see cref="IAdornmentSpaceReservation"/>.</param>
        public DiagnosticInfosViewModel(
            IQualityTextView textView,
            IDiagnosticProvider diagnosticProvider,
            IOutliningManagerService outliningManagerService,
            IAdornmentSpaceReservation adornmentSpaceReservation)
        {
            _diagnosticProvider       = diagnosticProvider ?? throw new ArgumentNullException(nameof(diagnosticProvider));
            TextView                  = textView ?? throw new ArgumentNullException(nameof(textView));
            AdornmentSpaceReservation = adornmentSpaceReservation ?? throw new ArgumentNullException(nameof(adornmentSpaceReservation));
            OutliningManager          = outliningManagerService.GetOutliningManager(TextView.TextView);

            WeakEventManager <IDiagnosticProvider, DiagnosticsChangedEventArgs> .AddHandler(_diagnosticProvider, nameof(IDiagnosticProvider.DiagnosticsChanged), OnDiagnosticsChanged);

            OutliningManager.RegionsExpanded  += OnRegionsExpanded;
            OutliningManager.RegionsCollapsed += OnRegionsCollapsed;

            OnDiagnosticsChanged(this, new DiagnosticsChangedEventArgs(_diagnosticProvider.CurrentDiagnostics));
        }
예제 #22
0
        internal static async Task <IOutliningManager> GetOutliningManagerAsync(this Shell.IAsyncServiceProvider serviceProvider, ITextView textView)
        {
            if (serviceProvider == null || textView == null)
            {
                return(null);
            }

            IComponentModel componentModel = await serviceProvider.GetServiceAsync <SComponentModel, IComponentModel>();

            IOutliningManagerService outliningManagerService = componentModel?.GetService <IOutliningManagerService>();

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

            return(outliningManagerService.GetOutliningManager(textView));
        }
예제 #23
0
        DiagnosticService(IWpfTextView textView, IComponentModel componentModel)
        {
            var viewTagAggregatorFactoryService = componentModel.GetService <IViewTagAggregatorFactoryService>();

            _textView = textView;
            _outliningManagerService = componentModel.GetService <IOutliningManagerService>();
            _errorTagAggregator      = viewTagAggregatorFactoryService.CreateTagAggregator <DiagnosticErrorTag>(textView);
            _diagnosticMapping       = new Dictionary <DiagnosticSeverity, ReadOnlyCollection <IMappingTagSpan <DiagnosticErrorTag> > >();

            WaitingForAnalysis = true;

            _textView.Closed                       += OnTextViewClosed;
            _textView.TextBuffer.Changed           += OnTextBufferChanged;
            _errorTagAggregator.BatchedTagsChanged += OnBatchedTagsChanged;

            // Evtl. gibt es bereits einen Syntaxbaum...
            Invalidate();
        }
예제 #24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Selector"/> class.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="textSearchService"></param>
        /// <param name="editorOperationsService"></param>
        /// <param name="textStructureNavigator"></param>
        /// <param name="outliningManagerService"></param>
        public Selector(
            IWpfTextView view,
            ITextSearchService textSearchService,
            IEditorOperationsFactoryService editorOperationsService,
            ITextStructureNavigator textStructureNavigator,
            IOutliningManagerService outliningManagerService)
        {
            this.view = view;

            // Services
            this.textSearchService      = textSearchService;
            this.EditorOperations       = editorOperationsService.GetEditorOperations(this.view);
            this.textStructureNavigator = textStructureNavigator;
            this.outliningManager       = outliningManagerService?.GetOutliningManager(this.view);
            this.Dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;

            this.Selections     = new List <Selection>();
            this.historyManager = new HistoryManager();
        }
예제 #25
0
        public EditorHost(CompositionContainer compositionContainer)
        {
            _compositionContainer           = compositionContainer;
            _textBufferFactoryService       = _compositionContainer.GetExportedValue <ITextBufferFactoryService>();
            _textEditorFactoryService       = _compositionContainer.GetExportedValue <ITextEditorFactoryService>();
            _projectionBufferFactoryService = _compositionContainer.GetExportedValue <IProjectionBufferFactoryService>();
            _smartIndentationService        = _compositionContainer.GetExportedValue <ISmartIndentationService>();
            _editorOperationsFactoryService = _compositionContainer.GetExportedValue <IEditorOperationsFactoryService>();
            _editorOptionsFactoryService    = _compositionContainer.GetExportedValue <IEditorOptionsFactoryService>();
            _textSearchService                 = _compositionContainer.GetExportedValue <ITextSearchService>();
            _outliningManagerService           = _compositionContainer.GetExportedValue <IOutliningManagerService>();
            _textBufferUndoManagerProvider     = _compositionContainer.GetExportedValue <ITextBufferUndoManagerProvider>();
            _contentTypeRegistryService        = _compositionContainer.GetExportedValue <IContentTypeRegistryService>();
            _classificationTypeRegistryService = _compositionContainer.GetExportedValue <IClassificationTypeRegistryService>();

            var errorHandlers = _compositionContainer.GetExportedValues <IExtensionErrorHandler>();

            _protectedOperations      = EditorUtilsFactory.CreateProtectedOperations(errorHandlers);
            _basicUndoHistoryRegistry = _compositionContainer.GetExportedValue <IBasicUndoHistoryRegistry>();
        }
예제 #26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Selector"/> class.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="textSearchService"></param>
        /// <param name="IEditorOperationsFactoryService"></param>
        /// <param name="IEditorFormatMapService"></param>
        /// <param name="ITextStructureNavigator"></param>
        /// <param name="IOutliningManagerService"></param>
        public Selector(
            IWpfTextView view,
            ITextSearchService textSearchService,
            IEditorOperationsFactoryService editorOperationsService,
            IEditorFormatMapService formatMapService         = null,
            ITextStructureNavigator textStructureNavigator   = null,
            IOutliningManagerService outliningManagerService = null
            )
        {
            this.view = view;

            // Services
            this.textSearchService      = textSearchService ?? throw new ArgumentNullException("textSearchService");
            this.editorOperations       = editorOperationsService.GetEditorOperations(this.view);
            this.textStructureNavigator = textStructureNavigator;
            this.outliningManager       = outliningManagerService?.GetOutliningManager(this.view);
            this.Dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;

            this.Selections = new List <Selection>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AdornmentLayer"/> class.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="textSearchService"></param>
        /// <param name="IEditorOperationsFactoryService"></param>
        /// <param name="IEditorFormatMapService"></param>
        /// <param name="ITextStructureNavigator"></param>
        /// <param name="IOutliningManagerService"></param>
        public AdornmentLayer(
            IWpfTextView view,
            ITextSearchService textSearchService,
            IEditorOperationsFactoryService editorOperationsService,
            IEditorFormatMapService formatMapService         = null,
            ITextStructureNavigator textStructureNavigator   = null,
            IOutliningManagerService outliningManagerService = null
            )
        {
            view.Properties.GetOrCreateSingletonProperty(
                typeof(AdornmentLayer), () => this
                );

            this.view  = view;
            this.layer = view.GetAdornmentLayer(Vsix.Name);

            this.Selector = new Selector(
                view,
                textSearchService,
                editorOperationsService,
                formatMapService,
                textStructureNavigator,
                outliningManagerService
                );

            this.SetupBrushes(formatMapService);

            // events
            this.view.LayoutChanged += this.OnLayoutChanged;

            MenuCommandRegistrations.OnConvertSelectionToMultipleCursorsPressed += new CmdConvertSelectionToMultipleCursors(view).OnCommandInvoked;
            MenuCommandRegistrations.OnSelectNextOccurrencePressed          += new CmdSelectNextOccurrence(view).OnCommandInvoked;
            MenuCommandRegistrations.OnSelectNextExactOccurrencePressed     += new CmdSelectNextExactOccurrence(view).OnCommandInvoked;
            MenuCommandRegistrations.OnSelectPreviousExactOccurrencePressed += new CmdSelectPreviousExactOccurrence(view).OnCommandInvoked;
            MenuCommandRegistrations.OnSelectPreviousOccurrencePressed      += new CmdSelectPreviousOccurrence(view).OnCommandInvoked;
            MenuCommandRegistrations.OnSkipOccurrencePressed       += new CmdSkipOccurrence(view).OnCommandInvoked;
            MenuCommandRegistrations.OnUndoOccurrencePressed       += new CmdUndoOccurrence(view).OnCommandInvoked;
            MenuCommandRegistrations.OnAddCaretAbovePressed        += new CmdAddCaretAbove(view).OnCommandInvoked;
            MenuCommandRegistrations.OnAddCaretBelowPressed        += new CmdAddCaretBelow(view).OnCommandInvoked;
            MenuCommandRegistrations.OnSelectAllOccurrencesPressed += new CmdSelectAllOccurrences(view).OnCommandInvoked;
        }
예제 #28
0
        public static bool TryMoveCaretToAndEnsureVisible(
            this ITextView textView,
            VirtualSnapshotPoint point,
            IOutliningManagerService outliningManagerService  = null,
            EnsureSpanVisibleOptions ensureSpanVisibleOptions = EnsureSpanVisibleOptions.None)
        {
            if (textView.IsClosed)
            {
                return(false);
            }

            var pointInView = textView.GetPositionInView(point.Position);

            if (!pointInView.HasValue)
            {
                return(false);
            }

            // If we were given an outlining service, we need to expand any outlines first, or else
            // the Caret.MoveTo won't land in the correct location if our target is inside a
            // collapsed outline.
            if (outliningManagerService != null)
            {
                var outliningManager = outliningManagerService.GetOutliningManager(textView);
                if (outliningManager != null)
                {
                    outliningManager.ExpandAll(new SnapshotSpan(pointInView.Value, length: 0), match: _ => true);
                }
            }

            var newPosition = textView.Caret.MoveTo(new VirtualSnapshotPoint(pointInView.Value, point.VirtualSpaces));

            // We use the caret's position in the view's current snapshot here in case something
            // changed text in response to a caret move (e.g. line commit)
            var spanInView = new SnapshotSpan(newPosition.BufferPosition, 0);

            textView.ViewScroller.EnsureSpanVisible(spanInView, ensureSpanVisibleOptions);

            return(true);
        }
        public CodeViewUserControlTop(Window window, RowDefinition row = null,
                                      IWpfTextView textView            = null, IOutliningManagerService outliningManagerService = null,
                                      VisualStudioWorkspace workspace  = null, CodeNavMargin margin = null, DTE dte = null)
        {
            InitializeComponent();

            // Setup viewmodel as datacontext
            CodeDocumentViewModel = new CodeDocumentViewModel();
            DataContext           = CodeDocumentViewModel;

            _window  = window;
            _row     = row;
            TextView = textView;
            OutliningManagerService = outliningManagerService;
            _workspace = workspace;
            _margin    = margin;
            Dte        = dte;

            LogHelper.Dte = dte;

            VSColorTheme.ThemeChanged += VSColorTheme_ThemeChanged;
        }
예제 #30
0
        /// <summary>
        /// Attempts to find a <see cref="ICollapsible" /> associated with the specified <see
        /// cref="IMembers" />.
        /// </summary>
        /// <param name="item">The IMembers CodeItem.</param>
        /// <param name="outliningManagerService">The outlining manager to get all regions</param>
        /// <param name="textView">The textview to find collapsibles in</param>
        /// <returns>The <see cref="ICollapsible" /> on the same starting line, otherwise null.</returns>
        private static ICollapsible FindCollapsibleFromCodeItem(CodeItem item,
                                                                IOutliningManagerService outliningManagerService, IWpfTextView textView)
        {
            if (item.Kind == CodeItemKindEnum.ImplementedInterface)
            {
                return(null);
            }
            if (item.StartLine > textView.TextBuffer.CurrentSnapshot.LineCount)
            {
                return(null);
            }

            try
            {
                var outliningManager = GetOutliningManager(outliningManagerService, textView);
                if (outliningManager == null)
                {
                    return(null);
                }

                var collapsibles = outliningManager.GetAllRegions(ToSnapshotSpan(textView, item.Span));

                return((from collapsible in collapsibles
                        let startLine = GetStartLineForCollapsible(collapsible)
                                        where startLine == item.StartLine
                                        select collapsible).FirstOrDefault());
            }
            catch (ArgumentOutOfRangeException)
            {
                // FindCollapsibleFromCodeItem failed for item
                return(null);
            }
            catch (ObjectDisposedException)
            {
                // FindCollapsibleFromCodeItem failed because of disposed object
                return(null);
            }
        }
예제 #31
0
        public CodeNavMargin(IWpfTextViewHost textViewHost, DTE dte, IOutliningManagerService outliningManagerService,
                             VisualStudioWorkspace workspace, MarginSideEnum side)
        {
            // Wire up references for the event handlers in RegisterEvents
            _dte      = dte;
            _textView = textViewHost.TextView;
            _window   = GetWindow(textViewHost, dte);
            _outliningManagerService = outliningManagerService;
            _outliningManager        = OutliningHelper.GetOutliningManager(outliningManagerService, _textView);
            _workspace = workspace;
            MarginSide = side;

            // If we can not find the window we belong to we can not do anything
            if (_window == null)
            {
                return;
            }

            // Add the view/content to the margin area
            if (side == MarginSideEnum.Top)
            {
                _codeNavGrid = CreateGridTop(textViewHost);
            }
            else
            {
                _codeNavGrid   = CreateGrid(textViewHost);
                _codeNavColumn = _codeNavGrid.ColumnDefinitions[Settings.Default.MarginSide == MarginSideEnum.Left ? 0 : 2];
            }

            Children.Add(_codeNavGrid);

            System.Windows.Threading.Dispatcher.CurrentDispatcher.VerifyAccess();

            RegisterEvents();

            UpdateSettings();
        }
예제 #32
0
        public static void SyncAllRegions(IOutliningManagerService outliningManagerService, IWpfTextView textView, IEnumerable <CodeItem> document)
        {
            if (outliningManagerService == null)
            {
                return;
            }

            _outliningManagerService = outliningManagerService;
            _textView = textView;

            foreach (var item in document)
            {
                if (!(item is IMembers))
                {
                    continue;
                }

                var collapsible = FindCollapsibleFromCodeItem(item, outliningManagerService, textView);

                if (collapsible == null)
                {
                    (item as IMembers).IsExpanded = true;
                }
                else
                {
                    (item as IMembers).IsExpanded = !collapsible.IsCollapsed;
                }

                if (item is ICodeCollapsible)
                {
                    (item as ICodeCollapsible).IsExpandedChanged += OnIsExpandedChanged;
                }

                SyncAllRegions(outliningManagerService, textView, (item as IMembers).Members);
            }
        }
예제 #33
0
 public OutlineController(ITextView textView, IOutliningManagerService outliningManagerService) {
     _textView = textView;
     _outliningManagerService = outliningManagerService;
 }
예제 #34
0
 public virtual void SetupBase()
 {
     _compositionContainer = GetOrCreateCompositionContainer();
     _textBufferFactoryService = _compositionContainer.GetExportedValue<ITextBufferFactoryService>();
     _textEditorFactoryService = _compositionContainer.GetExportedValue<ITextEditorFactoryService>();
     _smartIndentationService = _compositionContainer.GetExportedValue<ISmartIndentationService>();
     _editorOperationsFactoryService = _compositionContainer.GetExportedValue<IEditorOperationsFactoryService>();
     _editorOptionsFactoryService = _compositionContainer.GetExportedValue<IEditorOptionsFactoryService>();
     _textSearchService = _compositionContainer.GetExportedValue<ITextSearchService>();
     _outliningManagerService = _compositionContainer.GetExportedValue<IOutliningManagerService>();
     _textBufferUndoManagerProvider = _compositionContainer.GetExportedValue<ITextBufferUndoManagerProvider>();
     _contentTypeRegistryService = _compositionContainer.GetExportedValue<IContentTypeRegistryService>();
     _adhocOutlinerFactory = _compositionContainer.GetExportedValue<IAdhocOutlinerFactory>();
     _taggerFactory = _compositionContainer.GetExportedValue<ITaggerFactory>();
 }