/// <summary>
        /// Links the specified rich text box to this rich text box.  Whenever either richtextbox
        /// scrolls, the other will scroll too.
        /// </summary>
        /// <param name="richTextBox">The RichTextBox to link.</param>
        public void AddLinkedRichTextBox(MyRichTextBox richTextBox)
        {
            if (richTextBox == this)
            {
                throw new ArgumentException("Cannot link a RichTextBox to itself!", "richTextBox");
            }

            if (!linkedRichTextBoxes.Contains(richTextBox))
            {
                //add the richtextbox to our list of linked richtextboxes
                linkedRichTextBoxes.Add(richTextBox);
                //add this to the richtextbox's list of linked richtextboxes
                richTextBox.AddLinkedRichTextBox(this);

                //make sure the RichTextBox is linked to all of the other RichTextBoxes that this RichTextBox is linked to
                for (int i = 0; i < linkedRichTextBoxes.Count; i++)
                {
                    //get the linked richtextbox
                    var linkedRichTextBox = linkedRichTextBoxes[i];
                    //link the richtextboxes together
                    if (linkedRichTextBox != richTextBox)
                    {
                        linkedRichTextBox.AddLinkedRichTextBox(richTextBox);
                    }
                }
            }
        }
        /// <summary>
        /// Sets the destination's scroll positions to that of the source.
        /// </summary>
        /// <param name="source">The source of the scroll positions.</param>
        /// <param name="dest">The destinations to set the scroll positions for.</param>
        private void SetScrollPositions(MyRichTextBox source, MyRichTextBox dest)
        {
            //get the scroll positions of the source
            int horizontal = User32.GetScrollPos(source.Handle, Orientation.Horizontal);
            int vertical   = User32.GetScrollPos(source.Handle, Orientation.Vertical);

            //set the scroll positions of the destination
            User32.SetScrollPos(dest.Handle, Orientation.Horizontal, horizontal, true);
            User32.SetScrollPos(dest.Handle, Orientation.Vertical, vertical, true);
        }
Example #3
0
        private void compareTexts(MyRichTextBox newRichTextBox, string newText, MyRichTextBox oldRichTextBox, string oldText)
        {
            ISideBySideDiffBuilder diffBuilder     = new SideBySideDiffBuilder(new Differ());
            SideBySideDiffModel    sideBySideModel = diffBuilder.BuildDiffModel(oldText, newText);

            colorRichTextBox(newRichTextBox, sideBySideModel.NewText.Lines, true);
            colorRichTextBox(oldRichTextBox, sideBySideModel.OldText.Lines, false);

            newRichTextBox.AddLinkedRichTextBox(oldRichTextBox);
        }
Example #4
0
        private void colorRichTextBox(MyRichTextBox richTextBox, List <DiffPiece> textLines, bool productionEnvironment)
        {
            commonClient commonClient = new commonClient();

            richTextBox.Text = "";

            foreach (DiffPiece diffPiece in textLines)
            {
                if (diffPiece.Type == ChangeType.Unchanged)
                {
                    richTextBox.AppendText(diffPiece.Text + "\n");
                }
                else if (diffPiece.Type == ChangeType.Inserted)
                {
                    if (productionEnvironment)
                    {
                        richTextBox.AppendText(diffPiece.Text + "\n", commonClient.insertedColor);
                    }
                    else
                    {
                        richTextBox.AppendText(diffPiece.Text + "\n", commonClient.deletedColor);
                    }
                }
                else if (diffPiece.Type == ChangeType.Deleted)
                {
                    if (productionEnvironment)
                    {
                        richTextBox.AppendText(diffPiece.Text + "\n", commonClient.deletedColor);
                    }
                    else
                    {
                        richTextBox.AppendText(diffPiece.Text + "\n", commonClient.insertedColor);
                    }
                }
                else if (diffPiece.Type == ChangeType.Modified)
                {
                    richTextBox.AppendText(diffPiece.Text + "\n", commonClient.modifiedColor);
                }
                else if (diffPiece.Type == ChangeType.Imaginary)
                {
                    richTextBox.AppendText(diffPiece.Text + "\n", commonClient.deletedColor);
                }
            }
        }