コード例 #1
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            foreach (var v in textView.VisualLines)
            {
                Rect rc      = BackgroundGeometryBuilder.GetRectsFromVisualSegment(textView, v, 0, 1000).First();
                int  linenum = v.FirstDocumentLine.LineNumber - 1;

                if (linenum == currentLine)
                {
                    drawingContext.DrawRectangle(brush, pen, new Rect(0, rc.Top, textView.ActualWidth, rc.Height));
                }
            }
        }
コード例 #2
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (Lines == null)
            {
                return;
            }

            foreach (var v in textView.VisualLines)
            {
                var linenum = v.FirstDocumentLine.LineNumber - 1;
                if (linenum >= Lines.Count)
                {
                    continue;
                }

                var diffLine = Lines[linenum];

                if (diffLine.Style == DiffContext.Context)
                {
                    continue;
                }

                var brush = default(Brush);
                switch (diffLine.Style)
                {
                case DiffContext.Added:
                    brush = AddedBackground;
                    break;

                case DiffContext.Deleted:
                    brush = DeletedBackground;
                    break;

                case DiffContext.Blank:
                    brush = BlankBackground;
                    break;
                }

                foreach (var rc in BackgroundGeometryBuilder.GetRectsFromVisualSegment(textView, v, 0, 6000))
                {
                    drawingContext.DrawRectangle(brush, BorderlessPen,
                                                 new Rect(0, rc.Top, textView.ActualWidth, rc.Height));
                }
            }
        }
コード例 #3
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            int cl = CurrentLine + 1;

            foreach (VisualLine v in textView.VisualLines)
            {
                //CurrentLine
                if (cl == v.FirstDocumentLine.LineNumber)
                {
                    Rect rc = BackgroundGeometryBuilder.GetRectsFromVisualSegment(textView, v, 0, 1000).First();
                    drawingContext.DrawRectangle(CurrentLineBackground, CurrentLinePen, new Rect(0, rc.Top, textView.ActualWidth, rc.Height));
                }

                //Error Lines
                if (ErrorLines.Contains(v.FirstDocumentLine.LineNumber))
                {
                    Rect rc = BackgroundGeometryBuilder.GetRectsFromVisualSegment(textView, v, 0, 1000).First();
                    drawingContext.DrawRectangle(ErrorBackground, ErrorPen, new Rect(0, rc.Top, textView.ActualWidth, rc.Height));
                }
            }
        }
コード例 #4
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            canvas.Children.Clear();

            for (var i = 0; i < textView.VisualLines.Count; i++)
            {
                var linenum = textView.VisualLines[i].FirstDocumentLine.LineNumber - 1;
                if (linenum >= host.Snapshot.FileDetails.Count)
                {
                    continue;
                }

                var snapshot = host.Snapshots[host.GetLineBirth(host.Snapshot, linenum)];
                var rc       = BackgroundGeometryBuilder.GetRectsFromVisualSegment(textView, textView.VisualLines[i], 0, 1000).First();

                // Prevent drawing not fully visible lines
                if (rc.Top < -5)
                {
                    continue;
                }
                if (textView.ActualHeight - rc.Top < 10)
                {
                    continue;
                }

                TextBlock textBlock = new TextBlock();
                textBlock.Text       = snapshot.Date.ToString(Constants.DATE_FORMAT) + " " + Truncate(snapshot.Author, 10);
                textBlock.ToolTip    = snapshot.Tooltip;
                textBlock.Foreground = BlackBrush;
                textBlock.Background = GetLineBackgroundBrush(host.Snapshot, linenum);
                textBlock.Width      = canvas.Width;
                textBlock.FontFamily = new FontFamily("Consolas");
                textBlock.Tag        = snapshot.Sha;
                textBlock.MouseDown += TextBlock_MouseDown;

                Canvas.SetLeft(textBlock, 0);
                Canvas.SetTop(textBlock, rc.Top);
                canvas.Children.Add(textBlock);
            }
        }
