/// <summary>
        /// Initializes a new instance of the <see cref="CodeStructureViewModel"/> class.
        /// </summary>
        /// <param name="editor">The <see cref="IEditor"/>.</param>
        /// <param name="diagnosticProvider">The <see cref="IDiagnosticProvider"/>.</param>
        /// <param name="documentAnalyzerService">The <see cref="IDocumentAnalyzerService"/>.</param>
        /// <param name="spaceReservation">The <see cref="IAdornmentSpaceReservation"/>.</param>
        public CodeStructureViewModel(
            IEditor editor,
            IDiagnosticProvider diagnosticProvider,
            IDocumentAnalyzerService documentAnalyzerService,
            IAdornmentSpaceReservation spaceReservation,
            IDispatcherServiceFactory dispatcherServiceFactory)
        {
            _editor                  = editor;
            _diagnosticProvider      = diagnosticProvider ?? throw new ArgumentNullException(nameof(diagnosticProvider));
            _documentAnalyzerService = documentAnalyzerService ?? throw new ArgumentNullException(nameof(documentAnalyzerService));
            _dispatcherService       = dispatcherServiceFactory.Create();

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

            WeakEventManager <IDocumentAnalyzerService, EventArgs> .AddHandler(_documentAnalyzerService, nameof(IDocumentAnalyzerService.AnalysisFinished), OnAnalysisFinished);

            SpaceReservation = spaceReservation;
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CodeStructureViewModel"/> class.
        /// </summary>
        /// <param name="textView">The <see cref="IWpfTextView"/>.</param>
        /// <param name="adornmentLayer">The <see cref="IAdornmentLayer"/>.</param>
        /// <param name="diagnosticProvider">The <see cref="IDiagnosticProvider"/>.</param>
        /// <param name="documentAnalyzerService">The <see cref="IDocumentAnalyzerService"/>.</param>
        /// <param name="spaceReservation">The <see cref="IAdornmentSpaceReservation"/>.</param>
        public CodeStructureViewModel(
            IWpfTextView textView,
            IAdornmentLayer adornmentLayer,
            IDiagnosticProvider diagnosticProvider,
            IDocumentAnalyzerService documentAnalyzerService,
            IAdornmentSpaceReservation spaceReservation)
        {
            _textView                = textView;
            _diagnosticProvider      = diagnosticProvider ?? throw new ArgumentNullException(nameof(diagnosticProvider));
            _documentAnalyzerService = documentAnalyzerService ?? throw new ArgumentNullException(nameof(documentAnalyzerService));
            _adornmentLayer          = adornmentLayer ?? throw new ArgumentNullException(nameof(adornmentLayer));

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

            WeakEventManager <IDocumentAnalyzerService, EventArgs> .AddHandler(_documentAnalyzerService, nameof(IDocumentAnalyzerService.AnalysisFinished), OnAnalysisFinished);

            SpaceReservation = spaceReservation;
        }
예제 #3
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));
        }
예제 #4
0
        /// <summary>
        /// Calculates the placement <see cref="Rect"/> of the <paramref name="diagnosticInfoLine"/> ind the <paramref name="textView"/>.
        /// </summary>
        /// <param name="textView">The <see cref="IWpfTextView"/> in which the line should be placed.</param>
        /// <param name="diagnosticInfoLine">The <see cref="DiagnosticInfoLine"/> to place.</param>
        /// <param name="adornmentSpaceReservation">The <see cref="IAdornmentSpaceReservation"/>.</param>
        /// <returns>The placement <see cref="Rect"/>.</returns>
        public static Rect CalculatePlacementRect(IWpfTextView textView, DiagnosticInfoLine diagnosticInfoLine, IAdornmentSpaceReservation adornmentSpaceReservation)
        {
            var lineSnapshot = textView.GetSnapshotForLineNumber(diagnosticInfoLine.LineNumber);

            if (lineSnapshot == null)
            {
                return(Rect.Empty);
            }

            var snapshotSpan = lineSnapshot.Extent;
            var endPoint     = snapshotSpan.End;

            try
            {
                if (!textView.TextViewLines.ContainsBufferPosition(endPoint))
                {
                    return(Rect.Empty);
                }
            }
            catch (InvalidCastException)
            {
                // Don't know exactly why this can happen, but it occasionally occurs since performance improvements
                // in  parsing diagnostic infos were done.
                return(Rect.Empty);
            }

            var textViewLine = textView.GetTextViewLineContainingBufferPosition(endPoint);

            var isVisible = textViewLine.VisibilityState > VisibilityState.PartiallyVisible;

            if (!isVisible)
            {
                return(Rect.Empty);
            }

            var reservedWidth = adornmentSpaceReservation?.ActualWidth ?? 0.0;

            var height = textViewLine.TextHeight;
            var left   = Math.Min(textViewLine.TextRight + 10, textView.ViewportRight - height - reservedWidth) - textView.ViewportLeft;
            var width  = Math.Max(textView.ViewportWidth - left - reservedWidth, height);
            var top    = textViewLine.TextTop - textView.ViewportTop;

            return(new Rect(left, top, width, height));
        }