Esempio n. 1
0
        public ucFunction()
        {
            InitializeComponent();
            if (Utility.InDesignMode)
            {
                return;
            }

            EnableDoubleBuffering();
            syntaxEditor1.Height = ClientSize.Height - btnEdit.Bottom - Gap;
            //btnTest.Visible = false;
            if (_CurrentFunction != null)
            {
                ReconstructFunctionRunner();
            }

            syntaxEditor1.Document.SpanIndicatorLayers.Add(new SpanIndicatorLayer(BreakpointLayerKey, 1));
            syntaxEditor1.Document.SpanIndicatorLayers.Add(new SpanIndicatorLayer(CurrentStatementLayerKey, 10));

            syntaxEditorPreviewText.Document.SpanIndicatorLayers.Add(new SpanIndicatorLayer(NewPreviewTextLayerKey, 1));

            newTextHighlightStyle = new HighlightingStyle("New Text Style", "New Text", Color.Red, Color.LightGray);

            Controller.Instance.SettingChangedEvent += Instance_SettingChangedEvent;
            SetEditorFontSize((float)Settings.Default.EditorFontSize);

            OverrideFunctionChecked = true;
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // OBJECT
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes the <c>CustomReadOnlyRegionTagger</c> class.
        /// </summary>
        static CustomReadOnlyRegionTagger()
        {
            // Register the classification type with a grayed-out background
            IHighlightingStyle style = new HighlightingStyle(null, Color.FromArgb(0x40, 0xB0, 0xB0, 0xB0));

            AmbientHighlightingStyleRegistry.Instance.Register(ClassificationTypes.ReadOnlyRegion, style);
        }
Esempio n. 3
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // OBJECT
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes the <c>WordHighlightTagger</c> class.
        /// </summary>
        static WordHighlightTagger()
        {
            IHighlightingStyle style = new HighlightingStyle(null, Color.FromArgb(0x40, 0xC0, 0xC0, 0xC0));

            style.BorderColor      = Color.FromArgb(0xFF, 0xC0, 0xC0, 0xC0);
            style.BorderCornerKind = HighlightingStyleBorderCornerKind.Rounded;
            style.BorderKind       = LineKind.Solid;
            AmbientHighlightingStyleRegistry.Instance.Register(wordHighlightClassificationType, style);
        }
Esempio n. 4
0
        private static void DiffInSingleEditor(List<DiffMatchPatch.Diff> diffs, SyntaxEditor editor)
        {
            //editor.SuspendLayout();
            //editor.SuspendPainting();
            Document doc = new Document();

            Color backColorGreen = Color.FromArgb(230, 255, 230);
            Color backColorRed = Color.FromArgb(255, 230, 230);

            #region Deleted style
            SpanIndicatorLayer deletedLayer = new SpanIndicatorLayer("Deleted", 1000);
            HighlightingStyle deletedHighlightingStyle = new HighlightingStyle("Deleted", null, Color.Empty, backColorRed)
            {
                StrikeOutStyle = HighlightingStyleLineStyle.Solid,
                StrikeOutColor = Color.Red
            };
            doc.SpanIndicatorLayers.Add(deletedLayer);
            #endregion

            #region New style
            SpanIndicatorLayer newLayer = new SpanIndicatorLayer("New", 1000);
            HighlightingStyle newHighlightingStyle = new HighlightingStyle("New", null, Color.Empty, backColorGreen);
            doc.SpanIndicatorLayers.Add(newLayer);
            #endregion

            System.Text.StringBuilder sb = new System.Text.StringBuilder(10000);

            foreach (DiffMatchPatch.Diff aDiff in diffs)
                sb.Append(aDiff.text);

            doc.Text = sb.ToString();

            int start = 0;
            int endOffset = 0;
            int i = 0;

            foreach (DiffMatchPatch.Diff aDiff in diffs)
            {
                int diffLength = aDiff.text.Length;

                switch (aDiff.operation)
                {
                    case DiffMatchPatch.Operation.INSERT://green
                        start = i;
                        endOffset = i + diffLength;

                        if (endOffset > start)
                            newLayer.Add(new HighlightingStyleSpanIndicator("New", newHighlightingStyle), new TextRange(start, endOffset));

                        break;
                    case DiffMatchPatch.Operation.DELETE://red
                        start = i;
                        endOffset = i + diffLength;

                        if (endOffset > start)
                            deletedLayer.Add(new HighlightingStyleSpanIndicator("Deleted", deletedHighlightingStyle), new TextRange(start, endOffset));

                        break;
                    //case Operation.EQUAL:
                    //    start = i;// editor.Document.GetText(LineTerminator.Newline).Length;
                    //    //editor.Document.InsertText(DocumentModificationType.Custom, start, aDiff.text);
                    //    //editor.Document.AppendText(aDiff.text);
                    //    break;
                }
                //if (aDiff.operation != Operation.DELETE)
                i += diffLength;
            }
            editor.Document = doc;
            //editor.SelectedView.EnsureVisible(1, false);
            //editor.ResumeLayout();
            //editor.ResumePainting();
        }
Esempio n. 5
0
        /// <summary>
        /// Populates two Actipro SyntaxEditors with diff-highlighted text.
        /// </summary>
        /// <param name="editor1">Actipro SyntaxEditor</param>
        /// <param name="editor2">Actipro SyntaxEditor</param>
        /// <param name="text">Fully combined text.</param>
        /// <param name="lines1">Lines unique to the left file.</param>
        /// <param name="lines2">Lines unique to the right file.</param>
        public static void PopulateSyntaxEditors(
  ActiproSoftware.SyntaxEditor.SyntaxEditor editor1,
  ActiproSoftware.SyntaxEditor.SyntaxEditor editor2,
  string text,
  SlyceMerge.LineSpan[] lines1,
  SlyceMerge.LineSpan[] lines2)
        {
            editor1.Text = text;
            editor2.Text = text;

            for (int i = 0; i < lines1.Length; i++)
            {
                for (int lineCounter = lines1[i].StartLine; lineCounter <= lines1[i].EndLine; lineCounter++)
                {
                    editor1.Document.Lines[lineCounter].BackColor = ColourNewGen;
                    editor2.Document.Lines[lineCounter].BackColor = Color.LightGray;
                    editor2.Document.DeleteText(ActiproSoftware.SyntaxEditor.DocumentModificationType.Delete, editor2.Document.Lines[lineCounter].StartOffset, editor2.Document.Lines[lineCounter].Length);
                }
            }
            for (int i = 0; i < lines2.Length; i++)
            {
                for (int lineCounter = lines2[i].StartLine; lineCounter <= lines2[i].EndLine; lineCounter++)
                {
                    editor2.Document.Lines[lineCounter].BackColor = ColourNewGen;
                    editor1.Document.Lines[lineCounter].BackColor = Color.LightGray;
                    editor1.Document.DeleteText(ActiproSoftware.SyntaxEditor.DocumentModificationType.Delete, editor1.Document.Lines[lineCounter].StartOffset, editor1.Document.Lines[lineCounter].Length);
                }
            }
            // Compact the displays
            int lineCount1 = 0;
            int lineCount2 = 0;

            for (int i = editor1.Document.Lines.Count - 1; i >= -1; i--)
            {
                Color lineColor = Color.Empty;

                if (i >= 0)
                {
                    lineColor = editor1.Document.Lines[i].BackColor;
                }
                if (lineColor == Color.Empty && (lineCount1 + lineCount2) > 0)
                {
                    // Process counted lines
                    int startIndex = i + 1;
                    int condensedLineCount = Math.Max(lineCount1, lineCount2);
                    int numLinesToRemove = lineCount1 + lineCount2 - condensedLineCount;
                    int lastLine = startIndex + lineCount1 + lineCount2 - 1;

                    //if (numLinesToRemove > 0)
                    //{
                    //   // Walk backward when processing Left
                    //   for (int removeIndex = lastLine; removeIndex >= startIndex + condensedLineCount; removeIndex--)
                    //   {
                    //      editor1.Document.Lines[removeIndex].BackColor = editor1.Document.Lines[removeIndex + 1].BackColor;
                    //      editor1.Document.Lines.RemoveAt(removeIndex);

                    //      int newPos = lastLine - condensedLineCount - (lastLine - removeIndex);
                    //      string gg = editor2.Document.Lines[removeIndex].Text;
                    //      editor2.Document.Lines[newPos].Text = editor2.Document.Lines[removeIndex].Text;
                    //      editor2.Document.Lines[newPos].BackColor = editor2.Document.Lines[removeIndex].BackColor;
                    //      editor2.Document.Lines[removeIndex].BackColor = editor2.Document.Lines[removeIndex + 1].BackColor;
                    //      editor2.Document.Lines.RemoveAt(removeIndex);
                    //   }
                    //}
                    numLinesToRemove = Math.Min(lineCount1, lineCount2);
                    int linesRemoved1 = 0;
                    int linesRemoved2 = 0;

                    for (int x = startIndex + (lineCount1 + lineCount2); x >= startIndex; x--)
                    {
                        if (linesRemoved1 < numLinesToRemove &&
                            editor1.Document.Lines[x].BackColor == Color.LightGray)
                        {
                            editor1.Document.Lines[x].BackColor = editor1.Document.Lines[x + 1].BackColor;
                            editor1.Document.Lines.RemoveAt(x);
                            linesRemoved1++;
                        }
                        if (linesRemoved2 < numLinesToRemove &&
                            editor2.Document.Lines[x].BackColor == Color.LightGray)
                        {
                            editor2.Document.Lines[x].BackColor = editor2.Document.Lines[x + 1].BackColor;
                            editor2.Document.Lines.RemoveAt(x);
                            linesRemoved2++;
                        }
                    }
                    if (linesRemoved1 != linesRemoved2)
                        throw new Exception("Non-equal number of lines removed.");

                    //if (lineCount1 > lineCount2)
                    //{
                    //   // Remove trailing gray lines from editor2
                    //   for (int removeIndex = startIndex; removeIndex <= startIndex + numLinesToRemove; removeIndex++)
                    //   {
                    //      string q111 = editor1.Document.Lines[removeIndex].Text;
                    //      string gg = editor2.Document.Lines[removeIndex].Text;
                    //      editor2.Document.Lines.RemoveAt(removeIndex);
                    //   }
                    //}
                    //else if (lineCount2 > lineCount1)
                    //{
                    //   // Remove trailing gray lines from editor1
                    //   for (int removeIndex = lastLine; removeIndex >= startIndex + condensedLineCount; removeIndex--)
                    //   {
                    //      string q111 = editor1.Document.Lines[removeIndex].Text;
                    //      string gg = editor2.Document.Lines[removeIndex].Text;
                    //      editor1.Document.Lines.RemoveAt(removeIndex);
                    //   }
                    //}
                    lineCount1 = 0;
                    lineCount2 = 0;
                    continue;
                }
                else if (lineColor == ColourNewGen)
                {
                    lineCount1++;
                }
                else if (lineColor == Color.LightGray)
                {
                    lineCount2++;
                }
            }
            // Line Marker Colours, Strikethroughs
            string layerKey = "Diff";
            string indicatorKey = "Diff";
            SpanIndicatorLayer layer = new SpanIndicatorLayer(layerKey, 1000);
            HighlightingStyle highlightingStyle = new HighlightingStyle("Diff", null, Color.Empty, Color.Empty);
            highlightingStyle.StrikeOutStyle = HighlightingStyleLineStyle.Solid;
            highlightingStyle.StrikeOutColor = Color.Red;
            editor1.Document.SpanIndicatorLayers.Add(layer);

            int lineNumber1 = 1;
            int lineNumber2 = 1;

            for (int i = 0; i < editor1.Document.Lines.Count; i++)
            {
                // Set the line marker colours
                if (editor1.Document.Lines[i].BackColor == Color.LightGray &&
                    editor2.Document.Lines[i].BackColor == ColourNewGen)
                {
                    if (i > 0 && editor2.Document.Lines[i - 1].SelectionMarginMarkColor == changedMarkerColour)
                    {
                        editor2.Document.Lines[i].SelectionMarginMarkColor = changedMarkerColour;
                        editor2.Document.Lines[i].BackColor = Color.LightYellow;
                    }
                    else
                    {
                        editor2.Document.Lines[i].SelectionMarginMarkColor = addedMarkerColour;
                        editor2.Document.Lines[i].BackColor = Color.Honeydew;
                    }
                    editor1.Document.Lines[i].BackColor = Color.WhiteSmoke;
                    editor1.Document.Lines[i].CustomLineNumber = string.Empty;
                    editor2.Document.Lines[i].CustomLineNumber = lineNumber2.ToString();
                    lineNumber2++;
                }
                else if (editor1.Document.Lines[i].BackColor == ColourNewGen &&
                    editor2.Document.Lines[i].BackColor == Color.LightGray)
                {
                    editor2.Document.Lines[i].SelectionMarginMarkColor = deletedMarkerColour;
                    editor1.Document.Lines[i].BackColor = Color.MistyRose;
                    editor2.Document.Lines[i].BackColor = Color.WhiteSmoke;
                    editor1.Document.Lines[i].CustomLineNumber = lineNumber1.ToString();
                    editor2.Document.Lines[i].CustomLineNumber = string.Empty;
                    lineNumber1++;
                }
                else if (editor1.Document.Lines[i].BackColor == ColourNewGen &&
                    editor2.Document.Lines[i].BackColor == ColourNewGen)
                {
                    editor2.Document.Lines[i].SelectionMarginMarkColor = changedMarkerColour;
                    editor1.Document.Lines[i].BackColor = Color.LightYellow;
                    editor2.Document.Lines[i].BackColor = Color.LightYellow;
                    layer.Add(new HighlightingStyleSpanIndicator(indicatorKey, highlightingStyle), editor1.Document.Lines[i].TextRange);
                    editor1.Document.Lines[i].CustomLineNumber = lineNumber1.ToString();
                    editor2.Document.Lines[i].CustomLineNumber = lineNumber2.ToString();
                    lineNumber1++;
                    lineNumber2++;
                }
                else
                {
                    editor1.Document.Lines[i].CustomLineNumber = lineNumber1.ToString();
                    editor2.Document.Lines[i].CustomLineNumber = lineNumber2.ToString();
                    lineNumber1++;
                    lineNumber2++;
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Populates a single Actipro SyntaxEditor with diff-highlighted text.
        /// </summary>
        /// <param name="editor">Actipro SyntaxEditor</param>
        /// <param name="text">Fully combined text.</param>
        /// <param name="newLines">Lines unique to the new file.</param>
        /// <param name="oldLines">Lines unique to the original file.</param>
        /// <param name="strikeoutLine2Lines"></param>
        public static void PopulateSyntaxEditor(ActiproSoftware.SyntaxEditor.SyntaxEditor editor, string text, SlyceMerge.LineSpan[] newLines, SlyceMerge.LineSpan[] oldLines, bool strikeoutLine2Lines)
        {
            editor.Text = text;
            SpanIndicatorLayer layer = null;
            HighlightingStyle highlightingStyle = null;
            List<int> linesToNotCount = new List<int>();

            if (strikeoutLine2Lines)
            {
                layer = new SpanIndicatorLayer("Diff", 1000);
                highlightingStyle = new HighlightingStyle("Diff", null, Color.Empty, Color.Empty);
                highlightingStyle.StrikeOutStyle = HighlightingStyleLineStyle.Solid;
                highlightingStyle.StrikeOutColor = Color.Red;
                editor.Document.SpanIndicatorLayers.Add(layer);
            }
            for (int i = 0; i < oldLines.Length; i++)
            {
                if (strikeoutLine2Lines)
                {
                    for (int lineCounter = oldLines[i].StartLine; lineCounter <= oldLines[i].EndLine; lineCounter++)
                    {
                        editor.Document.Lines[lineCounter].BackColor = Color.MistyRose;// ColourUser;
                        editor.Document.Lines[lineCounter].SelectionMarginMarkColor = deletedMarkerColour;// changedMarkerColour;
                        editor.Document.Lines[lineCounter].CustomLineNumber = String.Empty;
                        layer.Add(new HighlightingStyleSpanIndicator("Diff", highlightingStyle), editor.Document.Lines[lineCounter].TextRange);
                        linesToNotCount.Add(lineCounter);
                    }
                }
                else
                {
                    for (int lineCounter = oldLines[i].StartLine; lineCounter <= oldLines[i].EndLine; lineCounter++)
                    {
                        editor.Document.Lines[lineCounter].BackColor = ColourNewGen;
                        editor.Document.Lines[lineCounter].SelectionMarginMarkColor = addedMarkerColour;
                    }
                }
            }
            for (int i = 0; i < newLines.Length; i++)
            {
                for (int lineCounter = newLines[i].StartLine; lineCounter <= newLines[i].EndLine; lineCounter++)
                {
                    editor.Document.Lines[lineCounter].BackColor = Color.Honeydew;// ColourUser;
                    editor.Document.Lines[lineCounter].SelectionMarginMarkColor = addedMarkerColour;// changedMarkerColour;
                }
            }
            // Fix-up changed vs. new/deleted
            for (int i = 0; i < editor.Document.Lines.Count; i++)
            {
                if (editor.Document.Lines[i].SelectionMarginMarkColor == addedMarkerColour)
                {
                    int startLine = i;
                    int endLine = -1;
                    bool changeProcessed = false;

                    for (int checkCounter = i + 1; checkCounter < editor.Document.Lines.Count; checkCounter++)
                    {
                        if (changeProcessed)
                        {
                            break;
                        }
                        if (editor.Document.Lines[checkCounter].SelectionMarginMarkColor == addedMarkerColour)
                        {
                            continue;
                        }
                        else if (editor.Document.Lines[checkCounter].SelectionMarginMarkColor == deletedMarkerColour)
                        {
                            // We have found a change
                            for (int deleteCounter = checkCounter + 1; deleteCounter < editor.Document.Lines.Count; deleteCounter++)
                            {
                                if (editor.Document.Lines[deleteCounter].SelectionMarginMarkColor != deletedMarkerColour)
                                {
                                    endLine = deleteCounter - 1;

                                    // Apply the Change colouring
                                    for (int changeCounter = startLine; changeCounter <= endLine; changeCounter++)
                                    {
                                        editor.Document.Lines[changeCounter].SelectionMarginMarkColor = changedMarkerColour;
                                        editor.Document.Lines[changeCounter].BackColor = Color.LightYellow;
                                    }
                                    changeProcessed = true;
                                    // We are back to 'normal' lines - no change found
                                    i = checkCounter;
                                    break;
                                }
                                else
                                {
                                    editor.Document.Lines[deleteCounter].CustomLineNumber = string.Empty;
                                }
                            }
                        }
                        else
                        {
                            // We are back to 'normal' lines - no change found
                            i = checkCounter;
                            break;
                        }
                    }
                }
            }
            int lineNumber = 1;
            for (int i = 0; i < editor.Document.Lines.Count; i++)
            {
                if (linesToNotCount.Contains(i))
                {
                    editor.Document.Lines[i].CustomLineNumber = string.Empty;
                }
                else
                {
                    editor.Document.Lines[i].CustomLineNumber = lineNumber.ToString();
                    lineNumber++;
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Populates a single Actipro SyntaxEditor with diff-highlighted text.
        /// </summary>
        /// <param name="editor">Actipro SyntaxEditor</param>
        /// <param name="text">Fully combined text.</param>
        /// <param name="newLines">Lines unique to the new file.</param>
        /// <param name="oldLines">Lines unique to the original file.</param>
        /// <param name="strikeoutLine2Lines"></param>
        public static void PopulateSyntaxEditor(ActiproSoftware.SyntaxEditor.SyntaxEditor editor, string text, SlyceMerge.LineSpan[] newLines, SlyceMerge.LineSpan[] oldLines, bool strikeoutLine2Lines)
        {
            editor.Text = text;
            SpanIndicatorLayer layer             = null;
            HighlightingStyle  highlightingStyle = null;
            List <int>         linesToNotCount   = new List <int>();

            if (strikeoutLine2Lines)
            {
                layer             = new SpanIndicatorLayer("Diff", 1000);
                highlightingStyle = new HighlightingStyle("Diff", null, Color.Empty, Color.Empty);
                highlightingStyle.StrikeOutStyle = HighlightingStyleLineStyle.Solid;
                highlightingStyle.StrikeOutColor = Color.Red;
                editor.Document.SpanIndicatorLayers.Add(layer);
            }
            for (int i = 0; i < oldLines.Length; i++)
            {
                if (strikeoutLine2Lines)
                {
                    for (int lineCounter = oldLines[i].StartLine; lineCounter <= oldLines[i].EndLine; lineCounter++)
                    {
                        editor.Document.Lines[lineCounter].BackColor = Color.MistyRose;                        // ColourUser;
                        editor.Document.Lines[lineCounter].SelectionMarginMarkColor = deletedMarkerColour;     // changedMarkerColour;
                        editor.Document.Lines[lineCounter].CustomLineNumber         = String.Empty;
                        layer.Add(new HighlightingStyleSpanIndicator("Diff", highlightingStyle), editor.Document.Lines[lineCounter].TextRange);
                        linesToNotCount.Add(lineCounter);
                    }
                }
                else
                {
                    for (int lineCounter = oldLines[i].StartLine; lineCounter <= oldLines[i].EndLine; lineCounter++)
                    {
                        editor.Document.Lines[lineCounter].BackColor = ColourNewGen;
                        editor.Document.Lines[lineCounter].SelectionMarginMarkColor = addedMarkerColour;
                    }
                }
            }
            for (int i = 0; i < newLines.Length; i++)
            {
                for (int lineCounter = newLines[i].StartLine; lineCounter <= newLines[i].EndLine; lineCounter++)
                {
                    editor.Document.Lines[lineCounter].BackColor = Color.Honeydew;                    // ColourUser;
                    editor.Document.Lines[lineCounter].SelectionMarginMarkColor = addedMarkerColour;  // changedMarkerColour;
                }
            }
            // Fix-up changed vs. new/deleted
            for (int i = 0; i < editor.Document.Lines.Count; i++)
            {
                if (editor.Document.Lines[i].SelectionMarginMarkColor == addedMarkerColour)
                {
                    int  startLine       = i;
                    int  endLine         = -1;
                    bool changeProcessed = false;

                    for (int checkCounter = i + 1; checkCounter < editor.Document.Lines.Count; checkCounter++)
                    {
                        if (changeProcessed)
                        {
                            break;
                        }
                        if (editor.Document.Lines[checkCounter].SelectionMarginMarkColor == addedMarkerColour)
                        {
                            continue;
                        }
                        else if (editor.Document.Lines[checkCounter].SelectionMarginMarkColor == deletedMarkerColour)
                        {
                            // We have found a change
                            for (int deleteCounter = checkCounter + 1; deleteCounter < editor.Document.Lines.Count; deleteCounter++)
                            {
                                if (editor.Document.Lines[deleteCounter].SelectionMarginMarkColor != deletedMarkerColour)
                                {
                                    endLine = deleteCounter - 1;

                                    // Apply the Change colouring
                                    for (int changeCounter = startLine; changeCounter <= endLine; changeCounter++)
                                    {
                                        editor.Document.Lines[changeCounter].SelectionMarginMarkColor = changedMarkerColour;
                                        editor.Document.Lines[changeCounter].BackColor = Color.LightYellow;
                                    }
                                    changeProcessed = true;
                                    // We are back to 'normal' lines - no change found
                                    i = checkCounter;
                                    break;
                                }
                                else
                                {
                                    editor.Document.Lines[deleteCounter].CustomLineNumber = string.Empty;
                                }
                            }
                        }
                        else
                        {
                            // We are back to 'normal' lines - no change found
                            i = checkCounter;
                            break;
                        }
                    }
                }
            }
            int lineNumber = 1;

            for (int i = 0; i < editor.Document.Lines.Count; i++)
            {
                if (linesToNotCount.Contains(i))
                {
                    editor.Document.Lines[i].CustomLineNumber = string.Empty;
                }
                else
                {
                    editor.Document.Lines[i].CustomLineNumber = lineNumber.ToString();
                    lineNumber++;
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Populates two Actipro SyntaxEditors with diff-highlighted text.
        /// </summary>
        /// <param name="editor1">Actipro SyntaxEditor</param>
        /// <param name="editor2">Actipro SyntaxEditor</param>
        /// <param name="text">Fully combined text.</param>
        /// <param name="lines1">Lines unique to the left file.</param>
        /// <param name="lines2">Lines unique to the right file.</param>
        public static void PopulateSyntaxEditors(
            ActiproSoftware.SyntaxEditor.SyntaxEditor editor1,
            ActiproSoftware.SyntaxEditor.SyntaxEditor editor2,
            string text,
            SlyceMerge.LineSpan[] lines1,
            SlyceMerge.LineSpan[] lines2)
        {
            editor1.Text = text;
            editor2.Text = text;

            for (int i = 0; i < lines1.Length; i++)
            {
                for (int lineCounter = lines1[i].StartLine; lineCounter <= lines1[i].EndLine; lineCounter++)
                {
                    editor1.Document.Lines[lineCounter].BackColor = ColourNewGen;
                    editor2.Document.Lines[lineCounter].BackColor = Color.LightGray;
                    editor2.Document.DeleteText(ActiproSoftware.SyntaxEditor.DocumentModificationType.Delete, editor2.Document.Lines[lineCounter].StartOffset, editor2.Document.Lines[lineCounter].Length);
                }
            }
            for (int i = 0; i < lines2.Length; i++)
            {
                for (int lineCounter = lines2[i].StartLine; lineCounter <= lines2[i].EndLine; lineCounter++)
                {
                    editor2.Document.Lines[lineCounter].BackColor = ColourNewGen;
                    editor1.Document.Lines[lineCounter].BackColor = Color.LightGray;
                    editor1.Document.DeleteText(ActiproSoftware.SyntaxEditor.DocumentModificationType.Delete, editor1.Document.Lines[lineCounter].StartOffset, editor1.Document.Lines[lineCounter].Length);
                }
            }
            // Compact the displays
            int lineCount1 = 0;
            int lineCount2 = 0;

            for (int i = editor1.Document.Lines.Count - 1; i >= -1; i--)
            {
                Color lineColor = Color.Empty;

                if (i >= 0)
                {
                    lineColor = editor1.Document.Lines[i].BackColor;
                }
                if (lineColor == Color.Empty && (lineCount1 + lineCount2) > 0)
                {
                    // Process counted lines
                    int startIndex         = i + 1;
                    int condensedLineCount = Math.Max(lineCount1, lineCount2);
                    int numLinesToRemove   = lineCount1 + lineCount2 - condensedLineCount;
                    int lastLine           = startIndex + lineCount1 + lineCount2 - 1;

                    //if (numLinesToRemove > 0)
                    //{
                    //   // Walk backward when processing Left
                    //   for (int removeIndex = lastLine; removeIndex >= startIndex + condensedLineCount; removeIndex--)
                    //   {
                    //      editor1.Document.Lines[removeIndex].BackColor = editor1.Document.Lines[removeIndex + 1].BackColor;
                    //      editor1.Document.Lines.RemoveAt(removeIndex);

                    //      int newPos = lastLine - condensedLineCount - (lastLine - removeIndex);
                    //      string gg = editor2.Document.Lines[removeIndex].Text;
                    //      editor2.Document.Lines[newPos].Text = editor2.Document.Lines[removeIndex].Text;
                    //      editor2.Document.Lines[newPos].BackColor = editor2.Document.Lines[removeIndex].BackColor;
                    //      editor2.Document.Lines[removeIndex].BackColor = editor2.Document.Lines[removeIndex + 1].BackColor;
                    //      editor2.Document.Lines.RemoveAt(removeIndex);
                    //   }
                    //}
                    numLinesToRemove = Math.Min(lineCount1, lineCount2);
                    int linesRemoved1 = 0;
                    int linesRemoved2 = 0;

                    for (int x = startIndex + (lineCount1 + lineCount2); x >= startIndex; x--)
                    {
                        if (linesRemoved1 < numLinesToRemove &&
                            editor1.Document.Lines[x].BackColor == Color.LightGray)
                        {
                            editor1.Document.Lines[x].BackColor = editor1.Document.Lines[x + 1].BackColor;
                            editor1.Document.Lines.RemoveAt(x);
                            linesRemoved1++;
                        }
                        if (linesRemoved2 < numLinesToRemove &&
                            editor2.Document.Lines[x].BackColor == Color.LightGray)
                        {
                            editor2.Document.Lines[x].BackColor = editor2.Document.Lines[x + 1].BackColor;
                            editor2.Document.Lines.RemoveAt(x);
                            linesRemoved2++;
                        }
                    }
                    if (linesRemoved1 != linesRemoved2)
                    {
                        throw new Exception("Non-equal number of lines removed.");
                    }

                    //if (lineCount1 > lineCount2)
                    //{
                    //   // Remove trailing gray lines from editor2
                    //   for (int removeIndex = startIndex; removeIndex <= startIndex + numLinesToRemove; removeIndex++)
                    //   {
                    //      string q111 = editor1.Document.Lines[removeIndex].Text;
                    //      string gg = editor2.Document.Lines[removeIndex].Text;
                    //      editor2.Document.Lines.RemoveAt(removeIndex);
                    //   }
                    //}
                    //else if (lineCount2 > lineCount1)
                    //{
                    //   // Remove trailing gray lines from editor1
                    //   for (int removeIndex = lastLine; removeIndex >= startIndex + condensedLineCount; removeIndex--)
                    //   {
                    //      string q111 = editor1.Document.Lines[removeIndex].Text;
                    //      string gg = editor2.Document.Lines[removeIndex].Text;
                    //      editor1.Document.Lines.RemoveAt(removeIndex);
                    //   }
                    //}
                    lineCount1 = 0;
                    lineCount2 = 0;
                    continue;
                }
                else if (lineColor == ColourNewGen)
                {
                    lineCount1++;
                }
                else if (lineColor == Color.LightGray)
                {
                    lineCount2++;
                }
            }
            // Line Marker Colours, Strikethroughs
            string             layerKey          = "Diff";
            string             indicatorKey      = "Diff";
            SpanIndicatorLayer layer             = new SpanIndicatorLayer(layerKey, 1000);
            HighlightingStyle  highlightingStyle = new HighlightingStyle("Diff", null, Color.Empty, Color.Empty);

            highlightingStyle.StrikeOutStyle = HighlightingStyleLineStyle.Solid;
            highlightingStyle.StrikeOutColor = Color.Red;
            editor1.Document.SpanIndicatorLayers.Add(layer);

            int lineNumber1 = 1;
            int lineNumber2 = 1;

            for (int i = 0; i < editor1.Document.Lines.Count; i++)
            {
                // Set the line marker colours
                if (editor1.Document.Lines[i].BackColor == Color.LightGray &&
                    editor2.Document.Lines[i].BackColor == ColourNewGen)
                {
                    if (i > 0 && editor2.Document.Lines[i - 1].SelectionMarginMarkColor == changedMarkerColour)
                    {
                        editor2.Document.Lines[i].SelectionMarginMarkColor = changedMarkerColour;
                        editor2.Document.Lines[i].BackColor = Color.LightYellow;
                    }
                    else
                    {
                        editor2.Document.Lines[i].SelectionMarginMarkColor = addedMarkerColour;
                        editor2.Document.Lines[i].BackColor = Color.Honeydew;
                    }
                    editor1.Document.Lines[i].BackColor        = Color.WhiteSmoke;
                    editor1.Document.Lines[i].CustomLineNumber = string.Empty;
                    editor2.Document.Lines[i].CustomLineNumber = lineNumber2.ToString();
                    lineNumber2++;
                }
                else if (editor1.Document.Lines[i].BackColor == ColourNewGen &&
                         editor2.Document.Lines[i].BackColor == Color.LightGray)
                {
                    editor2.Document.Lines[i].SelectionMarginMarkColor = deletedMarkerColour;
                    editor1.Document.Lines[i].BackColor        = Color.MistyRose;
                    editor2.Document.Lines[i].BackColor        = Color.WhiteSmoke;
                    editor1.Document.Lines[i].CustomLineNumber = lineNumber1.ToString();
                    editor2.Document.Lines[i].CustomLineNumber = string.Empty;
                    lineNumber1++;
                }
                else if (editor1.Document.Lines[i].BackColor == ColourNewGen &&
                         editor2.Document.Lines[i].BackColor == ColourNewGen)
                {
                    editor2.Document.Lines[i].SelectionMarginMarkColor = changedMarkerColour;
                    editor1.Document.Lines[i].BackColor = Color.LightYellow;
                    editor2.Document.Lines[i].BackColor = Color.LightYellow;
                    layer.Add(new HighlightingStyleSpanIndicator(indicatorKey, highlightingStyle), editor1.Document.Lines[i].TextRange);
                    editor1.Document.Lines[i].CustomLineNumber = lineNumber1.ToString();
                    editor2.Document.Lines[i].CustomLineNumber = lineNumber2.ToString();
                    lineNumber1++;
                    lineNumber2++;
                }
                else
                {
                    editor1.Document.Lines[i].CustomLineNumber = lineNumber1.ToString();
                    editor2.Document.Lines[i].CustomLineNumber = lineNumber2.ToString();
                    lineNumber1++;
                    lineNumber2++;
                }
            }
        }
Esempio n. 9
0
        private static void DiffInSingleEditor(List <DiffMatchPatch.Diff> diffs, SyntaxEditor editor)
        {
            //editor.SuspendLayout();
            //editor.SuspendPainting();
            Document doc = new Document();

            Color backColorGreen = Color.FromArgb(230, 255, 230);
            Color backColorRed   = Color.FromArgb(255, 230, 230);

            #region Deleted style
            SpanIndicatorLayer deletedLayer             = new SpanIndicatorLayer("Deleted", 1000);
            HighlightingStyle  deletedHighlightingStyle = new HighlightingStyle("Deleted", null, Color.Empty, backColorRed)
            {
                StrikeOutStyle = HighlightingStyleLineStyle.Solid,
                StrikeOutColor = Color.Red
            };
            doc.SpanIndicatorLayers.Add(deletedLayer);
            #endregion

            #region New style
            SpanIndicatorLayer newLayer             = new SpanIndicatorLayer("New", 1000);
            HighlightingStyle  newHighlightingStyle = new HighlightingStyle("New", null, Color.Empty, backColorGreen);
            doc.SpanIndicatorLayers.Add(newLayer);
            #endregion

            System.Text.StringBuilder sb = new System.Text.StringBuilder(10000);

            foreach (DiffMatchPatch.Diff aDiff in diffs)
            {
                sb.Append(aDiff.text);
            }

            doc.Text = sb.ToString();

            int start     = 0;
            int endOffset = 0;
            int i         = 0;

            foreach (DiffMatchPatch.Diff aDiff in diffs)
            {
                int diffLength = aDiff.text.Length;

                switch (aDiff.operation)
                {
                case DiffMatchPatch.Operation.INSERT:                        //green
                    start     = i;
                    endOffset = i + diffLength;

                    if (endOffset > start)
                    {
                        newLayer.Add(new HighlightingStyleSpanIndicator("New", newHighlightingStyle), new TextRange(start, endOffset));
                    }

                    break;

                case DiffMatchPatch.Operation.DELETE:                        //red
                    start     = i;
                    endOffset = i + diffLength;

                    if (endOffset > start)
                    {
                        deletedLayer.Add(new HighlightingStyleSpanIndicator("Deleted", deletedHighlightingStyle), new TextRange(start, endOffset));
                    }

                    break;
                    //case Operation.EQUAL:
                    //    start = i;// editor.Document.GetText(LineTerminator.Newline).Length;
                    //    //editor.Document.InsertText(DocumentModificationType.Custom, start, aDiff.text);
                    //    //editor.Document.AppendText(aDiff.text);
                    //    break;
                }
                //if (aDiff.operation != Operation.DELETE)
                i += diffLength;
            }
            editor.Document = doc;
            //editor.SelectedView.EnsureVisible(1, false);
            //editor.ResumeLayout();
            //editor.ResumePainting();
        }
Esempio n. 10
0
 public LuatWarningSpanIndicator(HighlightingStyle style, LuatWarning[] warnings)
     : base(style.ForeColor)
 {
     Warnings = warnings;
 }