private void ShowDiff(DiffListText source, DiffListText destination, List <DiffResultSpan> DiffLines, double seconds) { currentIndex = 0; cmdDifferenceNext.Enabled = true; cmdDifferencePrevious.Enabled = true; differences = new List <int>(); rtbSourceScript.BeginUpdate(); rtbDestinationScript.BeginUpdate(); List <KeyValuePair <string, Color> > sourceLines = new List <KeyValuePair <string, Color> >(); List <KeyValuePair <string, Color> > destinationLines = new List <KeyValuePair <string, Color> >(); int i; foreach (DiffResultSpan drs in DiffLines) { switch (drs.Status) { case DiffResultSpanStatus.DeleteSource: differences.Add(sourceLines.Count); for (i = 0; i < drs.Length; i++) { sourceLines.Add(new KeyValuePair <string, Color>(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line, Color.Red)); destinationLines.Add(new KeyValuePair <string, Color>(new string(' ', ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line.Length), Color.Blue)); } break; case DiffResultSpanStatus.NoChange: for (i = 0; i < drs.Length; i++) { sourceLines.Add(new KeyValuePair <string, Color>(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line, Color.Empty)); destinationLines.Add(new KeyValuePair <string, Color>(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line, Color.Empty)); } break; case DiffResultSpanStatus.AddDestination: differences.Add(sourceLines.Count); for (i = 0; i < drs.Length; i++) { sourceLines.Add(new KeyValuePair <string, Color>(new string(' ', ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line.Length), Color.Blue)); destinationLines.Add(new KeyValuePair <string, Color>(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line, Color.Blue)); } break; case DiffResultSpanStatus.Replace: differences.Add(sourceLines.Count); for (i = 0; i < drs.Length; i++) { sourceLines.Add(new KeyValuePair <string, Color>(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line, Color.Red)); destinationLines.Add(new KeyValuePair <string, Color>(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line, Color.Green)); } break; } } FillScript(sourceLines, rtbSourceScript); FillScript(destinationLines, rtbDestinationScript); rtbSourceScript.EndUpdate(); rtbDestinationScript.EndUpdate(); this.Text = differences.Count + " differences."; }
private void ShowDiff(DiffListText source, DiffListText destination, ArrayList DiffLines) { this.lvSource.SuspendLayout(); this.lvDestination.SuspendLayout(); this.pbxNavigator.Image = (Image)null; Color color1 = Color.FromArgb((int)byte.MaxValue, 175, 238, 238); Color color2 = Color.FromArgb((int)byte.MaxValue, 152, 251, 152); Color color3 = Color.FromArgb((int)byte.MaxValue, (int)byte.MaxValue, 192, 203); int num = 1; foreach (DiffResultSpan diffLine in DiffLines) { switch (diffLine.Status) { case DiffResultSpanStatus.NoChange: for (int index = 0; index < diffLine.Length; ++index) { this.lvSource.Items.Add(new ListViewItem(num.ToString()) { SubItems = { ((TextLine)source.GetByIndex(diffLine.SourceIndex + index)).Line } }); this.lvDestination.Items.Add(new ListViewItem(num.ToString()) { SubItems = { ((TextLine)destination.GetByIndex(diffLine.DestIndex + index)).Line } }); ++num; } break; case DiffResultSpanStatus.Replace: this.lbxChangedLine.Items.Add(num.ToString()); for (int index = 0; index < diffLine.Length; ++index) { ListViewItem listViewItem1 = new ListViewItem(num.ToString()); listViewItem1.SubItems.Add(((TextLine)source.GetByIndex(diffLine.SourceIndex + index)).Line); this.lvSource.Items.Add(listViewItem1); ListViewItem listViewItem2 = new ListViewItem(num.ToString()); listViewItem2.SubItems.Add(((TextLine)destination.GetByIndex(diffLine.DestIndex + index)).Line); this.lvDestination.Items.Add(listViewItem2); listViewItem1.BackColor = listViewItem2.BackColor = color2; ++num; } break; case DiffResultSpanStatus.DeleteSource: this.lbxChangedLine.Items.Add(num.ToString()); for (int index = 0; index < diffLine.Length; ++index) { ListViewItem listViewItem1 = new ListViewItem(num.ToString()); listViewItem1.SubItems.Add(((TextLine)source.GetByIndex(diffLine.SourceIndex + index)).Line); this.lvSource.Items.Add(listViewItem1); ListViewItem listViewItem2 = new ListViewItem(num.ToString()); listViewItem2.SubItems.Add(""); this.lvDestination.Items.Add(listViewItem2); listViewItem1.BackColor = listViewItem2.BackColor = color3; ++num; } break; case DiffResultSpanStatus.AddDestination: this.lbxChangedLine.Items.Add(num.ToString()); for (int index = 0; index < diffLine.Length; ++index) { ListViewItem listViewItem1 = new ListViewItem(num.ToString()); listViewItem1.SubItems.Add(""); this.lvSource.Items.Add(listViewItem1); ListViewItem listViewItem2 = new ListViewItem(num.ToString()); listViewItem2.SubItems.Add(((TextLine)destination.GetByIndex(diffLine.DestIndex + index)).Line); this.lvDestination.Items.Add(listViewItem2); listViewItem1.BackColor = listViewItem2.BackColor = color1; ++num; } break; } } this.lvSource.ResumeLayout(); this.lvDestination.ResumeLayout(); this.lvSource.Scrollable = true; this.lvDestination.Scrollable = true; ++this.lvSource.Columns[0].Width; --this.lvSource.Columns[0].Width; ++this.lvDestination.Columns[0].Width; --this.lvDestination.Columns[0].Width; this.CreateNavigatorBitmap(); }