Esempio n. 1
0
        protected override Size MeasureOverride(Size availableSize)
        {
            if (!DiffLines.Any())
            {
                return(new Size(0.0, 0.0));
            }

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

            var typeFace = TypeFace;

            _FormattedMaxLineNumber = new FormattedText(_maxValueOfLineNum.ToString(),
                                                        CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeFace, emSize, Brushes.White);
            return(new Size(GetRequiredWidth(), 0.0));
        }
Esempio n. 2
0
            /// <summary>
            /// Sets the Counterpart property in each line property of each
            /// <see cref="DiffLines"/> object to refer to each other. This information
            /// can be used for finding equivelant lines from left to right lines[] collection
            /// and vice versa.
            /// </summary>
            /// <param name="counterpartView"></param>
            public void SetCounterPartLines(DiffLines counterpartView)
            {
                int numLines = _DocLineDiffs.Count;

                if (numLines != counterpartView._DocLineDiffs.Count)
                {
                    throw new ArgumentException("The counterpart view has a different number of view lines.", nameof(counterpartView));
                }

                for (int i = 0; i < numLines; i++)
                {
                    var line        = _DocLineDiffs[i];
                    var counterpart = counterpartView._DocLineDiffs[i];

                    // Make the counterpart lines refer to each other.
                    line.SetCounterPart(counterpart);
                    counterpart.SetCounterPart(line);
                }
            }
Esempio n. 3
0
        public HunkRangeInfo(HunkRange originaleHunkRange, HunkRange newHunkRange, IEnumerable <string> diffLines, string fileName)
        {
            OriginalHunkRange = originaleHunkRange;
            NewHunkRange      = newHunkRange;

            // Don't want things like "git --diff, which are stuck on the bottom.  Discard anything after hunk-specified range:
            var lines = Math.Max(OriginalHunkRange.NumberOfLines, NewHunkRange.NumberOfLines);

            DiffLines     = diffLines.Take(lines).ToList();
            this.FileName = fileName;

            IsAddition     = DiffLines.All(s => s.StartsWith("+") || string.IsNullOrWhiteSpace(s));
            IsDeletion     = DiffLines.All(s => s.StartsWith("-") || string.IsNullOrWhiteSpace(s));
            IsModification = !IsAddition && !IsDeletion;

            if (IsDeletion || IsModification)
            {
                OriginalText = DiffLines.Where(s => s.StartsWith("-")).Select(s => s.Remove(0, 1).TrimEnd('\n').TrimEnd('\r')).ToList();
            }
        }
        public override void Paint(Graphics g, Rectangle rect)
        {
            var totalWidth = Size.Width;
            var leftWidth  = (int)(totalWidth / 2.0);
            var rightWidth = rect.Width - leftWidth;

            var fontHeight             = textArea.TextView.FontHeight;
            var lineNumberPainterColor = textArea.Document.HighlightingStrategy.GetColorFor("LineNumbers");
            var fillBrush = textArea.Enabled ? BrushRegistry.GetBrush(lineNumberPainterColor.BackgroundColor) : SystemBrushes.InactiveBorder;
            var drawBrush = BrushRegistry.GetBrush(lineNumberPainterColor.Color);

            for (var y = 0; y < ((DrawingPosition.Height + textArea.TextView.VisibleLineDrawingRemainder) / fontHeight) + 1; ++y)
            {
                var ypos = drawingPosition.Y + (fontHeight * y) - textArea.TextView.VisibleLineDrawingRemainder;
                var backgroundRectangle = new Rectangle(drawingPosition.X, ypos, drawingPosition.Width, fontHeight);
                if (!rect.IntersectsWith(backgroundRectangle))
                {
                    continue;
                }

                g.FillRectangle(fillBrush, backgroundRectangle);
                var curLine = textArea.Document.GetFirstLogicalLine(textArea.Document.GetVisibleLine(textArea.TextView.FirstVisibleLine) + y);

                if (curLine >= textArea.Document.TotalNumberOfLines)
                {
                    continue;
                }

                if (!DiffLines.ContainsKey(curLine + 1))
                {
                    continue;
                }

                var diffLine = DiffLines[curLine + 1];
                if (diffLine.Style != DiffLineNum.DiffLineStyle.Context)
                {
                    var brush = default(Brush);
                    switch (diffLine.Style)
                    {
                    case DiffLineNum.DiffLineStyle.Plus:
                        brush = new SolidBrush(AppSettings.DiffAddedColor);
                        break;

                    case DiffLineNum.DiffLineStyle.Minus:
                        brush = new SolidBrush(AppSettings.DiffRemovedColor);
                        break;

                    case DiffLineNum.DiffLineStyle.Header:
                        brush = new SolidBrush(AppSettings.DiffSectionColor);
                        break;
                    }

                    Debug.Assert(brush != null, string.Format("brush != null, unknow diff line style {0}", diffLine.Style));
                    g.FillRectangle(brush, new Rectangle(0, backgroundRectangle.Top, leftWidth, backgroundRectangle.Height));

                    g.FillRectangle(brush, new Rectangle(leftWidth, backgroundRectangle.Top, rightWidth, backgroundRectangle.Height));
                }

                if (diffLine.LeftLineNum != DiffLineNum.NotApplicableLineNum)
                {
                    g.DrawString(diffLine.LeftLineNum.ToString(),
                                 lineNumberPainterColor.GetFont(TextEditorProperties.FontContainer),
                                 drawBrush,
                                 new Point(TextHorizontalMargin, backgroundRectangle.Top));
                }

                if (diffLine.RightLineNum != DiffLineNum.NotApplicableLineNum)
                {
                    g.DrawString(diffLine.RightLineNum.ToString(),
                                 lineNumberPainterColor.GetFont(TextEditorProperties.FontContainer),
                                 drawBrush,
                                 new Point(TextHorizontalMargin + (totalWidth / 2), backgroundRectangle.Top));
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Class constructor
 /// </summary>
 public LinesFactory()
 {
     _linesA = new DiffLines();
     _linesB = new DiffLines();
 }
Esempio n. 6
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));
                    }
                }
            }
        }
 public void Clear(bool forDiff)
 {
     DiffLines.Clear();
 }