Ejemplo n.º 1
0
        private void PerformCopy(TextEditorControl from, TextEditorControl to, int line, int length, int fromLength)
        {
            var fromDocument = from.Document;

            // Get the text we're going to copy.

            int fromStart = fromDocument.PositionToOffset(new TextLocation(
                                                              0,
                                                              line
                                                              ));
            int fromEnd = fromDocument.PositionToOffset(new TextLocation(
                                                            0,
                                                            line + fromLength
                                                            ));
            string fromText = fromDocument.GetText(fromStart, fromEnd - fromStart);

            UpdateEditor(from, () =>
            {
                // Remove the markers.

                int start = from.Document.PositionToOffset(new TextLocation(
                                                               0,
                                                               line
                                                               ));
                int end = from.Document.PositionToOffset(new TextLocation(
                                                             0,
                                                             line + length
                                                             ));

                from.Document.MarkerStrategy.RemoveAll(p => p.Offset >= start && p.EndOffset <= end);

                // Remove empty lines from the source editor.

                if (fromLength != length)
                {
                    start = from.Document.PositionToOffset(new TextLocation(
                                                               0,
                                                               line + fromLength
                                                               ));
                    from.Document.Remove(start, end - start);
                }
            });

            UpdateEditor(to, () =>
            {
                // Update the target.

                int start = to.Document.PositionToOffset(new TextLocation(
                                                             0,
                                                             line
                                                             ));
                int end = to.Document.PositionToOffset(new TextLocation(
                                                           0,
                                                           line + length
                                                           ));
                to.Document.Replace(start, end - start, fromText);
            });
        }
Ejemplo n.º 2
0
        private void RemoveFromDocument(TextEditorControl editor, int line, int length)
        {
            UpdateEditor(editor, () =>
            {
                var start = editor.Document.PositionToOffset(new TextLocation(
                                                                 0, line
                                                                 ));
                var end = editor.Document.PositionToOffset(new TextLocation(
                                                               0, line + length
                                                               ));

                editor.Document.Remove(start, end - start);
            });
        }
Ejemplo n.º 3
0
        protected override Control CreateClient()
        {
            var fontSettings = SettingsBuilder.GetSettings <IFontSettings>(this);

            var control = new TextEditorControl
            {
                Font = fontSettings.CodeFont ?? Constants.DefaultCodeFont,
                ConvertTabsToSpaces = true,
                Site = new SiteProxy(this)
            };

            HookEvents(control.ActiveTextAreaControl);

            return(control);
        }
Ejemplo n.º 4
0
 private void SyncTo(TextEditorControl source, TextEditorControl target)
 {
     source.ActiveTextAreaControl.HScrollBar.ValueChanged += (s, e) =>
     {
         target.ActiveTextAreaControl.TextArea.VirtualTop =
             source.ActiveTextAreaControl.TextArea.VirtualTop;
         source.ActiveTextAreaControl.TextArea.Update();
         target.ActiveTextAreaControl.TextArea.Update();
     };
     source.ActiveTextAreaControl.VScrollBar.ValueChanged += (s, e) =>
     {
         target.ActiveTextAreaControl.TextArea.VirtualTop =
             source.ActiveTextAreaControl.TextArea.VirtualTop;
         source.ActiveTextAreaControl.TextArea.Update();
         target.ActiveTextAreaControl.TextArea.Update();
     };
 }
Ejemplo n.º 5
0
        private void UpdateEditor(TextEditorControl editor, Action action)
        {
            var textArea = editor.ActiveTextAreaControl.TextArea;
            var document = textArea.Document;

            document.ReadOnly = false;

            try
            {
                textArea.BeginUpdate();

                action();

                textArea.Caret.ValidateCaretPos();
                textArea.EndUpdate();
                textArea.Refresh();
            }
            finally
            {
                document.ReadOnly = false;
            }
        }
Ejemplo n.º 6
0
 public TrimmedCopy(SideBySideViewer owner, TextEditorControl editor)
 {
     _owner = owner;
     _editor = editor;
 }
Ejemplo n.º 7
0
        private void UpdateEditor(TextEditorControl editor, Action action)
        {
            var textArea = editor.ActiveTextAreaControl.TextArea;
            var document = textArea.Document;

            document.ReadOnly = false;

            try
            {
                textArea.BeginUpdate();

                action();

                textArea.Caret.ValidateCaretPos();
                textArea.EndUpdate();
                textArea.Refresh();
            }
            finally
            {
                document.ReadOnly = false;
            }
        }
Ejemplo n.º 8
0
 private void SyncTo(TextEditorControl source, TextEditorControl target)
 {
     source.ActiveTextAreaControl.HScrollBar.ValueChanged += (s, e) =>
     {
         target.ActiveTextAreaControl.TextArea.VirtualTop =
             source.ActiveTextAreaControl.TextArea.VirtualTop;
         source.ActiveTextAreaControl.TextArea.Update();
         target.ActiveTextAreaControl.TextArea.Update();
     };
     source.ActiveTextAreaControl.VScrollBar.ValueChanged += (s, e) =>
     {
         target.ActiveTextAreaControl.TextArea.VirtualTop =
             source.ActiveTextAreaControl.TextArea.VirtualTop;
         source.ActiveTextAreaControl.TextArea.Update();
         target.ActiveTextAreaControl.TextArea.Update();
     };
 }
