public void Do( object context, CommandFactoryReference commandFactoryReference, CommandFactoryManager <OperationContext> controller) { // Pull out some useful variables for processing. var editViewController = (EditorViewController)context; IDisplayContext displayContext = editViewController.DisplayContext; TextPosition position = displayContext.Caret.Position; // Set up the operation context for this request. var textPosition = new TextPosition( displayContext.Caret.Position.LinePosition, displayContext.Caret.Position.CharacterPosition); var operationContext = new OperationContext( displayContext.LineBuffer, textPosition); // Create the commands and execute them. Do( context, controller, commandFactoryReference.Data, operationContext, editViewController, displayContext, position); }
protected override void Do( object context, CommandFactoryManager <OperationContext> commandFactory, object commandData, OperationContext operationContext, EditorViewController controller, IDisplayContext displayContext, TextPosition position) { IDeleteTextCommand <OperationContext> deleteCommand = controller.CommandController.CreateDeleteTextCommand( new SingleLineTextRange( displayContext.Caret.Position.LinePosition, displayContext.Caret.Position.CharacterPosition, CharacterPosition.Word)); deleteCommand.UpdateTextPosition = DoTypes.All; // Execute the command. controller.CommandController.Do(deleteCommand, operationContext); // If we have a text position, we need to set it. if (operationContext.Results.HasValue) { displayContext.Caret.SetAndScrollToPosition( operationContext.Results.Value.TextPosition); } }
protected override void Do( object context, CommandFactoryManager <OperationContext> commandFactory, object commandData, OperationContext operationContext, EditorViewController controller, IDisplayContext displayContext, TextPosition position) { // Create the command and execute it. var textPosition = new TextPosition( displayContext.Caret.Position.LinePosition, displayContext.Caret.Position.CharacterPosition); var splitCommand = new SplitParagraphCommand <OperationContext>( controller.CommandController, textPosition); controller.CommandController.Do(splitCommand, operationContext); // If we have a text position, we need to set it. if (operationContext.Results.HasValue) { displayContext.Caret.SetAndScrollToPosition( operationContext.Results.Value.TextPosition); } }
protected abstract void Do( object context, CommandFactoryManager <OperationContext> commandFactory, object commandData, OperationContext operationContext, EditorViewController editViewController, IDisplayContext displayContext, TextPosition position);
protected override void Do( object context, CommandFactoryManager <OperationContext> commandFactory, object commandData, OperationContext operationContext, EditorViewController controller, IDisplayContext displayContext, TextPosition position) { // If we don't have a selection, this is a simple insert command. TextPosition bufferPosition = displayContext.Caret.Position; TextRange selection = displayContext.Caret.Selection; if (!selection.IsEmpty) { // Create and execute the delete command. We do this separately // so they show up as a different undo item. IUndoableCommand <OperationContext> deleteCommand = DeleteSelectionCommandFactory.CreateCommand(controller, displayContext); controller.CommandController.Do(deleteCommand, operationContext); // We have to reset the position so the insert happens as if // the text doesn't exist. bufferPosition = selection.FirstTextPosition; operationContext = new OperationContext( operationContext.LineBuffer, bufferPosition); } // Create the insert command using the (potentially) modified selection. string text = commandData.ToString(); IInsertTextCommand <OperationContext> insertCommand = controller.CommandController.CreateInsertTextCommand(bufferPosition, text); insertCommand.UpdateTextPosition = DoTypes.All; controller.CommandController.Do(insertCommand, operationContext); // If we have a text position, we need to set it. if (operationContext.Results.HasValue) { displayContext.Caret.SetAndScrollToPosition( operationContext.Results.Value.TextPosition); } }
protected override void Do( object context, CommandFactoryManager <OperationContext> commandFactory, object commandData, OperationContext operationContext, EditorViewController controller, IDisplayContext displayContext, TextPosition position) { // Create the delete selection command. ICommand <OperationContext> command = CreateCommand( controller, displayContext); // Execute the command. controller.CommandController.Do(command, operationContext); // If we have a text position, we need to set it. if (operationContext.Results.HasValue) { displayContext.Caret.Position = operationContext.Results.Value.TextPosition; } }
protected override void Do( object context, CommandFactoryManager <OperationContext> commandFactory, object commandData, OperationContext operationContext, EditorViewController controller, IDisplayContext displayContext, TextPosition position) { if (controller.CommandController.CanUndo) { // Request that the previous command be undone. controller.CommandController.Undo(operationContext); // If we have a text position, we need to set it. if (operationContext.Results.HasValue) { displayContext.Caret.SetAndScrollToPosition( operationContext.Results.Value.TextPosition); } } }
protected override void Do( object context, CommandFactoryManager <OperationContext> commandFactory, object commandData, OperationContext operationContext, EditorViewController controller, IDisplayContext displayContext, TextPosition position) { var command = new JoinNextParagraphCommand <OperationContext>( controller.CommandController, position.LinePosition); controller.CommandController.Do(command, operationContext); // If we have a text position, we need to set it. if (operationContext.Results.HasValue) { displayContext.Caret.SetAndScrollToPosition( operationContext.Results.Value.TextPosition); } }
protected override void Do( object context, CommandFactoryManager <OperationContext> commandFactory, object commandData, OperationContext operationContext, EditorViewController controller, IDisplayContext displayContext, TextPosition position) { // Figure out which command we'll be passing the operation to. HierarchicalPath key; if (!displayContext.Caret.Selection.IsEmpty) { // If we have a selection, then we use the Delete Selection command. key = DeleteSelectionCommandFactory.Key; } else if (position.IsBeginningOfBuffer(controller.DisplayContext)) { // If we are the beginning of the buffer, then we can't delete anything. return; } else if (position.CharacterPosition == 0) { // If we are at the beginning of the line, then we are combining paragraphs. key = JoinPreviousParagraphCommandFactory.Key; } else { // Delete the next character only. key = DeleteLeftWordCommandFactory.Key; } // Execute the command and pass the results to calling method. var nextCommand = new CommandFactoryReference(key); commandFactory.Do(context, nextCommand); }
/// <summary> /// Initializes a new instance of the <see cref="EditorViewController"/> class. /// </summary> /// <param name="editorView">The text editor associated with this controller.</param> public EditorViewController(EditorView editorView) { // Saves the display context for performing actions. if (editorView == null) { throw new ArgumentNullException("editorView"); } displayContext = editorView; // Bind the initial keybindings. keyBindings = new Dictionary <int, ActionEntry>(); actions = new Dictionary <string, ActionEntry>(); // Bind the action states. states = new ActionStateCollection(); Commands = new CommandManager(); CommandController = new LineBufferCommandController(); CommandFactory = new CommandFactoryManager <OperationContext>(CommandController); // Bind the default actions for the editor. BindActions(); }
protected override void Do( object context, CommandFactoryManager <OperationContext> commandFactory, object commandData, OperationContext operationContext, EditorViewController controller, IDisplayContext displayContext, TextPosition position) { // Get the text from the clipboard. Clipboard clipboard = displayContext.Clipboard; clipboard.RequestText(null); string clipboardText = clipboard.WaitForText(); if (string.IsNullOrEmpty(clipboardText)) { return; } // Figure out the position of this paste. TextPosition textPosition; if (displayContext.Caret.Selection.IsEmpty) { textPosition = new TextPosition( displayContext.Caret.Position.LinePosition, displayContext.Caret.Position.CharacterPosition); } else { textPosition = displayContext.Caret.Selection.FirstTextPosition; } // Create the paste command for the text. CompositeCommand <OperationContext> command = new PasteCommand <OperationContext>( controller.CommandController, textPosition, clipboardText); // If we have a selection, we need to delete the selection first. if (!displayContext.Caret.Selection.IsEmpty) { // Create the composite command for the delete. var composite = new CompositeCommand <OperationContext>(true, false); IUndoableCommand <OperationContext> selection = DeleteSelectionCommandFactory.CreateCommand(controller, displayContext); composite.Commands.Add(selection); composite.Commands.Add(command); // Move the composite over to the command. command = composite; } // Execute the command. controller.CommandController.Do(command, operationContext); // If we have a text position, we need to set it. if (operationContext.Results.HasValue) { displayContext.Caret.SetAndScrollToPosition( operationContext.Results.Value.TextPosition); } }