Search in sources :

Example 1 with HandlesUndoRedo

use of org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo in project che by eclipse.

the class QuickAssistWidget method createItem.

public Element createItem(final CompletionProposal proposal) {
    final Element element = Elements.createLiElement(popupResources.popupStyle().item());
    final Element icon = Elements.createDivElement(popupResources.popupStyle().icon());
    if (proposal.getIcon() != null && proposal.getIcon().getSVGImage() != null) {
        icon.appendChild((Node) proposal.getIcon().getSVGImage().getElement());
    } else if (proposal.getIcon() != null && proposal.getIcon().getImage() != null) {
        icon.appendChild((Node) proposal.getIcon().getImage().getElement());
    }
    element.appendChild(icon);
    final SpanElement label = Elements.createSpanElement(popupResources.popupStyle().label());
    label.setInnerHTML(proposal.getDisplayString());
    element.appendChild(label);
    final EventListener validateListener = new EventListener() {

        @Override
        public void handleEvent(final Event evt) {
            proposal.getCompletion(new CompletionProposal.CompletionCallback() {

                @Override
                public void onCompletion(final Completion completion) {
                    HandlesUndoRedo undoRedo = null;
                    if (textEditor instanceof UndoableEditor) {
                        UndoableEditor undoableEditor = (UndoableEditor) QuickAssistWidget.this.textEditor;
                        undoRedo = undoableEditor.getUndoRedo();
                    }
                    try {
                        if (undoRedo != null) {
                            undoRedo.beginCompoundChange();
                        }
                        completion.apply(textEditor.getDocument());
                        final LinearRange selection = completion.getSelection(textEditor.getDocument());
                        if (selection != null) {
                            textEditor.getDocument().setSelectedRange(selection, true);
                        }
                    } catch (final Exception e) {
                        Log.error(getClass(), e);
                    } finally {
                        if (undoRedo != null) {
                            undoRedo.endCompoundChange();
                        }
                    }
                }
            });
            hide();
        }
    };
    element.addEventListener(Event.DBLCLICK, validateListener, false);
    element.addEventListener(CUSTOM_EVT_TYPE_VALIDATE, validateListener, false);
    return element;
}
Also used : SpanElement(elemental.html.SpanElement) UndoableEditor(org.eclipse.che.ide.api.editor.texteditor.UndoableEditor) LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) CompletionProposal(org.eclipse.che.ide.api.editor.codeassist.CompletionProposal) Element(elemental.dom.Element) SpanElement(elemental.html.SpanElement) Node(elemental.dom.Node) HandlesUndoRedo(org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo) Completion(org.eclipse.che.ide.api.editor.codeassist.Completion) Event(elemental.events.Event) CustomEvent(elemental.events.CustomEvent) EventListener(elemental.events.EventListener)

Example 2 with HandlesUndoRedo

use of org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo in project che by eclipse.

the class ContentAssistWidget method applyCompletion.

private void applyCompletion(Completion completion) {
    textEditor.setFocus();
    UndoableEditor undoableEditor = textEditor;
    HandlesUndoRedo undoRedo = undoableEditor.getUndoRedo();
    try {
        if (undoRedo != null) {
            undoRedo.beginCompoundChange();
        }
        completion.apply(textEditor.getDocument());
        final LinearRange selection = completion.getSelection(textEditor.getDocument());
        if (selection != null) {
            textEditor.getDocument().setSelectedRange(selection, true);
        }
    } catch (final Exception e) {
        Log.error(getClass(), e);
    } finally {
        if (undoRedo != null) {
            undoRedo.endCompoundChange();
        }
    }
}
Also used : UndoableEditor(org.eclipse.che.ide.api.editor.texteditor.UndoableEditor) HandlesUndoRedo(org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo) LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange)

Example 3 with HandlesUndoRedo

use of org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo in project che by eclipse.

the class LanguageServerFormatter method applyEdits.

private void applyEdits(List<TextEditDTO> edits, Document document) {
    HandlesUndoRedo undoRedo = null;
    if (editor instanceof UndoableEditor) {
        undoRedo = ((UndoableEditor) editor).getUndoRedo();
    }
    try {
        if (undoRedo != null) {
            undoRedo.beginCompoundChange();
        }
        // #2437: apply the text edits from last to first to avoid messing up the document
        Collections.reverse(edits);
        for (TextEditDTO change : edits) {
            RangeDTO range = change.getRange();
            document.replace(range.getStart().getLine(), range.getStart().getCharacter(), range.getEnd().getLine(), range.getEnd().getCharacter(), change.getNewText());
        }
    } catch (final Exception e) {
        Log.error(getClass(), e);
    } finally {
        if (undoRedo != null) {
            undoRedo.endCompoundChange();
        }
    }
}
Also used : HandlesUndoRedo(org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo) UndoableEditor(org.eclipse.che.ide.api.editor.texteditor.UndoableEditor) TextEditDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextEditDTO) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 4 with HandlesUndoRedo

use of org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo in project che by eclipse.

the class RecipeEditorPanel method onCancelButtonClicked.

/** {@inheritDoc} */
@Override
public void onCancelButtonClicked() {
    setEnableSaveAndCancelButtons(false);
    view.setTags(recipeDescriptor.getTags());
    view.setName(recipeDescriptor.getName());
    if (editor instanceof UndoableEditor) {
        HandlesUndoRedo undoRedo = ((UndoableEditor) editor).getUndoRedo();
        while (editor.isDirty() && undoRedo.undoable()) {
            undoOperations++;
            undoRedo.undo();
        }
    }
}
Also used : UndoableEditor(org.eclipse.che.ide.api.editor.texteditor.UndoableEditor) HandlesUndoRedo(org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo)

Example 5 with HandlesUndoRedo

use of org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo in project che by eclipse.

the class RedoAction method updateInPerspective.

@Override
public void updateInPerspective(@NotNull ActionEvent event) {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    boolean mustEnable = false;
    if (activeEditor != null && activeEditor instanceof UndoableEditor) {
        final HandlesUndoRedo undoRedo = ((UndoableEditor) activeEditor).getUndoRedo();
        if (undoRedo != null) {
            mustEnable = undoRedo.redoable();
        }
    }
    event.getPresentation().setEnabled(mustEnable);
}
Also used : UndoableEditor(org.eclipse.che.ide.api.editor.texteditor.UndoableEditor) HandlesUndoRedo(org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Aggregations

HandlesUndoRedo (org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo)7 UndoableEditor (org.eclipse.che.ide.api.editor.texteditor.UndoableEditor)7 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)3 OperationException (org.eclipse.che.api.promises.client.OperationException)2 LinearRange (org.eclipse.che.ide.api.editor.text.LinearRange)2 Element (elemental.dom.Element)1 Node (elemental.dom.Node)1 CustomEvent (elemental.events.CustomEvent)1 Event (elemental.events.Event)1 EventListener (elemental.events.EventListener)1 SpanElement (elemental.html.SpanElement)1 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)1 TextEditDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextEditDTO)1 Completion (org.eclipse.che.ide.api.editor.codeassist.Completion)1 CompletionProposal (org.eclipse.che.ide.api.editor.codeassist.CompletionProposal)1 Change (org.eclipse.che.ide.ext.java.shared.dto.Change)1