當前位置: 首頁>>代碼示例>>Java>>正文


Java AnActionEvent.getRequiredData方法代碼示例

本文整理匯總了Java中com.intellij.openapi.actionSystem.AnActionEvent.getRequiredData方法的典型用法代碼示例。如果您正苦於以下問題:Java AnActionEvent.getRequiredData方法的具體用法?Java AnActionEvent.getRequiredData怎麽用?Java AnActionEvent.getRequiredData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.openapi.actionSystem.AnActionEvent的用法示例。


在下文中一共展示了AnActionEvent.getRequiredData方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: actionPerformed

import com.intellij.openapi.actionSystem.AnActionEvent; //導入方法依賴的package包/類
@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
    final PsiFile psiFile = e.getRequiredData(CommonDataKeys.PSI_FILE);
    
    CommandProcessor.getInstance().executeCommand(project, () -> {
        try {
            MultiHighlightHandler.invoke(project, editor, psiFile);
        } catch (IndexNotReadyException ex) {
            DumbService.getInstance(project)
                    .showDumbModeNotification("MultiHighlight requires indices "
                            + "and cannot be performed until they are built");
        }
    }, "MultiHighlight", null);
}
 
開發者ID:huoguangjin,項目名稱:MultiHighlight,代碼行數:17,代碼來源:MultiHighlightAction.java

示例2: actionPerformed

import com.intellij.openapi.actionSystem.AnActionEvent; //導入方法依賴的package包/類
@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
    
    final HighlightManager highlightManager = HighlightManager.getInstance(project);
    final RangeHighlighter[] highlighters =
            ((HighlightManagerImpl) highlightManager).getHighlighters(editor);
    for (RangeHighlighter highlighter : highlighters) {
        final TextAttributes ta = highlighter.getTextAttributes();
        if (ta != null && ta instanceof NamedTextAttr
                && highlighter.getLayer() == HighlighterLayer.SELECTION - 1) {
            highlightManager.removeSegmentHighlighter(editor, highlighter);
        }
    }
}
 
開發者ID:huoguangjin,項目名稱:MultiHighlight,代碼行數:17,代碼來源:MultiHighlightClearAction.java

示例3: actionPerformed

import com.intellij.openapi.actionSystem.AnActionEvent; //導入方法依賴的package包/類
@Override
public void actionPerformed(AnActionEvent e) {
    //Get all the required data from data keys
    final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    //Access document, caret, and selection
    final Document document = editor.getDocument();
    final SelectionModel selectionModel = editor.getSelectionModel();

    final int start = selectionModel.getSelectionStart();
    final int end = selectionModel.getSelectionEnd();
    //New instance of Runnable to make a replacement
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            //  return hex(random.randint(0, 2 ** 64) | 1 << 63)
            // from 0 to 64
            BigInteger rand = new BigInteger(64, new Random());
            rand = rand.or(new BigInteger("1").shiftLeft(63));
            String capnpId = rand.toString(16);
            document.setText( String.format("@0x%s; \n\n", capnpId) + document.getText());
        }
    };
    //Making the replacement
    WriteCommandAction.runWriteCommandAction(project, runnable);
    selectionModel.removeSelection();
}
 
開發者ID:xmonader,項目名稱:sercapnp,代碼行數:28,代碼來源:GenerateCapnpID.java


注:本文中的com.intellij.openapi.actionSystem.AnActionEvent.getRequiredData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。