Example usage for com.intellij.openapi.editor.actionSystem EditorActionManager getInstance

List of usage examples for com.intellij.openapi.editor.actionSystem EditorActionManager getInstance

Introduction

In this page you can find the example usage for com.intellij.openapi.editor.actionSystem EditorActionManager getInstance.

Prototype

public static EditorActionManager getInstance() 

Source Link

Document

Returns the instance of the editor action manager.

Usage

From source file:com.bmesta.powermode.PowerMode.java

License:Apache License

@Override
public void initComponent() {

    final EditorActionManager editorActionManager = EditorActionManager.getInstance();
    final EditorFactory editorFactory = EditorFactory.getInstance();
    particleContainerManager = new ParticleContainerManager();
    editorFactory.addEditorFactoryListener(particleContainerManager, new Disposable() {
        @Override//from ww w  .  j  a  v a 2 s  . com
        public void dispose() {

        }
    });
    final TypedAction typedAction = editorActionManager.getTypedAction();
    final TypedActionHandler rawHandler = typedAction.getRawHandler();
    typedAction.setupRawHandler(new TypedActionHandler() {
        @Override
        public void execute(@NotNull final Editor editor, final char c,
                @NotNull final DataContext dataContext) {
            updateEditor(editor);
            rawHandler.execute(editor, c, dataContext);
        }
    });
}

From source file:com.dci.intellij.dbn.editor.code.SourceCodeEditorManager.java

License:Apache License

private SourceCodeEditorManager(Project project) {
    super(project);
    EditorActionManager.getInstance()
            .setReadonlyFragmentModificationHandler(OverrideReadonlyFragmentModificationHandler.INSTANCE);
    FileEditorManager editorManager = FileEditorManager.getInstance(project);
    editorManager.addFileEditorManagerListener(DatabaseFileSystem.getInstance());
    editorManager.addFileEditorManagerListener(new DBLanguageFileEditorListener());
}

From source file:com.goide.completion.BracesInsertHandler.java

License:Apache License

@Override
public void handleInsert(@Nonnull InsertionContext context, LookupElement item) {
    Editor editor = context.getEditor();
    CharSequence documentText = context.getDocument().getImmutableCharSequence();
    int offset = skipWhiteSpaces(editor.getCaretModel().getOffset(), documentText);
    if (documentText.charAt(offset) != '{') {
        Project project = context.getProject();
        Template template = TemplateManager.getInstance(project).createTemplate("braces", "go",
                myOneLine ? "{$END$}" : " {\n$END$\n}");
        template.setToReformat(true);// w w  w .j a  v  a2  s .c  om
        TemplateManager.getInstance(project).startTemplate(editor, template);
    } else {
        editor.getCaretModel().moveToOffset(offset);
        ApplicationManager.getApplication().runWriteAction(() -> {
            EditorActionHandler enterAction = EditorActionManager.getInstance()
                    .getActionHandler(IdeActions.ACTION_EDITOR_START_NEW_LINE);
            enterAction.execute(editor, editor.getCaretModel().getCurrentCaret(),
                    ((EditorEx) editor).getDataContext());
        });
    }
}

From source file:com.intellij.application.options.codeInsight.editor.quotes.SelectionQuotingTypedHandlerTest.java

License:Apache License

private void doTest(final char c, @NotNull String before, @NotNull String expected) {
    myFixture.configureByText(PlainTextFileType.INSTANCE, before);
    final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
    performAction(myFixture.getProject(), new Runnable() {
        @Override//from w  w  w.  ja v  a 2s.  co m
        public void run() {
            typedAction.actionPerformed(myFixture.getEditor(), c,
                    ((EditorEx) myFixture.getEditor()).getDataContext());
        }
    });
    myFixture.getEditor().getSelectionModel().removeSelection();
    myFixture.checkResult(expected);
}

From source file:com.intellij.application.options.codeInsight.editor.quotes.SelectionQuotingTypedHandlerTest.java

