Search in sources :

Example 1 with KeyBindingAction

use of org.eclipse.che.ide.api.editor.keymap.KeyBindingAction in project che by eclipse.

the class OrionEditorInit method configureCodeAssist.

/**
     * Configure the editor's code assistant.
     * @param documentHandle the handle on the document
     */
private void configureCodeAssist(final DocumentHandle documentHandle) {
    if (this.codeAssistantFactory == null) {
        return;
    }
    final Map<String, CodeAssistProcessor> processors = configuration.getContentAssistantProcessors();
    if (processors != null && !processors.isEmpty()) {
        LOG.info("Creating code assistant.");
        final CodeAssistant codeAssistant = this.codeAssistantFactory.create(this.textEditor, this.configuration.getPartitioner());
        for (String key : processors.keySet()) {
            codeAssistant.setCodeAssistantProcessor(key, processors.get(key));
        }
        final KeyBindingAction action = new KeyBindingAction() {

            @Override
            public boolean action() {
                showCompletion(codeAssistant, true);
                return true;
            }
        };
        final HasKeyBindings hasKeyBindings = this.textEditor.getHasKeybindings();
        hasKeyBindings.addKeyBinding(new KeyBinding(true, false, false, false, KeyCode.SPACE, action), CONTENT_ASSIST);
        // handle CompletionRequest events that come from text operations instead of simple key binding
        documentHandle.getDocEventBus().addHandler(CompletionRequestEvent.TYPE, new CompletionRequestHandler() {

            @Override
            public void onCompletionRequest(final CompletionRequestEvent event) {
                showCompletion(codeAssistant, false);
            }
        });
    } else {
        final KeyBindingAction action = new KeyBindingAction() {

            @Override
            public boolean action() {
                showCompletion();
                return true;
            }
        };
        final HasKeyBindings hasKeyBindings = this.textEditor.getHasKeybindings();
        if (UserAgent.isMac()) {
            hasKeyBindings.addKeyBinding(new KeyBinding(false, false, false, true, KeyCode.SPACE, action), CONTENT_ASSIST);
            hasKeyBindings.addKeyBinding(new KeyBinding(false, false, true, true, KeyCode.SPACE, action), CONTENT_ASSIST);
        } else {
            hasKeyBindings.addKeyBinding(new KeyBinding(true, false, false, false, KeyCode.SPACE, action), CONTENT_ASSIST);
        }
        // handle CompletionRequest events that come from text operations instead of simple key binding
        documentHandle.getDocEventBus().addHandler(CompletionRequestEvent.TYPE, new CompletionRequestHandler() {

            @Override
            public void onCompletionRequest(final CompletionRequestEvent event) {
                showCompletion();
            }
        });
    }
}
Also used : KeyBinding(org.eclipse.che.ide.api.editor.keymap.KeyBinding) CompletionRequestHandler(org.eclipse.che.ide.api.editor.events.CompletionRequestHandler) CompletionRequestEvent(org.eclipse.che.ide.api.editor.events.CompletionRequestEvent) CodeAssistProcessor(org.eclipse.che.ide.api.editor.codeassist.CodeAssistProcessor) HasKeyBindings(org.eclipse.che.ide.api.editor.texteditor.HasKeyBindings) CodeAssistant(org.eclipse.che.ide.api.editor.codeassist.CodeAssistant) KeyBindingAction(org.eclipse.che.ide.api.editor.keymap.KeyBindingAction)

Example 2 with KeyBindingAction

use of org.eclipse.che.ide.api.editor.keymap.KeyBindingAction in project che by eclipse.

the class OrionEditorPresenter method setupEventHandlers.

private void setupEventHandlers() {
    this.editorWidget.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(final ChangeEvent event) {
            handleDocumentChanged();
        }
    });
    this.editorWidget.addGutterClickHandler(new GutterClickHandler() {

        @Override
        public void onGutterClick(final GutterClickEvent event) {
            if (Gutters.BREAKPOINTS_GUTTER.equals(event.getGutterId()) || Gutters.LINE_NUMBERS_GUTTER.equals(event.getGutterId())) {
                breakpointManager.changeBreakpointState(event.getLineNumber());
            }
        }
    });
    this.editorWidget.addKeyBinding(new KeyBinding(true, false, false, false, KeyCodes.KEY_F8, new KeyBindingAction() {

        @Override
        public boolean action() {
            int currentLine = editorWidget.getDocument().getCursorPosition().getLine();
            breakpointManager.changeBreakpointState(currentLine);
            return true;
        }
    }), TOGGLE_LINE_BREAKPOINT);
}
Also used : KeyBinding(org.eclipse.che.ide.api.editor.keymap.KeyBinding) GutterClickEvent(org.eclipse.che.ide.api.editor.events.GutterClickEvent) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) GutterClickHandler(org.eclipse.che.ide.api.editor.events.GutterClickHandler) KeyBindingAction(org.eclipse.che.ide.api.editor.keymap.KeyBindingAction)

Example 3 with KeyBindingAction

use of org.eclipse.che.ide.api.editor.keymap.KeyBindingAction in project che by eclipse.

the class OrionEditorInit method addQuickAssistKeyBinding.

/**
     * Add key binding to quick assist assistant.
     */
private void addQuickAssistKeyBinding() {
    if (this.quickAssist != null) {
        final KeyBindingAction action = new KeyBindingAction() {

            @Override
            public boolean action() {
                final PositionConverter positionConverter = textEditor.getPositionConverter();
                if (positionConverter != null) {
                    textEditor.showQuickAssist();
                }
                return true;
            }
        };
        final HasKeyBindings hasKeyBindings = this.textEditor.getHasKeybindings();
        hasKeyBindings.addKeyBinding(new KeyBinding(false, false, true, false, KeyCode.ENTER, action), QUICK_FIX);
    }
}
Also used : KeyBinding(org.eclipse.che.ide.api.editor.keymap.KeyBinding) HasKeyBindings(org.eclipse.che.ide.api.editor.texteditor.HasKeyBindings) PositionConverter(org.eclipse.che.ide.api.editor.position.PositionConverter) KeyBindingAction(org.eclipse.che.ide.api.editor.keymap.KeyBindingAction)

Aggregations

KeyBinding (org.eclipse.che.ide.api.editor.keymap.KeyBinding)3 KeyBindingAction (org.eclipse.che.ide.api.editor.keymap.KeyBindingAction)3 HasKeyBindings (org.eclipse.che.ide.api.editor.texteditor.HasKeyBindings)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 CodeAssistProcessor (org.eclipse.che.ide.api.editor.codeassist.CodeAssistProcessor)1 CodeAssistant (org.eclipse.che.ide.api.editor.codeassist.CodeAssistant)1 CompletionRequestEvent (org.eclipse.che.ide.api.editor.events.CompletionRequestEvent)1 CompletionRequestHandler (org.eclipse.che.ide.api.editor.events.CompletionRequestHandler)1 GutterClickEvent (org.eclipse.che.ide.api.editor.events.GutterClickEvent)1 GutterClickHandler (org.eclipse.che.ide.api.editor.events.GutterClickHandler)1 PositionConverter (org.eclipse.che.ide.api.editor.position.PositionConverter)1