Ejemplo n.º 9
0
        private void RemoveFromDocument(TextEditorControl editor, int line, int length)
        {
            UpdateEditor(editor, () =>
            {
                var start = editor.Document.PositionToOffset(new TextLocation(
                    0, line
                ));
                var end = editor.Document.PositionToOffset(new TextLocation(
                    0, line + length
                ));

                editor.Document.Remove(start, end - start);
            });
        }
Ejemplo n.º 10
0
        private void PerformCopy(TextEditorControl from, TextEditorControl to, int line, int length, int fromLength)
        {
            var fromDocument = from.Document;

            // Get the text we're going to copy.

            int fromStart = fromDocument.PositionToOffset(new TextLocation(
                0,
                line
            ));
            int fromEnd = fromDocument.PositionToOffset(new TextLocation(
                0,
                line + fromLength
            ));
            string fromText = fromDocument.GetText(fromStart, fromEnd - fromStart);

            UpdateEditor(from, () =>
            {
                // Remove the markers.

                int start = from.Document.PositionToOffset(new TextLocation(
                    0,
                    line
                ));
                int end = from.Document.PositionToOffset(new TextLocation(
                    0,
                    line + length
                ));

                from.Document.MarkerStrategy.RemoveAll(p => p.Offset >= start && p.EndOffset <= end);

                // Remove empty lines from the source editor.

                if (fromLength != length)
                {
                    start = from.Document.PositionToOffset(new TextLocation(
                        0,
                        line + fromLength
                    ));
                    from.Document.Remove(start, end - start);
                }
            });

            UpdateEditor(to, () =>
            {
                // Update the target.

                int start = to.Document.PositionToOffset(new TextLocation(
                    0,
                    line
                ));
                int end = to.Document.PositionToOffset(new TextLocation(
                    0,
                    line + length
                ));
                to.Document.Replace(start, end - start, fromText);
            });
        }
Ejemplo n.º 11
0
        private string GetTrimmedText(TextEditorControl editor, int start, int end)
        {
            var document = editor.Document;

            // The document contains empty lines to fill up space because the
            // other side has more text. This removes these empty lines from
            // the output.

            var sb = new StringBuilder();

            bool isLeft = editor == _leftEditor;
            int offset = start;

            foreach (var marker in _markers)
            {
                int startLength = isLeft ? marker.LeftLength : marker.RightLength;
                int endLength = marker.Length;

                if (startLength != endLength)
                {
                    int markerStart = document.PositionToOffset(new TextLocation(
                        0,
                        marker.Line + startLength
                    ));
                    int markerEnd = document.PositionToOffset(new TextLocation(
                        0,
                        marker.Line + endLength
                    ));

                    if (markerStart < offset)
                        offset = markerEnd;

                    if (markerEnd > offset)
                    {
                        sb.Append(document.GetText(
                            offset,
                            Math.Min(markerStart, end) - offset
                        ));

                        offset = markerEnd;
                    }

                    if (offset >= end)
                        break;
                }
            }

            if (offset < end)
            {
                sb.Append(document.GetText(
                    offset,
                    end - offset
                ));
            }

            return sb.ToString();
        }
Ejemplo n.º 12
0
 public TrimmedCopy(SideBySideViewer owner, TextEditorControl editor)
 {
     _owner  = owner;
     _editor = editor;
 }
Ejemplo n.º 13
0
        private string GetTrimmedText(TextEditorControl editor, int start, int end)
        {
            var document = editor.Document;

            // The document contains empty lines to fill up space because the
            // other side has more text. This removes these empty lines from
            // the output.

            var sb = new StringBuilder();

            bool isLeft = editor == _leftEditor;
            int  offset = start;

            foreach (var marker in _markers)
            {
                int startLength = isLeft ? marker.LeftLength : marker.RightLength;
                int endLength   = marker.Length;

                if (startLength != endLength)
                {
                    int markerStart = document.PositionToOffset(new TextLocation(
                                                                    0,
                                                                    marker.Line + startLength
                                                                    ));
                    int markerEnd = document.PositionToOffset(new TextLocation(
                                                                  0,
                                                                  marker.Line + endLength
                                                                  ));

                    if (markerStart < offset)
                    {
                        offset = markerEnd;
                    }

                    if (markerEnd > offset)
                    {
                        sb.Append(document.GetText(
                                      offset,
                                      Math.Min(markerStart, end) - offset
                                      ));

                        offset = markerEnd;
                    }

                    if (offset >= end)
                    {
                        break;
                    }
                }
            }

            if (offset < end)
            {
                sb.Append(document.GetText(
                              offset,
                              end - offset
                              ));
            }

            return(sb.ToString());
        }
Ejemplo n.º 14
0
        protected override Control CreateClient()
        {
            var fontSettings = SettingsBuilder.GetSettings<IFontSettings>(this);

            var control = new TextEditorControl
            {
                Font = fontSettings.CodeFont ?? Constants.DefaultCodeFont,
                ConvertTabsToSpaces = true,
                Site = new SiteProxy(this)
            };

            HookEvents(control.ActiveTextAreaControl);

            return control;
        }