示例#1
0
        private void ComputeLineDifferences(LineRecord lrec, LineRecord rrec)
        {
            DiffList_CharData left  = new DiffList_CharData(lrec.Text);
            DiffList_CharData right = new DiffList_CharData(rrec.Text);

            DiffEngine engine = new DiffEngine();

            engine.ProcessDiff(left, right, DiffEngineLevel.SlowPerfect);
            ArrayList report = engine.DiffReport();

            foreach (DiffResultSpan dres in report)
            {
                switch (dres.Status)
                {
                case DiffResultSpanStatus.NoChange:
                    break;

                case DiffResultSpanStatus.Replace:
                    lrec.AddRange(dres.SourceIndex, dres.SourceIndex + dres.Length, Color.LightSalmon, Color.Empty);
                    rrec.AddRange(dres.DestIndex, dres.DestIndex + dres.Length, Color.LightSalmon, Color.Empty);
                    break;

                case DiffResultSpanStatus.DeleteSource:
                    lrec.AddRange(dres.SourceIndex, dres.SourceIndex + dres.Length, Color.LightSalmon, Color.Empty);
                    break;

                case DiffResultSpanStatus.AddDestination:
                    rrec.AddRange(dres.DestIndex, dres.DestIndex + dres.Length, Color.LightSalmon, Color.Empty);
                    break;

                default:
                    break;
                } // switch
            }     // foreach
        }
示例#2
0
 private void UpdateDiffColors(Dictionary <int, Color> dcolors, List <LineRecord> lines)
 {
     for (int i = 0; i < lines.Count; i++)
     {
         LineRecord lrec = lines[i];
         if (lrec.BackColor != Color.Empty)
         {
             Color mark = lrec.BackColor;
             if (lrec.RangesCount > 0)
             {
                 mark = lrec[0].BackColor;
             }
             dcolors.Add(i, mark);
         }
     } // for
 }
示例#3
0
        public object Clone()
        {
            LineRecord res = new LineRecord();

            res._backColor  = this._backColor;
            res._foreColor  = this._foreColor;
            res._lineNumber = this._lineNumber;
            res._modified   = this._modified;
            res._rangeIndex = this._rangeIndex;
            if (this._ranges != null)
            {
                res._ranges = new List <TextRange>();
                foreach (TextRange tr in this._ranges)
                {
                    res._ranges.Add((TextRange)tr.Clone());
                }
            }
            else
            {
                res._ranges = null;
            }
            res._text = this._text;
            return(res);
        }
示例#4
0
        private void PrepareDiff(string[] left, string[] right, List <LineRecord> leftrecs, List <LineRecord> rightrecs)
        {
            DiffList_TextFile file1 = new DiffList_TextFile(left);
            DiffList_TextFile file2 = new DiffList_TextFile(right);

            DiffEngine engine = new DiffEngine();

            engine.ProcessDiff(file1, file2, DiffEngineLevel.SlowPerfect);
            ArrayList report = engine.DiffReport();

            foreach (DiffResultSpan dres in report)
            {
                switch (dres.Status)
                {
                case DiffResultSpanStatus.NoChange:
                    for (int i = 0; i < dres.Length; i++)
                    {
                        LineRecord lrec = new LineRecord(i + dres.SourceIndex, left[i + dres.SourceIndex]);
                        leftrecs.Add(lrec);
                        LineRecord rrec = new LineRecord(i + dres.DestIndex, right[i + dres.DestIndex]);
                        rightrecs.Add(rrec);
                    }
                    break;

                case DiffResultSpanStatus.Replace:
                    for (int i = 0; i < dres.Length; i++)
                    {
                        LineRecord lrec = new LineRecord(i + dres.SourceIndex, left[i + dres.SourceIndex]);
                        lrec.BackColor = Color.Khaki;
                        leftrecs.Add(lrec);
                        LineRecord rrec = new LineRecord(i + dres.DestIndex, right[i + dres.DestIndex]);
                        rrec.BackColor = Color.Khaki;
                        rightrecs.Add(rrec);
                        ComputeLineDifferences(lrec, rrec);
                    }
                    break;

                case DiffResultSpanStatus.DeleteSource:
                    for (int i = 0; i < dres.Length; i++)
                    {
                        LineRecord lrec = new LineRecord(i + dres.SourceIndex, left[i + dres.SourceIndex]);
                        lrec.BackColor = Color.Khaki;
                        leftrecs.Add(lrec);
                        LineRecord rrec = new LineRecord();
                        rrec.BackColor = Color.LightGray;
                        rightrecs.Add(rrec);
                    }
                    break;

                case DiffResultSpanStatus.AddDestination:
                    for (int i = 0; i < dres.Length; i++)
                    {
                        LineRecord lrec = new LineRecord();
                        lrec.BackColor = Color.LightGray;
                        leftrecs.Add(lrec);
                        LineRecord rrec = new LineRecord(i + dres.DestIndex, right[i + dres.DestIndex]);
                        rrec.BackColor = Color.Khaki;
                        rightrecs.Add(rrec);
                    }
                    break;

                default:
                    break;
                } // switch
            }     // foreach
        }