Exemplo n.º 1
0
        private void InvalidateTextEditors()
        {
            SourceTextArea.Invalidate();
            SourceTextArea.Update();

            DestTextArea.Invalidate();
            DestTextArea.Update();
        }
Exemplo n.º 2
0
        private void DisplayDiff(TextDiff source, TextDiff destination, ArrayList DiffLines)
        {
            CleanResultTextEditors();
            int cnt = 1;
            int i;

            try
            {
                _isDisplayingDiff  = true;
                SourceDoc.ReadOnly = false;
                DestDoc.ReadOnly   = false;
                SourceTextArea.BeginUpdate();
                DestTextArea.BeginUpdate();



                foreach (DiffResultSpan drs in DiffLines)
                {
                    switch (drs.Status)
                    {
                    case DiffResultSpanStatus.DeleteSource:
                        for (i = 0; i < drs.Length; i++)
                        {
                            var line = ((DiffTextLine)source.GetByIndex(drs.SourceIndex + i)).Line + "\n";
                            SourceTextArea.InsertString(line);
                            //SourceDoc.CustomLineManager.AddCustomLine(cnt - 1, Color.MistyRose, false);

                            var segment = SourceDoc.GetLineSegment(cnt - 1);
                            if (segment.Length > 0)
                            {
                                var marker = new TextMarker(segment.Offset, segment.Length, TextMarkerType.SolidBlock, Color.Green, Color.White);
                                SourceDoc.MarkerStrategy.AddMarker(marker);
                            }

                            DestTextArea.InsertString("\n");
                            DestDoc.CustomLineManager.AddCustomLine(cnt - 1, Color.LightGray, false);

                            cnt++;
                        }
                        break;

                    case DiffResultSpanStatus.NoChange:
                        for (i = 0; i < drs.Length; i++)
                        {
                            var bgColor = SourceDoc.HighlightingStrategy.GetColorFor("Default");
                            SourceTextArea.InsertString(((DiffTextLine)source.GetByIndex(drs.SourceIndex + i)).Line + "\n");
                            //SourceDoc.CustomLineManager.AddCustomLine(cnt - 1, bgColor != null ? bgColor.BackgroundColor : Color.White, false);

                            bgColor = DestDoc.HighlightingStrategy.GetColorFor("Default");
                            DestTextArea.InsertString(((DiffTextLine)destination.GetByIndex(drs.DestIndex + i)).Line + "\n");
                            //DestDoc.CustomLineManager.AddCustomLine(cnt - 1, bgColor != null ? bgColor.BackgroundColor : Color.White, false);

                            cnt++;
                        }

                        break;

                    case DiffResultSpanStatus.AddDestination:
                        for (i = 0; i < drs.Length; i++)
                        {
                            SourceTextArea.InsertString("\n");
                            SourceDoc.CustomLineManager.AddCustomLine(cnt - 1, Color.LightGray, false);

                            var line = ((DiffTextLine)destination.GetByIndex(drs.DestIndex + i)).Line + "\n";
                            DestTextArea.InsertString(line);

                            var segment = DestDoc.GetLineSegment(cnt - 1);
                            if (segment.Length > 0)
                            {
                                var marker = new TextMarker(segment.Offset, segment.Length, TextMarkerType.SolidBlock, Color.Red, Color.White);
                                DestDoc.MarkerStrategy.AddMarker(marker);
                            }

                            //DestDoc.CustomLineManager.AddCustomLine(cnt - 1, Color.LightGreen, false);

                            cnt++;
                        }

                        break;

                    case DiffResultSpanStatus.Replace:

                        for (i = 0; i < drs.Length; i++)
                        {
                            var line = ((DiffTextLine)source.GetByIndex(drs.SourceIndex + i)).Line + "\n";
                            SourceTextArea.InsertString(line);
                            //SourceDoc.CustomLineManager.AddCustomLine(cnt - 1, Color.MistyRose, false);
                            var segment = SourceDoc.GetLineSegment(cnt - 1);
                            if (segment.Length > 0)
                            {
                                var marker = new TextMarker(segment.Offset, segment.Length, TextMarkerType.SolidBlock, Color.Gold, Color.Black);
                                SourceDoc.MarkerStrategy.AddMarker(marker);
                            }


                            line = ((DiffTextLine)destination.GetByIndex(drs.DestIndex + i)).Line + "\n";
                            DestTextArea.InsertString(line);

                            segment = DestDoc.GetLineSegment(cnt - 1);
                            if (segment.Length > 0)
                            {
                                var marker = new TextMarker(segment.Offset, segment.Length, TextMarkerType.SolidBlock, Color.Gold, Color.Black);
                                DestDoc.MarkerStrategy.AddMarker(marker);
                            }

                            //DestDoc.CustomLineManager.AddCustomLine(cnt - 1, Color.LightGreen, false);
                            cnt++;
                        }

                        break;
                    }
                }
            }
            finally
            {
                SourceTextArea.EndUpdate();
                DestTextArea.EndUpdate();

                SourceTextArea.ScrollTo(0);
                DestTextArea.ScrollTo(0);
                _isDisplayingDiff  = false;
                SourceDoc.ReadOnly = true;
                DestDoc.ReadOnly   = true;
            }
        }