コード例 #5
0
        public void Draw(TextView textView, DrawingContext dc)
        {
            var messages = BuildDetailMessages.ToLookup(x => x.StartLine);

            var pen    = Caches.GetPen(ByteColor.Tomato, 2);
            var lineNo = 0;

            foreach (var visualLine in textView.VisualLines)
            {
                if (messages.Contains(lineNo))
                {
                    foreach (var message in messages[lineNo])
                    {
                        var end = message.EndCharacter;
                        if (end == message.StartCharacter)
                        {
                            ++end;
                        }

                        var segments = BackgroundGeometryBuilder.GetRectsFromVisualSegment(
                            textView,
                            visualLine,
                            message.StartCharacter,
                            end);

                        foreach (var segment in segments)
                        {
                            dc.DrawLine(
                                pen,
                                new Point(segment.Left, segment.Bottom - 1),
                                new Point(segment.Right, segment.Bottom - 1));
                        }
                    }
                }

                ++lineNo;
            }
        }
コード例 #6
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            var highlightedLine = vm.HighlightedLine;

            if (highlightedLine < 0)
            {
                return;
            }
            foreach (var v in textView.VisualLines)
            {
                // NB: This lookup to fetch the doc line number isn't great, we could
                // probably do it once then just increment.
                var linenum = v.FirstDocumentLine.LineNumber - 1;
                if (linenum != highlightedLine)
                {
                    continue;
                }

                var rc    = BackgroundGeometryBuilder.GetRectsFromVisualSegment(textView, v, 0, 1000).First();
                var brush = Brushes.Yellow;
                drawingContext.DrawRectangle(brush, pen, new Rect(0, rc.Top, textView.ActualWidth, rc.Height));
            }
        }
コード例 #7
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            var chunk = (ChunkDiff)textView.DataContext;

            foreach (VisualLine v in textView.VisualLines)
            {
                var rc = BackgroundGeometryBuilder.GetRectsFromVisualSegment(textView, v, 0, 1000).First();
                // NB: This lookup to fetch the doc line number isn't great, we could
                // probably do it once then just increment.
                var linenum = v.FirstDocumentLine.LineNumber - 1;
                if (linenum >= chunk.Changes.Count)
                {
                    continue;
                }

                var diffLine = chunk.Changes[linenum];

                if (diffLine.Type == LineChangeType.Normal)
                {
                    continue;
                }

                var brush = default(Brush);
                switch (diffLine.Type)
                {
                case LineChangeType.Add:
                    brush = _addedLineBackground;
                    break;

                case LineChangeType.Delete:
                    brush = _removedLineBackground;
                    break;
                }

                drawingContext.DrawRectangle(brush, pen, new Rect(0, rc.Top, textView.ActualWidth, rc.Height));
            }
        }
コード例 #8
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (host == null)
            {
                return;
            }

            foreach (var v in textView.VisualLines)
            {
                var linenum = v.FirstDocumentLine.LineNumber - 1;
                if (linenum >= host.Snapshot.FileDetails.Count)
                {
                    continue;
                }

                if (!host.DiffManager.IsDeleted(host.Snapshot, host.SnapshotParent, linenum))
                {
                    continue;
                }

                var rc = BackgroundGeometryBuilder.GetRectsFromVisualSegment(textView, v, 0, 1000).First();
                drawingContext.DrawRectangle(ColorPalette.DELETED, pen, new Rect(0, rc.Top, textView.ActualWidth, rc.Height));
            }
        }
コード例 #9
0
    public void Draw(TextView textView, DrawingContext drawingContext)
    {
        foreach (var v in textView.VisualLines)
        {
            var rc = BackgroundGeometryBuilder.GetRectsFromVisualSegment(textView, v, 0, 1000).First();
            // NB: This lookup to fetch the doc line number isn't great, we could
            // probably do it once then just increment.
            var linenum = v.FirstDocumentLine.LineNumber - 1;
            if (linenum >= host.ViewModel.Lines.Count)
            {
                continue;
            }
            var diffLine = host.ViewModel.Lines[linenum];
            if (diffLine.Style == DiffLineStyle.Context)
            {
                continue;
            }
            var brush = default(Brush);
            switch (diffLine.Style)
            {
            case DiffLineStyle.Header:
                brush = headerBackground;
                break;

            case DiffLineStyle.Added:
                brush = addedBackground;
                break;

            case DiffLineStyle.Deleted:
                brush = removedBackground;
                break;
            }
            drawingContext.DrawRectangle(brush, pen,
                                         new Rect(0, rc.Top, textView.ActualWidth, rc.Height));
        }
    }
