Exemplo n.º 1
0
        public override void Undo(RichTextBox edit)
        {
            FlowDocument document = edit.Document;

            __DataStream.Seek(0, SeekOrigin.Begin);
            TextRange whole = new TextRange(document.ContentStart, document.ContentEnd);

            TextPointer start = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetStart);

            whole.Select(start, start);
            whole.Load(__DataStream, DataFormats.Xaml);
            TextPointer caretPosition = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetCursorPosition);

            edit.CaretPosition = caretPosition;

            UpdateOffsets(edit, whole);

            if (__IsBlockSelected)
            {
                // Пересчитать ещё раз start
                start = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetStart);
                TextPointer end = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetEnd);
                edit.Selection.Select(start, end);
            }
        }
Exemplo n.º 2
0
        private void PerformUndo(FlowDocument document, RichTextBox edit)
        {
            __DataStream.Seek(0, SeekOrigin.Begin);

            if (__OffsetCursorPositionBefore != -1)
            {
                __OffsetCursorPositionAfter = document.ContentStart.GetOffsetToPosition(edit.CaretPosition);
            }

            TextPointer start = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, selectionStartOffset);
            TextPointer end   = UndoHelpers.SafePositionAtOffset(document, document.ContentEnd, selectionEndOffset);

            TextRange whole = new TextRange(start, end);

            __UndoStream = new MemoryStream();
            whole.Save(__UndoStream, DataFormats.Xaml);
            whole.Load(__DataStream, DataFormats.Xaml);

            UpdateSelectionOffsets(edit, whole);

            if (__OffsetCursorPositionBefore != -1)
            {
                edit.CaretPosition = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetCursorPositionBefore);
            }
            else
            {
                if (edit != null)
                {
                    edit.Selection.Select(start, end);
                }
            }
        }
 public override void Redo(RichTextBox edit)
 {
     edit.CaretPosition = UndoHelpers.SafePositionAtOffset(edit.Document, edit.Document.ContentStart, __OffsetCursorPosition);
     edit.Selection.Select(edit.CaretPosition, edit.CaretPosition);
     edit.Selection.ApplyPropertyValue(RichTextBox.FontWeightProperty, __RedoFontWeight);
     edit.Selection.ApplyPropertyValue(RichTextBox.FontFamilyProperty, __RedoFontFamily);
     edit.Selection.ApplyPropertyValue(RichTextBox.FontSizeProperty, __RedoFontSize);
     edit.Selection.ApplyPropertyValue(RichTextBox.FontStyleProperty, __RedoFontStyle);
     edit.Selection.ApplyPropertyValue(TextBlock.TextDecorationsProperty, __RedoTextDecoration);
 }
Exemplo n.º 4
0
        public override void Redo(RichTextBox edit)
        {
            FlowDocument document = edit.Document;
            TextRange    whole    = new TextRange(document.ContentStart, document.ContentEnd);
            TextPointer  start    = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetStart);
            TextPointer  end      = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetEnd);
            TextRange    range    = new TextRange(start, end);

            range.ClearAllProperties();
            range.Text = "";

            edit.CaretPosition = end;
            UpdateOffsets(edit, range);
        }
Exemplo n.º 5
0
        public override void Redo(RichTextBox edit)
        {
            FlowDocument document = edit.Document;

            __DataStream.Seek(0, SeekOrigin.Begin);
            TextRange whole = new TextRange(document.ContentStart, document.ContentEnd);

            TextPointer start = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetStart);
            TextPointer end   = UndoHelpers.SafePositionAtOffset(document, document.ContentEnd, __OffsetEnd);

            whole.Select(start, end);
            whole.Load(__DataStream, DataFormats.Xaml);

            edit.CaretPosition = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetCursorPositionAfter);
        }
Exemplo n.º 6
0
        public override void Undo(RichTextBox edit)
        {
            FlowDocument document = edit.Document;

            __OffsetCursorPositionAfter = document.ContentStart.GetOffsetToPosition(edit.CaretPosition);

            TextPointer start = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetStart);
            TextPointer end   = UndoHelpers.SafePositionAtOffset(document, document.ContentEnd, __OffsetEnd);
            TextRange   range = new TextRange(start, end);

            __DataStream = new MemoryStream();
            range.Save(__DataStream, DataFormats.Xaml);
            range.ClearAllProperties();
            range.Text = "";

            edit.CaretPosition = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetCursorPositionBefore);
        }
Exemplo n.º 7
0
        public override void Undo(RichTextBox edit)
        {
            FlowDocument document = edit.Document;
            TextRange    whole    = new TextRange(document.ContentStart, document.ContentEnd);
            TextRange    range    = new TextRange(
                UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetStart),
                UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetEnd));

            __DataStream = new MemoryStream();
            range.Save(__DataStream, DataFormats.Xaml);

            range.ClearAllProperties();
            range.Text = "";
            UpdateOffsets(edit, range);

            TextPointer caretPosition = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetStart);

            edit.CaretPosition = caretPosition;
        }
        public override void Undo(RichTextBox edit)
        {
            __DataStream.Seek(0, SeekOrigin.Begin);

            edit.CaretPosition = UndoHelpers.SafePositionAtOffset(edit.Document, edit.Document.ContentStart, __OffsetCursorPosition);

            edit.Selection.Select(edit.CaretPosition, edit.CaretPosition);
            __RedoFontWeight     = edit.Selection.GetPropertyValue(RichTextBox.FontWeightProperty);
            __RedoFontFamily     = edit.Selection.GetPropertyValue(RichTextBox.FontFamilyProperty);
            __RedoFontSize       = edit.Selection.GetPropertyValue(RichTextBox.FontSizeProperty);
            __RedoFontStyle      = edit.Selection.GetPropertyValue(RichTextBox.FontStyleProperty);
            __RedoTextDecoration = edit.Selection.GetPropertyValue(TextBlock.TextDecorationsProperty);

            edit.Selection.ApplyPropertyValue(RichTextBox.FontWeightProperty, __UndoFontWeight);
            edit.Selection.ApplyPropertyValue(RichTextBox.FontFamilyProperty, __UndoFontFamily);
            edit.Selection.ApplyPropertyValue(RichTextBox.FontSizeProperty, __UndoFontSize);
            edit.Selection.ApplyPropertyValue(RichTextBox.FontStyleProperty, __UndoFontStyle);
            edit.Selection.ApplyPropertyValue(TextBlock.TextDecorationsProperty, __UndoTextDecoration);
        }
Exemplo n.º 9
0
        public override void Redo(RichTextBox edit)
        {
            FlowDocument document = edit.Document;
            TextPointer  start    = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, selectionStartOffset);
            TextPointer  end      = UndoHelpers.SafePositionAtOffset(document, document.ContentEnd, selectionEndOffset);

            TextRange whole = new TextRange(start, end);

            __UndoStream.Seek(0, SeekOrigin.Begin);
            whole.Load(__UndoStream, DataFormats.Xaml);
            UpdateSelectionOffsets(edit, whole);

            if (__OffsetCursorPositionAfter != -1)
            {
                edit.CaretPosition = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetCursorPositionAfter);
            }
            else
            {
                edit.Selection.Select(start, end);
            }
        }