Search in sources :

Example 1 with DeleteTextCommand

use of org.whole.lang.ui.commands.DeleteTextCommand in project whole by wholeplatform.

the class TextualDirectEditEditPolicy method getDeleteCommand.

private Command getDeleteCommand(TextualRequest request) {
    Command command;
    ITextualEntityPart textualEntityPart = (ITextualEntityPart) getHost();
    if (textualEntityPart.hasSelectionRange()) {
        command = createDeleteSelectionCommand(textualEntityPart);
    } else {
        DeleteTextCommand delete = new DeleteTextCommand();
        delete.setEntity(textualEntityPart.getModelTextEntity());
        delete.setViewer(textualEntityPart.getViewer());
        delete.setLength(1);
        command = delete;
    }
    return command;
}
Also used : DeleteTextCommand(org.whole.lang.ui.commands.DeleteTextCommand) ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) DeleteTextCommand(org.whole.lang.ui.commands.DeleteTextCommand) BackspaceTextCommand(org.whole.lang.ui.commands.BackspaceTextCommand) ITextCommand(org.whole.lang.ui.commands.ITextCommand) InsertTextCommand(org.whole.lang.ui.commands.InsertTextCommand) TextTransactionCommand(org.whole.lang.ui.commands.TextTransactionCommand) OverwriteTextCommand(org.whole.lang.ui.commands.OverwriteTextCommand) Command(org.eclipse.gef.commands.Command)

Example 2 with DeleteTextCommand

use of org.whole.lang.ui.commands.DeleteTextCommand in project whole by wholeplatform.

the class TextualDirectEditEditPolicy method createDeleteSelectionCommand.

private Command createDeleteSelectionCommand(ITextualEntityPart textualEntityPart) {
    Command command;
    int start = textualEntityPart.getSelectionStart();
    int end = textualEntityPart.getSelectionEnd();
    int length = end - start;
    int caretPosition = textualEntityPart.getCaretPosition();
    if (caretPosition >= end) {
        BackspaceTextCommand backspace = new BackspaceTextCommand();
        backspace.setEntity(textualEntityPart.getModelTextEntity());
        backspace.setViewer(textualEntityPart.getViewer());
        backspace.setLength(length);
        command = backspace;
    } else {
        DeleteTextCommand delete = new DeleteTextCommand();
        delete.setEntity(textualEntityPart.getModelTextEntity());
        delete.setViewer(textualEntityPart.getViewer());
        delete.setLength(length);
        command = delete;
    }
    return command;
}
Also used : DeleteTextCommand(org.whole.lang.ui.commands.DeleteTextCommand) DeleteTextCommand(org.whole.lang.ui.commands.DeleteTextCommand) BackspaceTextCommand(org.whole.lang.ui.commands.BackspaceTextCommand) ITextCommand(org.whole.lang.ui.commands.ITextCommand) InsertTextCommand(org.whole.lang.ui.commands.InsertTextCommand) TextTransactionCommand(org.whole.lang.ui.commands.TextTransactionCommand) OverwriteTextCommand(org.whole.lang.ui.commands.OverwriteTextCommand) Command(org.eclipse.gef.commands.Command) BackspaceTextCommand(org.whole.lang.ui.commands.BackspaceTextCommand)

Aggregations

Command (org.eclipse.gef.commands.Command)2 BackspaceTextCommand (org.whole.lang.ui.commands.BackspaceTextCommand)2 DeleteTextCommand (org.whole.lang.ui.commands.DeleteTextCommand)2 ITextCommand (org.whole.lang.ui.commands.ITextCommand)2 InsertTextCommand (org.whole.lang.ui.commands.InsertTextCommand)2 OverwriteTextCommand (org.whole.lang.ui.commands.OverwriteTextCommand)2 TextTransactionCommand (org.whole.lang.ui.commands.TextTransactionCommand)2 ITextualEntityPart (org.whole.lang.ui.editparts.ITextualEntityPart)1