コード例 #10
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            if (Lines == null || Lines.Count == 0)
            {
                return;
            }

            var lineNumberWidth = Math.Round(_lineFt.Width + TextHorizontalMargin * 2.0);

            var tf       = CreateTypeface();
            var fontSize = (double)GetValue(TextBlock.FontSizeProperty);

            var visualLines = TextView.VisualLinesValid ? TextView.VisualLines : Enumerable.Empty <VisualLine>();

            foreach (var v in visualLines)
            {
                var rcs     = BackgroundGeometryBuilder.GetRectsFromVisualSegment(TextView, v, 0, 1000).ToArray();
                var linenum = v.FirstDocumentLine.LineNumber - 1;
                if (linenum >= Lines.Count)
                {
                    continue;
                }

                var diffLine = Lines[linenum];

                FormattedText ft;

                if (diffLine.Style != DiffContext.Context)
                {
                    var brush = default(Brush);
                    switch (diffLine.Style)
                    {
                    case DiffContext.Added:
                        brush = AddedBackground;
                        break;

                    case DiffContext.Deleted:
                        brush = DeletedBackground;
                        break;

                    case DiffContext.Blank:
                        brush = BlankBackground;
                        break;
                    }

                    foreach (var rc in rcs)
                    {
                        drawingContext.DrawRectangle(brush, BorderlessPen, new Rect(0, rc.Top, ActualWidth, rc.Height));
                    }
                }

                if (diffLine.Text != "")
                {
                    ft = new FormattedText(diffLine.LineNumber,
                                           CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                                           tf, fontSize, ForegroundBrush);

                    var left = TextHorizontalMargin;

                    drawingContext.DrawText(ft, new Point(left, rcs[0].Top));
                }

                if (diffLine.PrefixForStyle != "")
                {
                    var prefix = diffLine.PrefixForStyle;
                    ft = new FormattedText(prefix,
                                           CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                                           tf, fontSize, (Brush)TextView.GetValue(Control.ForegroundProperty));

                    drawingContext.DrawText(ft, new Point(lineNumberWidth + TextHorizontalMargin, rcs[0].Top));
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// Draws the background of line based on its <see cref="DiffContext"/>
        /// and whether it is imaginary or not.
        /// </summary>
        /// <param name="textView"></param>
        /// <param name="drawingContext"></param>
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (_DiffView == null)
            {
                return;
            }

            // Draw background line diffs only if this is currently in comparing mode
            if (_DiffView.ViewMode != DisplayMode.Comparing)
            {
                return;
            }

            var srcLineDiffs = _DiffView.ItemsSource as IReadOnlyList <IDiffLineInfo>;

            if (srcLineDiffs == null)
            {
                return;
            }

            var toBeRequested = new List <int>();

            foreach (var v in textView.VisualLines)
            {
                var linenum = v.FirstDocumentLine.LineNumber - 1;

                // Find a diff context for a given line
                if (linenum >= srcLineDiffs.Count)
                {
                    continue;
                }

                // Determine change context (delete, insert, change) per line
                //  and color background according to bound brush
                var srcLineDiff = srcLineDiffs[linenum];
                var brush       = GetLineBackgroundDiffBrush(srcLineDiff.Context, srcLineDiff.ImaginaryLineNumber.HasValue == false);

                if (brush != default(SolidColorBrush))
                {
                    foreach (var rc in BackgroundGeometryBuilder.GetRectsFromVisualSegment(textView, v, 0, v.VisualLength))
                    {
                        drawingContext.DrawRectangle(brush, BorderlessPen,
                                                     new Rect(0, rc.Top, textView.ActualWidth, rc.Height));
                    }
                }

                if (srcLineDiff.LineEditScriptSegments != null)
                {
                    foreach (var item in srcLineDiff.LineEditScriptSegments)
                    {
                        // The main line background has already been drawn, so we just
                        // need to draw the deleted or inserted background segments.
                        if (srcLineDiff.FromA)
                        {
                            brush = _DiffView.ColorBackgroundDeleted;
                        }
                        else
                        {
                            brush = _DiffView.ColorBackgroundAdded;
                        }

                        BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder();
                        geoBuilder.AlignToWholePixels = true;

                        var segment = new Segment(v.StartOffset + item.Offset, item.Length,
                                                  v.StartOffset + item.EndOffset);
                        geoBuilder.AddSegment(textView, segment);

                        Geometry geometry = geoBuilder.CreateGeometry();
                        if (geometry != null)
                        {
                            drawingContext.DrawGeometry(brush, null, geometry);
                        }
                    }
                }
                else
                {
                    // Has this line ever been computed before ?
                    if (srcLineDiff.LineEditScriptSegmentsIsDirty == true &&
                        _DiffView.LineDiffDataProvider != null)
                    {
                        toBeRequested.Add(linenum);
                    }
                }
            }

            // Request matching of additional lines if these appear to be dirty
            if (toBeRequested.Count > 0)
            {
                _DiffView.LineDiffDataProvider.RequestLineDiff(toBeRequested);
            }
        }
コード例 #12
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (!DiffLines.Any())
            {
                return;
            }

            var totalWidth = GetRequiredWidth();
            var leftWidth  = totalWidth / 2.0;
            var rightWidth = ActualWidth - leftWidth;

            var visualLines = TextView.VisualLinesValid ? TextView.VisualLines : Enumerable.Empty <VisualLine>();

            foreach (var line in visualLines)
            {
                var rect = BackgroundGeometryBuilder.GetRectsFromVisualSegment(TextView, line,
                                                                               0, 1000).ToArray();
                var lineNumber = line.FirstDocumentLine.LineNumber;
                if (DiffLines.ContainsKey(lineNumber))
                {
                    var diffLine = DiffLines[lineNumber];
                    if (diffLine.Style != DiffLineNum.DiffLineStyle.Context)
                    {
                        var brush = default(Brush);
                        switch (diffLine.Style)
                        {
                        case DiffLineNum.DiffLineStyle.Plus:
                            brush = new SolidColorBrush(HighlighterHelper.PlusLineColor);
                            break;

                        case DiffLineNum.DiffLineStyle.Minus:
                            brush = new SolidColorBrush(HighlighterHelper.MinusLineColor);
                            break;

                        case DiffLineNum.DiffLineStyle.Header:
                            brush = new SolidColorBrush(HighlighterHelper.HeaderLineColor);
                            break;
                        }

                        foreach (var rc in rect)
                        {
                            drawingContext.DrawRectangle(brush, NullPen, new Rect(0.0, rc.Top, leftWidth, rc.Height));

                            drawingContext.DrawRectangle(brush, NullPen, new Rect(leftWidth, rc.Top, rightWidth, rc.Height));
                        }
                    }

                    var emSize = (double)GetValue(TextBlock.FontSizeProperty);

                    if (diffLine.LeftLineNum != DiffLineNum.NotApplicableLineNum)
                    {
                        var ft = new FormattedText(diffLine.LeftLineNum.ToString(),
                                                   CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                                                   TypeFace, emSize, Brushes.Black);

                        drawingContext.DrawText(ft, new Point(TextHorizontalMargin, rect[0].Top));
                    }

                    if (diffLine.RightLineNum != DiffLineNum.NotApplicableLineNum)
                    {
                        var ft = new FormattedText(diffLine.RightLineNum.ToString(),
                                                   CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                                                   TypeFace, emSize, Brushes.Black);

                        drawingContext.DrawText(ft, new Point(TextHorizontalMargin + totalWidth / 2, rect[0].Top));
                    }
                }
            }
        }