当前位置: 首页>>代码示例>>Java>>正文


Java EditorActionHandler.execute方法代码示例

本文整理汇总了Java中com.intellij.openapi.editor.actionSystem.EditorActionHandler.execute方法的典型用法代码示例。如果您正苦于以下问题:Java EditorActionHandler.execute方法的具体用法?Java EditorActionHandler.execute怎么用?Java EditorActionHandler.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.editor.actionSystem.EditorActionHandler的用法示例。


在下文中一共展示了EditorActionHandler.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: preprocessEnter

import com.intellij.openapi.editor.actionSystem.EditorActionHandler; //导入方法依赖的package包/类
@Override
public Result preprocessEnter(
    @NotNull PsiFile psiFile,
    @NotNull Editor editor,
    @NotNull Ref<Integer> caretOffset,
    @NotNull Ref<Integer> caretOffsetChange,
    @NotNull DataContext dataContext,
    @Nullable EditorActionHandler originalHandler) {
  if (psiFile instanceof SoyFile && isBetweenSiblingTags(psiFile, caretOffset.get())) {
    if (originalHandler != null) {
      originalHandler.execute(editor, dataContext);
    }
    return Result.Default;
  }
  return Result.Continue;
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:17,代码来源:EnterHandler.java

示例2: executeWriteAction

import com.intellij.openapi.editor.actionSystem.EditorActionHandler; //导入方法依赖的package包/类
@Override
public void executeWriteAction(@NotNull Editor editor, Caret caret, DataContext dataContext) {
  final Document document = editor.getDocument();
  final int caretOffset = editor.getCaretModel().getOffset();
  if (caretOffset < 1) {
    return;
  }

  final SelectionModel selectionModel = editor.getSelectionModel();
  final CharSequence text = document.getCharsSequence();
  final char c = text.charAt(caretOffset - 1);
  if (!selectionModel.hasSelection() && StringUtil.isWhiteSpace(c)) {
    int startOffset = CharArrayUtil.shiftBackward(text, caretOffset - 2, "\t \n") + 1;
    document.deleteString(startOffset, caretOffset);
  }
  else {
    final EditorActionHandler handler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE);
    handler.execute(editor, caret, dataContext);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:HungryBackspaceAction.java

示例3: handleBetweenSquareBraces

import com.intellij.openapi.editor.actionSystem.EditorActionHandler; //导入方法依赖的package包/类
private static boolean handleBetweenSquareBraces(Editor editor,
                                                 int caret,
                                                 DataContext context,
                                                 Project project,
                                                 EditorActionHandler originalHandler) {
  String text = editor.getDocument().getText();
  if (text == null || text.isEmpty()) return false;
  final EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter();
  if (caret < 1 || caret > text.length() - 1) {
    return false;
  }
  HighlighterIterator iterator = highlighter.createIterator(caret - 1);
  if (GroovyTokenTypes.mLBRACK == iterator.getTokenType()) {
    if (text.length() > caret) {
      iterator = highlighter.createIterator(caret);
      if (GroovyTokenTypes.mRBRACK == iterator.getTokenType()) {
        originalHandler.execute(editor, context);
        originalHandler.execute(editor, context);
        editor.getCaretModel().moveCaretRelatively(0, -1, false, false, true);
        insertSpacesByGroovyContinuationIndent(editor, project);
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:GroovyEnterHandler.java

示例4: handleBetweenSquareBraces

import com.intellij.openapi.editor.actionSystem.EditorActionHandler; //导入方法依赖的package包/类
private static boolean handleBetweenSquareBraces(Editor editor,
                                                 int caret,
                                                 DataContext context,
                                                 Project project,
                                                 EditorActionHandler originalHandler) {
  String text = editor.getDocument().getText();
  if (text == null || text.length() == 0) return false;
  final EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter();
  if (caret < 1 || caret > text.length() - 1) {
    return false;
  }
  HighlighterIterator iterator = highlighter.createIterator(caret - 1);
  if (mLBRACK == iterator.getTokenType()) {
    if (text.length() > caret) {
      iterator = highlighter.createIterator(caret);
      if (mRBRACK == iterator.getTokenType()) {
        originalHandler.execute(editor, context);
        originalHandler.execute(editor, context);
        editor.getCaretModel().moveCaretRelatively(0, -1, false, false, true);
        insertSpacesByGroovyContinuationIndent(editor, project);
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:27,代码来源:GroovyEnterHandler.java

示例5: executeWriteAction

import com.intellij.openapi.editor.actionSystem.EditorActionHandler; //导入方法依赖的package包/类
@Override
public void executeWriteAction(@Nonnull Editor editor, Caret caret, DataContext dataContext) {
  final Document document = editor.getDocument();
  final int caretOffset = editor.getCaretModel().getOffset();
  if (caretOffset < 1) {
    return;
  }

  final SelectionModel selectionModel = editor.getSelectionModel();
  final CharSequence text = document.getCharsSequence();
  final char c = text.charAt(caretOffset - 1);
  if (!selectionModel.hasSelection() && StringUtil.isWhiteSpace(c)) {
    int startOffset = CharArrayUtil.shiftBackward(text, caretOffset - 2, "\t \n") + 1;
    document.deleteString(startOffset, caretOffset);
  }
  else {
    final EditorActionHandler handler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE);
    handler.execute(editor, caret, dataContext);
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:21,代码来源:HungryBackspaceAction.java

示例6: preprocessEnter

import com.intellij.openapi.editor.actionSystem.EditorActionHandler; //导入方法依赖的package包/类
public Result preprocessEnter(@NotNull final PsiFile file, @NotNull final Editor editor, @NotNull final Ref<Integer> caretOffset, @NotNull final Ref<Integer> caretAdvance,
                              @NotNull final DataContext dataContext, final EditorActionHandler originalHandler) {
  /**
   * if we are between open and close tags, we ensure the caret ends up in the "logical" place on Enter.
   * i.e. "{#foo}<caret>{/foo}" becomes the following on Enter:
   *
   * {#foo}
   * <caret>
   * {/foo}
   *
   * (Note: <caret> may be indented depending on formatter settings.)
   */
  if (file instanceof DustFile
      && isBetweenHbTags(editor, file, caretOffset.get())) {
    originalHandler.execute(editor, dataContext);
    return Result.Default;
  }
  return Result.Continue;
}
 
开发者ID:yifanz,项目名称:Intellij-Dust,代码行数:20,代码来源:DustEnterHandler.java

示例7: doEnter

import com.intellij.openapi.editor.actionSystem.EditorActionHandler; //导入方法依赖的package包/类
@Override
public boolean doEnter(Editor editor, PsiElement psiElement, boolean isModified) {
  PsiElement parent = psiElement.getParent();
  if (!(parent instanceof PsiCodeBlock)) {
    return false;
  }

  final ASTNode node = psiElement.getNode();
  if (node != null && CONTROL_FLOW_ELEMENT_TYPES.contains(node.getElementType())) {
    return false;
  } 
  
  boolean leaveCodeBlock = isControlFlowBreak(psiElement);
  if (!leaveCodeBlock) {
    return false;
  }
  
  final int offset = parent.getTextRange().getEndOffset();
  
  // Check if there is empty line after the code block. Just move caret there in the case of the positive answer.
  final CharSequence text = editor.getDocument().getCharsSequence();
  if (offset < text.length() - 1) {
    final int i = CharArrayUtil.shiftForward(text, offset + 1, " \t");
    if (i < text.length() && text.charAt(i) == '\n') {
      editor.getCaretModel().moveToOffset(offset + 1);
      EditorActionManager actionManager = EditorActionManager.getInstance();
      EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_LINE_END);
      final DataContext dataContext = DataManager.getInstance().getDataContext(editor.getComponent());
      if (dataContext != null) {
        actionHandler.execute(editor, dataContext);
        return true;
      }
    }
  }
  
  editor.getCaretModel().moveToOffset(offset);
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:LeaveCodeBlockEnterProcessor.java

示例8: expandCodeBlock

import com.intellij.openapi.editor.actionSystem.EditorActionHandler; //导入方法依赖的package包/类
static boolean expandCodeBlock(Editor editor, PsiElement psiElement) {
  PsiCodeBlock block = getControlStatementBlock(editor.getCaretModel().getOffset(), psiElement);
  if (processExistingBlankLine(editor, block, psiElement)) {
    return true;
  }
  if (block == null) {
    return false;
  }

  EditorActionHandler enterHandler = getEnterHandler(IdeActions.ACTION_EDITOR_START_NEW_LINE);
  PsiElement firstElement = block.getFirstBodyElement();
  if (firstElement == null) {
    firstElement = block.getRBrace();
    // Plain enter processor inserts enter after the end of line, hence, we don't want to use it here because the line ends with
    // the empty braces block. So, we get the following in case of default handler usage:
    //     Before:
    //         if (condition[caret]) {}
    //     After:
    //         if (condition) {}
    //             [caret]
    enterHandler = getEnterHandler(IdeActions.ACTION_EDITOR_ENTER);
  }
  editor.getCaretModel().moveToOffset(firstElement != null ?
                                      firstElement.getTextRange().getStartOffset() :
                                      block.getTextRange().getEndOffset());
  enterHandler.execute(editor, ((EditorEx)editor).getDataContext());
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:PlainEnterProcessor.java

示例9: selectWordAtCaret

import com.intellij.openapi.editor.actionSystem.EditorActionHandler; //导入方法依赖的package包/类
@Override
public void selectWordAtCaret(final boolean honorCamelWordsSettings) {
  removeSelection();

  EditorActionHandler handler = EditorActionManager.getInstance().getActionHandler(
    IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET);
  handler.execute(myEditor, DataManager.getInstance().getDataContext(myEditor.getComponent()));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:TextComponentSelectionModel.java

示例10: insertLineFeedInString

import com.intellij.openapi.editor.actionSystem.EditorActionHandler; //导入方法依赖的package包/类
private static void insertLineFeedInString(Editor editor,
                                           DataContext dataContext,
                                           EditorActionHandler originalHandler,
                                           boolean isInsertIndent) {
  if (isInsertIndent) {
    originalHandler.execute(editor, dataContext);
  }
  else {
    EditorModificationUtil.insertStringAtCaret(editor, "\n");
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:GroovyEnterHandler.java

示例11: preprocessEnter

import com.intellij.openapi.editor.actionSystem.EditorActionHandler; //导入方法依赖的package包/类
@Override
public Result preprocessEnter(
    PsiFile file,
    Editor editor,
    Ref<Integer> caretOffset,
    Ref<Integer> caretAdvance,
    DataContext dataContext,
    EditorActionHandler originalHandler) {
  int offset = caretOffset.get();
  if (editor instanceof EditorWindow) {
    file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
    editor = InjectedLanguageUtil.getTopLevelEditor(editor);
    offset = editor.getCaretModel().getOffset();
  }
  if (!isApplicable(file, dataContext) || !insertIndent(file, offset)) {
    return Result.Continue;
  }
  int indent = SectionParser.INDENT;

  editor.getCaretModel().moveToOffset(offset);
  Document doc = editor.getDocument();
  PsiDocumentManager.getInstance(file.getProject()).commitDocument(doc);

  originalHandler.execute(editor, editor.getCaretModel().getCurrentCaret(), dataContext);
  LogicalPosition position = editor.getCaretModel().getLogicalPosition();
  if (position.column < indent) {
    String spaces = StringUtil.repeatSymbol(' ', indent - position.column);
    doc.insertString(editor.getCaretModel().getOffset(), spaces);
  }
  editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(position.line, indent));
  return Result.Stop;
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:33,代码来源:ProjectViewEnterHandler.java

示例12: doEnter

import com.intellij.openapi.editor.actionSystem.EditorActionHandler; //导入方法依赖的package包/类
@Override
public boolean doEnter(Editor editor, PsiElement psiElement, boolean isModified) {
  PsiCodeBlock block = getControlStatementBlock(editor.getCaretModel().getOffset(), psiElement);
  if (processExistingBlankLine(editor, block, psiElement)) {
    return true;
  }
  EditorActionHandler enterHandler = getEnterHandler(IdeActions.ACTION_EDITOR_START_NEW_LINE);
  if (block != null) {
    PsiElement firstElement = block.getFirstBodyElement();
    if (firstElement == null) {
      firstElement = block.getRBrace();
      // Plain enter processor inserts enter after the end of line, hence, we don't want to use it here because the line ends with 
      // the empty braces block. So, we get the following in case of default handler usage:
      //     Before:
      //         if (condition[caret]) {}
      //     After:
      //         if (condition) {}
      //             [caret]
      enterHandler = getEnterHandler(IdeActions.ACTION_EDITOR_ENTER);
    }
    editor.getCaretModel().moveToOffset(firstElement != null ?
                                        firstElement.getTextRange().getStartOffset() :
                                        block.getTextRange().getEndOffset());
  }

  enterHandler.execute(editor, ((EditorEx)editor).getDataContext());
  return true;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:29,代码来源:PlainEnterProcessor.java

示例13: executeWriteAction

import com.intellij.openapi.editor.actionSystem.EditorActionHandler; //导入方法依赖的package包/类
@Override
public void executeWriteAction(@NotNull Editor editor, DataContext dataContext) {
  final Document document = editor.getDocument();
  final int prevSymbolOffset = editor.getCaretModel().getOffset() - 1;
  if (prevSymbolOffset < 0) {
    return;
  }
  
  final SelectionModel selectionModel = editor.getSelectionModel();
  final CharSequence text = document.getCharsSequence();
  final char c = text.charAt(prevSymbolOffset);
  final boolean doHungryCheck = !selectionModel.hasSelection() && !selectionModel.hasBlockSelection() && StringUtil.isWhiteSpace(c);
  final EditorActionHandler handler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE);
  handler.execute(editor, dataContext);

  if (!doHungryCheck) {
    return;
  }
  
  final int endOffset = prevSymbolOffset;
  if (endOffset > document.getTextLength()) {
    return;
  }
  int startOffset = CharArrayUtil.shiftBackward(text, endOffset - 1, "\t \n");
  if (startOffset < 0) {
    // No non-white space symbol before the current caret offset has been found.
    startOffset = 0;
  }
  else {
    // Offset now points to the first non-white space symbol before the caret.
    // Increment it to point to the first white space symbol instead.
    startOffset++;
  }
  if (startOffset >= endOffset) {
    return;
  }
  document.deleteString(startOffset, endOffset);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:39,代码来源:HungryBackspaceAction.java

示例14: preprocessEnter

import com.intellij.openapi.editor.actionSystem.EditorActionHandler; //导入方法依赖的package包/类
@Override
public Result preprocessEnter(@NotNull final PsiFile file, @NotNull final Editor editor, @NotNull final Ref<Integer> caretOffsetRef, @NotNull final Ref<Integer> caretAdvance,
                              @NotNull final DataContext dataContext, final EditorActionHandler originalHandler) {
  Document document = editor.getDocument();
  CharSequence text = document.getCharsSequence();
  int caretOffset = caretOffsetRef.get().intValue();
  if (!CodeInsightSettings.getInstance().SMART_INDENT_ON_ENTER) {
    return Result.Continue;
  }
  
  if (caretOffset <= 0 || caretOffset >= text.length() || !isBracePair(text.charAt(caretOffset - 1), text.charAt(caretOffset))) {
    return Result.Continue;
  }

  final int line = document.getLineNumber(caretOffset);
  final int start = document.getLineStartOffset(line);
  final CodeDocumentationUtil.CommentContext commentContext =
    CodeDocumentationUtil.tryParseCommentContext(file, text, caretOffset, start);

  // special case: enter inside "()" or "{}"
  String indentInsideJavadoc = commentContext.docAsterisk
                               ? CodeDocumentationUtil.getIndentInsideJavadoc(document, caretOffset)
                               : null;

  originalHandler.execute(editor, dataContext);

  Project project = editor.getProject();
  if (indentInsideJavadoc != null && project != null && CodeStyleSettingsManager.getSettings(project).JD_LEADING_ASTERISKS_ARE_ENABLED) {
    document.insertString(editor.getCaretModel().getOffset(), "*" + indentInsideJavadoc);
  }

  PsiDocumentManager.getInstance(file.getProject()).commitDocument(document);
  try {
    CodeStyleManager.getInstance(file.getProject()).adjustLineIndent(file, editor.getCaretModel().getOffset());
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
  return indentInsideJavadoc == null ? Result.Continue : Result.DefaultForceIndent;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:41,代码来源:EnterBetweenBracesHandler.java

示例15: performAction

import com.intellij.openapi.editor.actionSystem.EditorActionHandler; //导入方法依赖的package包/类
private void performAction(final String fileName, final EditorActionHandler handler, final String afterFileName) throws Exception {
  configureByFile(fileName);
  final boolean enabled = handler.isEnabled(myEditor, null);
  assertEquals("not enabled for " + afterFileName, new File(getTestDataPath(), afterFileName).exists(), enabled);
  if (enabled) {
    handler.execute(myEditor, null);
    checkResultByFile(afterFileName);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:10,代码来源:XmlMoverTest.java


注:本文中的com.intellij.openapi.editor.actionSystem.EditorActionHandler.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。