Search in sources :

Example 1 with EditorWriteActionHandler

use of com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler in project intellij-community by JetBrains.

the class PydevConsoleRunnerImpl method createSplitLineAction.

protected AnAction createSplitLineAction() {
    class ConsoleSplitLineAction extends EditorAction {

        private static final String CONSOLE_SPLIT_LINE_ACTION_ID = "Console.SplitLine";

        public ConsoleSplitLineAction() {
            super(new EditorWriteActionHandler() {

                private final SplitLineAction mySplitLineAction = new SplitLineAction();

                @Override
                public boolean isEnabled(Editor editor, DataContext dataContext) {
                    return mySplitLineAction.getHandler().isEnabled(editor, dataContext);
                }

                @Override
                public void executeWriteAction(Editor editor, @Nullable Caret caret, DataContext dataContext) {
                    ((EditorWriteActionHandler) mySplitLineAction.getHandler()).executeWriteAction(editor, caret, dataContext);
                    editor.getCaretModel().getCurrentCaret().moveCaretRelatively(0, 1, false, true);
                }
            });
        }

        public void setup() {
            EmptyAction.setupAction(this, CONSOLE_SPLIT_LINE_ACTION_ID, null);
        }
    }
    ConsoleSplitLineAction action = new ConsoleSplitLineAction();
    action.setup();
    return action;
}
Also used : EditorWriteActionHandler(com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler) EditorAction(com.intellij.openapi.editor.actionSystem.EditorAction) Editor(com.intellij.openapi.editor.Editor) SplitLineAction(com.intellij.openapi.editor.actions.SplitLineAction) Nullable(org.jetbrains.annotations.Nullable) Caret(com.intellij.openapi.editor.Caret)

Example 2 with EditorWriteActionHandler

use of com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler in project intellij-community by JetBrains.

the class ExpandLiveTemplateCustomAction method createExpandTemplateHandler.

public static EditorWriteActionHandler createExpandTemplateHandler(final char shortcutChar) {
    return new EditorWriteActionHandler(true) {

        @Override
        public void executeWriteAction(Editor editor, @Nullable Caret caret, DataContext dataContext) {
            Project project = editor.getProject();
            assert project != null;
            TemplateManager.getInstance(project).startTemplate(editor, shortcutChar);
        }

        @Override
        protected boolean isEnabledForCaret(@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) {
            Project project = editor.getProject();
            return project != null && ((TemplateManagerImpl) TemplateManager.getInstance(project)).prepareTemplate(editor, shortcutChar, null) != null;
        }
    };
}
Also used : EditorWriteActionHandler(com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) TemplateManagerImpl(com.intellij.codeInsight.template.impl.TemplateManagerImpl) Editor(com.intellij.openapi.editor.Editor) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable) Caret(com.intellij.openapi.editor.Caret)

Aggregations

Caret (com.intellij.openapi.editor.Caret)2 Editor (com.intellij.openapi.editor.Editor)2 EditorWriteActionHandler (com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler)2 Nullable (org.jetbrains.annotations.Nullable)2 TemplateManagerImpl (com.intellij.codeInsight.template.impl.TemplateManagerImpl)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 EditorAction (com.intellij.openapi.editor.actionSystem.EditorAction)1 SplitLineAction (com.intellij.openapi.editor.actions.SplitLineAction)1 Project (com.intellij.openapi.project.Project)1 NotNull (org.jetbrains.annotations.NotNull)1