/// <inheritdoc/> public bool CanActivate(DocumentEditorContext context) { var block = context.Caret.Block; var headingBlock = block as HeadingBlock; return((headingBlock != null && headingBlock.HeadingLevel != _level) || block is ParagraphBlock); }
public static XElement SaveIntoElement(DocumentEditorContext context) { var node = context.Document.SerializeAsNode(); var xml = XmlNodeSerializer.Serialize(node); return(xml); }
public static void LoadInto(XElement fullXml, DocumentEditorContext editorContext) { try { var contentXml = fullXml; var node = XmlNodeSerializer.Deserialize(contentXml); var serializationContext = new SerializationContext( new DescriptorsLookup(ParagraphBlock.Descriptor, (BlockDescriptor)HeadingBlock.Descriptor ) ); var mode = new CaretMovementMode(); mode.SetModeToEnd(); editorContext.Document.Root.Deserialize(serializationContext, node.Children.First()); editorContext.Selection.Replace(editorContext.Document.Root.GetView <IBlockView>().GetCaretFromBottom(mode)); } catch (Exception) { // ignored } }
/// <inheritdoc /> bool IContextualCommand.CanActivate(DocumentEditorContext context) { var textBlock = context.Caret.Block as TextBlock; // TODO check if the parent collection allows multiple children return(textBlock != null); }
/// <inheritdoc /> public override void Undo(DocumentEditorContext context) { var caret = (TextCaret)CursorHandle.GetCaret(context); caret = caret.InsertText(OriginalText); context.Selection.Replace(caret); }
public BlockCaret Deserialize(DocumentEditorContext context) { var block = _pathToBlock.Get(context.Document); var content = ((TextBlock)block).Content; return(FromOffset(content, _graphemeOffset)); }
/// <inheritdoc /> public override void Do(DocumentEditorContext context) { var next = _nextPath.Get(context.Document); TextBlockHelperMethods.MergeWithPrevious((TextBlock)next); context.Selection.Replace(_endOfPreviousBlockHandle.GetCaret(context)); }
/// <inheritdoc /> public override void Do(DocumentEditorContext context) { var caret = (TextCaret)CursorHandle.GetCaret(context); caret = caret.DeleteText(1); context.Selection.Replace(caret); }
private bool TryMergeWith(DocumentEditorContext context, DeletePreviousCharacterCommand.DeletePreviousCharacterAction action) { var myCopy = (TextCaret)_insertionPoint.GetCaret(context); var otherCopy = (TextCaret)action.CursorHandle.GetCaret(context); if (Text.Length == 0) { return(false); } if (!Text.EndsWith(action.OriginalText)) { return(false); } if (myCopy.Block != otherCopy.Block) { return(false); } var insertionPointAfterInsert = myCopy.Offset.GraphemeOffset + Text.Length; var insertionPointAtDeletion = otherCopy.Offset.GraphemeOffset + action.OriginalText.Length; if (insertionPointAfterInsert != insertionPointAtDeletion) { return(false); } Text = Text.Remove(Text.Length - action.OriginalText.Length, action.OriginalText.Length); return(true); }
/// <inheritdoc /> public override void Do(DocumentEditorContext context) { var textCaret = _insertionPoint.GetCaret(context).As <TextCaret>(); textCaret = textCaret.InsertText(Text); context.Selection.Replace(textCaret); }
/// <inheritdoc /> public bool CanActivate(DocumentEditorContext context) { TextBlock unused1; TextBlock unused2; return(TryGetTextBlocks(context, out unused1, out unused2)); }
/// <inheritdoc /> public override void Undo(DocumentEditorContext context) { var caret = (TextCaret)_endOfPreviousBlockHandle.GetCaret(context); TextBlockHelperMethods.TryBreakBlock(caret); context.Selection.Replace(_originalCaretPosition.GetCaret(context)); }
/// <summary> Constructor. </summary> /// <param name="context"> The editor context for which this stack was created. </param> /// <param name="mergePolicy"> Strategy class for determining when actions should be merged </param> public ActionStack(DocumentEditorContext context, IActionStackMergePolicy mergePolicy) { _context = context; _mergePolicy = mergePolicy; _toRedoStack = new Stack <UndoStackEntry>(); _toUndoStack = new Stack <UndoStackEntry>(); }
/// <inheritdoc /> public override void Undo(DocumentEditorContext context) { // TODO graphemes? var textCaret = (TextCaret)_insertionPoint.GetCaret(context); textCaret = textCaret.DeleteText(Text.Length); context.Selection.Replace(textCaret); }
/// <summary> Deserializes the caret so that it can be reused. </summary> /// <param name="context"> The context which can be used to deserialize the caret. </param> /// <returns> The caret. </returns> public BlockCaret GetCaret(DocumentEditorContext context) { // TODO if we're at the same revision # as when we created the cursor, we don't have to // deserialize we can use the original cursor. // // you know. Like the documentation on the class says :: ) return(_serializedCursor.Deserialize(context)); }
/// <inheritdoc /> public override void Do(DocumentEditorContext context) { var caret = (TextCaret)_handle.GetCaret(context); var caretPosition = TextBlockHelperMethods.TryBreakBlock(caret); if (!caretPosition.IsValid) { return; } context.Selection.Replace(caretPosition); }
/// <inheritdoc /> public string GetName(DocumentEditorContext context) { if (context.Caret.IsAtBlockStart) { return("Merge paragraph backwards"); } else { return("Merge paragraph forwards"); } }
/// <inheritdoc/> public virtual void Activate(DocumentEditorContext context, IActionStack actionStack) { Activate(context.Selection, context.CaretMovementMode, context.IsSelectionExtendActive ? SelectionMode.Extend : SelectionMode.Replace); if (!ShouldPreserveCaretMovementMode) { context.CaretMovementMode.SetModeToNone(); } }
/// <inheritdoc /> public override void Undo(DocumentEditorContext context) { var caret = (TextCaret)_handle.GetCaret(context); var previousBlock = caret.Block; var nextBlock = previousBlock.NextBlock; TextBlockHelperMethods.MergeWithPrevious((TextBlock)nextBlock); // move it to where it was when we wanted to break the paragraph. It's safer to deserialize // again, as the cursor above is not guaranteed to be valid. context.Selection.MoveTo(_handle, context); }
/// <inheritdoc /> public void Activate(DocumentEditorContext context, IActionStack actionStack) { TextBlock previous; TextBlock next; if (!TryGetTextBlocks(context, out previous, out next)) { return; } actionStack.Do(new MergeTextBlockAction(previous, next, context.Selection)); }
/// <summary> Prepares the document for performing actions. </summary> private void Reinitialize() { Context = new DocumentEditorContext(); var toExecute = InitializeDocument(); if (toExecute != null) { foreach (var item in toExecute) { item.Invoke().Do(Context); } } }
/// <summary> /// Searches this list looking for the command whose modifier keys match the passed in modifiers /// and that can be enabled. /// </summary> private static IContextualCommand FindMatchOnModifierKeys(List <Shortcut> list, ModifierKeys modifers, DocumentEditorContext context) { foreach (var item in list) { var command = item.ContextualCommand; if (item.Modifers == modifers && command?.CanActivate(context) == true) { return(command); } } return(null); }
public DocumentEditor(DocumentEditorContext context) { Loaded += delegate { var view = ((DocumentEditorContextView)Content); view.Initialize(); view.Focus(); }; EditorContext = context; Content = new DocumentEditorContextView(EditorContext); var spellChecker = new TextBlockSpellCheckAddon(context); }
/// <inheritdoc/> public override bool TryMerge(DocumentEditorContext context, UndoableAction action) { if (action is InsertTextUndoableAction) { return(TryMergeWith(context, (InsertTextUndoableAction)action)); } else if (action is DeleteNextCharacterCommand.DeleteNextCharacterAction) { return(TryMergeWith(context, (DeleteNextCharacterCommand.DeleteNextCharacterAction)action)); } else if (action is DeletePreviousCharacterCommand.DeletePreviousCharacterAction) { return(TryMergeWith(context, (DeletePreviousCharacterCommand.DeletePreviousCharacterAction)action)); } return(false); }
private bool TryMergeWith(DocumentEditorContext context, InsertTextUndoableAction action) { var myCopy = (TextCaret)_insertionPoint.GetCaret(context); var otherCopy = (TextCaret)action._insertionPoint.GetCaret(context); if (myCopy.Block != otherCopy.Block) { return(false); } if (myCopy.Offset.GraphemeOffset + Text.Length != otherCopy.Offset.GraphemeOffset) { return(false); } Text += action.Text; return(true); }
/// <inheritdoc /> public override void Undo(DocumentEditorContext context) { var caret = (TextCaret)_handle.GetCaret(context); var block = caret.Block; // optimization; if it was originally a block of the same type, we can just deserialize // but leave it in-place if (block.DescriptorHandle == _originalDescriptor) { var originalBlock = block; originalBlock.DeserializeProperties(_originalProperties); } else { // otherwise we have to re-create it TextBlock original = (TextBlock)_originalDescriptor.CreateInstance(); original.DeserializeProperties(_originalProperties); Replace(context, caret.Block, original); } }
/// <inheritdoc /> public override void Do(DocumentEditorContext context) { var caret = (TextCaret)_handle.GetCaret(context); var block = caret.Block; var destinationDescriptor = GetDestinationDescriptor(); // optimization; if it's already the correct block type, we just have to change it in-place if (block.DescriptorHandle == destinationDescriptor) { MakeChangesTo((TBlock)block); } else { var newBlock = (TBlock)destinationDescriptor.CreateInstance(); MakeChangesTo(newBlock); Replace(context, block, newBlock); } }
/// <summary> /// Attempts to retrieve the previous and next text block for the caret at the current position. /// </summary> private bool TryGetTextBlocks(DocumentEditorContext context, out TextBlock previous, out TextBlock next) { var cursor = context.Caret; if (cursor.IsAtBlockStart && cursor.Block.PreviousBlock != null) { previous = cursor.Block.PreviousBlock as TextBlock; next = cursor.Block as TextBlock; } else if (cursor.IsAtBlockEnd && cursor.Block.NextBlock != null) { previous = cursor.Block as TextBlock; next = cursor.Block.NextBlock as TextBlock; } else { previous = null; next = null; } return(previous != null && next != null); }
public override bool CanActivate(DocumentEditorContext context) => context.Selection.Is <TextCaret>();
/// <inheritdoc/> public void Activate(DocumentEditorContext context, IActionStack actionStack) { actionStack.Do(new ConvertTextBlockIntoHeadingAction((TextCaret)context.Selection.Start, _level)); }