Search in sources :

Example 1 with TextTransactionCommand

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

the class TextualSelectionTool method handleTextRequest.

protected boolean handleTextRequest(TextualRequest edit) {
    EditPart target = getFocusedPart();
    if (target == null)
        return false;
    Command command = target.getCommand(edit);
    if (command == null || !command.canExecute())
        return false;
    if (command instanceof ITextCommand) {
        ITextCommand textCommand = (ITextCommand) command;
        if (transactionCommand == null || !transactionCommand.canMerge(textCommand) || !getDomain().getCommandStack().isDirty()) {
            transactionCommand = new TextTransactionCommand();
            transactionCommand.setModel((IEntity) target.getModel());
            transactionCommand.merge(textCommand);
            executeCommand(transactionCommand);
        } else
            transactionCommand.merge(textCommand);
    } else {
        resetTransactionCommand();
        executeCommand(command);
    }
    return true;
}
Also used : ITextCommand(org.whole.lang.ui.commands.ITextCommand) ITextCommand(org.whole.lang.ui.commands.ITextCommand) TextTransactionCommand(org.whole.lang.ui.commands.TextTransactionCommand) Command(org.eclipse.gef.commands.Command) EditPart(org.eclipse.gef.EditPart) TextTransactionCommand(org.whole.lang.ui.commands.TextTransactionCommand)

Example 2 with TextTransactionCommand

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

the class PasteHandler method execute.

@Override
@Execute
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
    if (bm.wIsSet("viewer") && Clipboard.instance().getInternalOrNativeEntityContents() == null) {
        IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
        if (ClipboardUtils.hasTextFocus(viewer) || ClipboardUtils.hasTextSeletion(viewer)) {
            IEntity focusEntity = bm.wGet("focusEntity");
            ITextualEntityPart focusPart = (ITextualEntityPart) viewer.getEditPartRegistry().get(focusEntity);
            String textContents = Clipboard.instance().getTextContents();
            Command command = focusPart.getCommand(TextualRequest.createInsertRequest(textContents));
            CommandStack commandStack = viewer.getEditDomain().getCommandStack();
            if (command instanceof ITextCommand) {
                TextTransactionCommand transactionCommand = new TextTransactionCommand();
                transactionCommand.setModel(focusEntity);
                transactionCommand.merge((ITextCommand) command);
                transactionCommand.setLabel(getLabel(bm));
                commandStack.execute(transactionCommand);
            } else {
                command.setLabel(getLabel(bm) + " text");
                commandStack.execute(command);
            }
            return;
        }
    }
    super.execute(bm);
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ITextCommand(org.whole.lang.ui.commands.ITextCommand) ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) ITextCommand(org.whole.lang.ui.commands.ITextCommand) TextTransactionCommand(org.whole.lang.ui.commands.TextTransactionCommand) Command(org.eclipse.gef.commands.Command) TextTransactionCommand(org.whole.lang.ui.commands.TextTransactionCommand) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 3 with TextTransactionCommand

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

the class TextualDirectEditEditPolicy method createInsertOverSelectionCommand.

private Command createInsertOverSelectionCommand(ITextualEntityPart textualEntityPart, String contentToInsert) {
    IEntity textEntity = textualEntityPart.getModelTextEntity();
    TextTransactionCommand transactionCommand = new TextTransactionCommand();
    transactionCommand.setModel(textEntity);
    transactionCommand.merge((ITextCommand) createDeleteSelectionCommand(textualEntityPart));
    InsertTextCommand insert = new InsertTextCommand();
    insert.setEntity(textEntity);
    insert.setViewer(textualEntityPart.getViewer());
    insert.setData(contentToInsert);
    transactionCommand.merge(insert);
    transactionCommand.setLabel(insert.getLabel());
    return transactionCommand;
}
Also used : InsertTextCommand(org.whole.lang.ui.commands.InsertTextCommand) IEntity(org.whole.lang.model.IEntity) TextTransactionCommand(org.whole.lang.ui.commands.TextTransactionCommand)

Aggregations

TextTransactionCommand (org.whole.lang.ui.commands.TextTransactionCommand)3 Command (org.eclipse.gef.commands.Command)2 IEntity (org.whole.lang.model.IEntity)2 ITextCommand (org.whole.lang.ui.commands.ITextCommand)2 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)1 Execute (org.eclipse.e4.core.di.annotations.Execute)1 EditPart (org.eclipse.gef.EditPart)1 CommandStack (org.eclipse.gef.commands.CommandStack)1 InsertTextCommand (org.whole.lang.ui.commands.InsertTextCommand)1 ITextualEntityPart (org.whole.lang.ui.editparts.ITextualEntityPart)1 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)1