本文整理匯總了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);
}
示例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);
}
}
}
示例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();
}