License:Apache License

private void doTest(@NotNull final String cs, @NotNull String before, @NotNull String expected) {
    final boolean smarterSelection = Registry.is("editor.smarterSelectionQuoting");
    Registry.get("editor.smarterSelectionQuoting").setValue(true);
    try {/*  w w w  . ja  va  2 s.c o  m*/
        myFixture.configureByText(PlainTextFileType.INSTANCE, before);
        final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();

        performAction(myFixture.getProject(), new Runnable() {
            @Override
            public void run() {
                for (int i = 0, max = cs.length(); i < max; i++) {
                    final char c = cs.charAt(i);
                    typedAction.actionPerformed(myFixture.getEditor(), c,
                            ((EditorEx) myFixture.getEditor()).getDataContext());
                }
            }
        });
        myFixture.checkResult(expected);
    } finally {
        Registry.get("editor.smarterSelectionQuoting").setValue(smarterSelection);
    }
}

From source file:com.intellij.application.options.codeInsight.editor.quotes.SelectionQuotingTypedHandlerTest.java

License:Apache License

public void testRuby7852ErrantEditor() {
    myFixture.configureByText(PlainTextFileType.INSTANCE, "\"aaa\"\nbbb\n\n");
    myFixture.getEditor().getCaretModel().moveToOffset(0);
    myFixture.getEditor().getSelectionModel().setSelection(0, 5);
    final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
    performAction(myFixture.getProject(), new Runnable() {
        @Override//  w ww .j  ava 2 s. c o m
        public void run() {
            typedAction.actionPerformed(myFixture.getEditor(), '\'',
                    ((EditorEx) myFixture.getEditor()).getDataContext());
        }
    });
    myFixture.getEditor().getSelectionModel().removeSelection();
    myFixture.checkResult("'aaa'\nbbb\n\n");

    myFixture.getEditor().getCaretModel()
            .moveToOffset(myFixture.getEditor().getDocument().getLineStartOffset(3));
    performAction(myFixture.getProject(), new Runnable() {
        @Override
        public void run() {
            typedAction.actionPerformed(myFixture.getEditor(), 'A',
                    ((EditorEx) myFixture.getEditor()).getDataContext());
            typedAction.actionPerformed(myFixture.getEditor(), 'B',
                    ((EditorEx) myFixture.getEditor()).getDataContext());
        }
    });
    myFixture.checkResult("'aaa'\nbbb\n\nAB");
}

From source file:com.intellij.codeInsight.CodeInsightTestCase.java

License:Apache License

protected static void type(char c, Editor editor) {
    EditorActionManager actionManager = EditorActionManager.getInstance();
    DataContext dataContext = DataManager.getInstance().getDataContext();
    if (c == '\n') {
        actionManager.getActionHandler(IdeActions.ACTION_EDITOR_ENTER).execute(editor, dataContext);
        return;//from w  ww. ja  v a 2s . com
    }
    TypedAction action = actionManager.getTypedAction();
    action.actionPerformed(editor, c, dataContext);
}

From source file:com.intellij.codeInsight.CodeInsightTestCase.java

License:Apache License

protected void caretRight() {
    EditorActionManager actionManager = EditorActionManager.getInstance();
    EditorActionHandler action = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT);
    action.execute(getEditor(), DataManager.getInstance().getDataContext());
}

From source file:com.intellij.codeInsight.CodeInsightTestCase.java

License:Apache License

protected void caretUp() {
    EditorActionManager actionManager = EditorActionManager.getInstance();
    EditorActionHandler action = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_UP);
    action.execute(getEditor(), DataManager.getInstance().getDataContext());
}

From source file:com.intellij.codeInsight.CodeInsightTestCase.java

License:Apache License

protected void deleteLine() {
    EditorActionManager actionManager = EditorActionManager.getInstance();
    EditorActionHandler action = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_DELETE_LINE);
    action.execute(getEditor(), DataManager.getInstance().getDataContext());
}