Example #1
0
        private static void InsertLinesInteral(InternalLinesViewer panel, List <DiffPiece> lines, bool isOld, UIElement source, bool disableSubPieces = false)
        {
            foreach (var line in lines)
            {
                if (line == null)
                {
                    var c = panel.Add(null, null, null as string, ChangeType.Unchanged.ToString(), source);
                    c.Tag = line;
                    continue;
                }

                var changeType = line.Type;
                var text       = line.Text;
                var hasAdded   = false;
                switch (line.Type)
                {
                case ChangeType.Modified:
                    changeType = isOld ? ChangeType.Deleted : ChangeType.Inserted;
                    if (line.SubPieces != null && line.SubPieces.Count > 1 && !disableSubPieces)
                    {
                        var details = GetSubPiecesInfo(line, isOld);
                        var c       = panel.Add(line.Position, isOld ? "-" : "+", details, changeType.ToString(), source);
                        c.Tag    = line;
                        hasAdded = true;
                    }

                    break;

                case ChangeType.Inserted:
                case ChangeType.Deleted:
                case ChangeType.Unchanged:
                    break;

                default:
                    changeType = ChangeType.Imaginary;
                    text       = string.Empty;
                    break;
                }

                if (!hasAdded)
                {
                    string op = " ";
                    switch (changeType)
                    {
                    case ChangeType.Inserted:
                        op = "+";
                        break;

                    case ChangeType.Deleted:
                        op = "-";
                        break;
                    }
                    var c = panel.Add(line.Position, op, text, changeType.ToString(), source);
                    c.Tag = line;
                }
            }

            panel.AdjustScrollView();
        }
Example #2
0
        /// <summary>
        /// Updates the inline diffs view.
        /// </summary>
        internal static void RenderInlineDiffs(InternalLinesViewer viewer, DiffPaneModel m, UIElement source)
        {
            viewer.Clear();
            if (m?.Lines == null)
            {
                return;
            }
            var disableSubPieces = m.Lines.Count > MaxCount;    // For performance.

            foreach (var line in m.Lines)
            {
                if (line == null)
                {
                    var c = viewer.Add(null, null, null as string, ChangeType.Unchanged.ToString(), source);
                    c.Tag = line;
                    continue;
                }

                var changeType = line.Type;
                var text       = line.Text;
                var hasAdded   = false;
                switch (line.Type)
                {
                case ChangeType.Modified:
                    changeType = ChangeType.Inserted;
                    break;

                case ChangeType.Inserted:
                    if (line.SubPieces != null && line.SubPieces.Count > 1 && !disableSubPieces)
                    {
                        var details = GetSubPiecesInfo(line, true);
                        var c       = viewer.Add(line.Position, "+", details, changeType.ToString(), source);
                        c.Tag    = line;
                        hasAdded = true;
                    }

                    break;

                case ChangeType.Deleted:
                    if (line.SubPieces != null && line.SubPieces.Count > 1 && !disableSubPieces)
                    {
                        var details = GetSubPiecesInfo(line, false);
                        var c       = viewer.Add(line.Position, "-", details, changeType.ToString(), source);
                        c.Tag    = line;
                        hasAdded = true;
                    }

                    break;

                case ChangeType.Unchanged:
                    break;

                default:
                    changeType = ChangeType.Imaginary;
                    text       = string.Empty;
                    break;
                }

                if (!hasAdded)
                {
                    var c = viewer.Add(line.Position, changeType switch
                    {
                        ChangeType.Inserted => "+",
                        ChangeType.Deleted => "-",
                        _ => " "
                    }, text, changeType.ToString(), source);