Example usage for com.intellij.openapi.actionSystem IdeActions ACTION_EDITOR_ENTER

List of usage examples for com.intellij.openapi.actionSystem IdeActions ACTION_EDITOR_ENTER

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem IdeActions ACTION_EDITOR_ENTER.

Prototype

String ACTION_EDITOR_ENTER

To view the source code for com.intellij.openapi.actionSystem IdeActions ACTION_EDITOR_ENTER.

Click Source Link

Usage

From source file:com.intellij.testFramework.LightPlatformCodeInsightTestCase.java

License:Apache License

protected static void type(char c) {
    EditorActionManager actionManager = EditorActionManager.getInstance();
    final DataContext dataContext = DataManager.getInstance().getDataContext();
    if (c == '\n') {
        actionManager.getActionHandler(IdeActions.ACTION_EDITOR_ENTER).execute(getEditor(), dataContext);
    } else if (c == '\b') {
        actionManager.getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE).execute(getEditor(), dataContext);
    } else {//from w  w w  .  j a  va2s.co  m
        actionManager.getTypedAction().actionPerformed(getEditor(), c, dataContext);
    }
}

From source file:org.jetbrains.plugins.ruby.ruby.actions.editor.RubyEditorActionsManager.java

License:Apache License

/**
 * Registers new <code>RubyEnterHandler</code> in manager
 *
 * @param manager IDEA`s editor action manager
 * @return Ruby EnterHandler/*from  ww w  .  ja v a  2 s.c o  m*/
 * @see org.jetbrains.plugins.ruby.ruby.actions.editor.handlers.editorHandlers.RubyEnterHandler RubyEnterHandler for more details
 */
public static EditorActionHandler registerRubyEnterActionHandler(EditorActionManager manager) {
    EditorActionHandler myHandler = new RubyEnterHandler(
            manager.getActionHandler(IdeActions.ACTION_EDITOR_ENTER));
    manager.setActionHandler(IdeActions.ACTION_EDITOR_ENTER, myHandler);
    assert (myHandler == manager.getActionHandler(IdeActions.ACTION_EDITOR_ENTER));
    return myHandler;
}

From source file:org.jetbrains.plugins.scala.lang.actions.editor.enter.AbstractEnterActionTestBase.java

License:Apache License

protected EditorActionHandler getMyHandler() {
    return EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER);
}

From source file:org.mustbe.consulo.csharp.ide.completion.CSharpAccessorCompletionContributor.java

License:Apache License

public CSharpAccessorCompletionContributor() {
    extend(CompletionType.BASIC, psiElement().andNot(psiElement().inside(DotNetXXXAccessor.class)),
            new CompletionProvider() {
                @RequiredReadAction/*from www .  j  a  v a  2 s .c o  m*/
                @Override
                protected void addCompletions(@NotNull CompletionParameters completionParameters,
                        ProcessingContext processingContext, @NotNull CompletionResultSet resultSet) {
                    PsiElement position = completionParameters.getPosition();
                    final CSharpXXXAccessorOwner accessorOwner = PsiTreeUtil.getParentOfType(position,
                            CSharpXXXAccessorOwner.class);
                    if (accessorOwner == null) {
                        return;
                    }
                    PsiElement leftBrace = accessorOwner.getLeftBrace();
                    if (leftBrace == null) {
                        return;
                    }

                    int textOffset = position.getTextOffset();
                    PsiElement rightBrace = accessorOwner.getRightBrace();
                    int rightTextRange = rightBrace == null ? -1 : rightBrace.getTextOffset();

                    if ((rightTextRange == -1 || textOffset < rightTextRange)
                            && textOffset > leftBrace.getTextOffset()) {
                        if (accessorOwner.hasModifier(DotNetModifier.ABSTRACT)) {
                            buildAccessorKeywordsCompletion(resultSet, accessorOwner, null);
                        } else {
                            buildAccessorKeywordsCompletion(resultSet, accessorOwner,
                                    new InsertHandler<LookupElement>() {
                                        @Override
                                        @RequiredWriteAction
                                        public void handleInsert(InsertionContext context, LookupElement item) {
                                            if (context.getCompletionChar() == '{') {
                                                context.setAddCompletionChar(false);

                                                Editor editor = context.getEditor();

                                                CaretModel caretModel = editor.getCaretModel();
                                                int offset = caretModel.getOffset();

                                                context.getDocument().insertString(offset, "{\n}");
                                                caretModel.moveToOffset(offset + 1);

                                                PsiElement elementAt = context.getFile()
                                                        .findElementAt(offset - 1);

                                                context.commitDocument();

                                                DotNetXXXAccessor accessor = PsiTreeUtil
                                                        .getParentOfType(elementAt, DotNetXXXAccessor.class);
                                                if (accessor != null) {
                                                    CodeStyleManager.getInstance(context.getProject())
                                                            .reformat(accessor);
                                                }

                                                EditorWriteActionHandler actionHandler = (EditorWriteActionHandler) EditorActionManager
                                                        .getInstance()
                                                        .getActionHandler(IdeActions.ACTION_EDITOR_ENTER);
                                                actionHandler.executeWriteAction(editor,
                                                        DataManager.getInstance()
                                                                .getDataContext(editor.getContentComponent()));
                                            }
                                        }
                                    });
                        }
                    }
                }
            });
}

From source file:org.mustbe.consulo.csharp.ide.completion.util.ExpressionOrStatementInsertHandler.java

License:Apache License

@Override
@RequiredWriteAction/*from  w ww  .  ja v  a 2s.c o m*/
public void handleInsert(final InsertionContext context, final T item) {
    final Editor editor = context.getEditor();
    final Document document = editor.getDocument();
    context.commitDocument();

    PsiElement elementAt = context.getFile().findElementAt(context.getStartOffset());
    handleInsertImpl(context, item, editor, document);
    if (myOpenChar == '{') {
        document.insertString(editor.getCaretModel().getOffset(), "\n");
    }
    context.commitDocument();
    if (elementAt != null) {
        PsiElement parent = elementAt.getParent();

        CodeStyleManager.getInstance(elementAt.getProject()).reformat(parent);

        if (myOpenChar == '{') {
            EditorWriteActionHandler actionHandler = (EditorWriteActionHandler) EditorActionManager
                    .getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER);
            actionHandler.executeWriteAction(editor,
                    DataManager.getInstance().getDataContext(editor.getContentComponent()));
        }
    }
}