use of com.intellij.openapi.util.AsyncResult in project intellij-community by JetBrains.
the class RichTextActionProcessor method process.
@Override
public JComponent process(@NotNull String s) {
final ActionManager actionManager = ActionManager.getInstance();
final AnAction action = actionManager.getAction(s);
if (action == null) {
return null;
}
final Presentation presentation = action.getTemplatePresentation();
if (presentation.getIcon() != null) {
return new ActionButton(action, presentation.clone(), GradleConstants.TOOL_WINDOW_TOOLBAR_PLACE, JBUI.emptySize()) {
@Override
protected void paintButtonLook(Graphics g) {
// Don't draw border at the inline button.
ActionButtonLook look = getButtonLook();
look.paintBackground(g, this);
look.paintIcon(g, this, getIcon());
}
};
}
final String text = action.getTemplatePresentation().getText();
JLabel result = new JLabel(text) {
public void paint(Graphics g) {
super.paint(g);
final int y = g.getClipBounds().height - getFontMetrics(getFont()).getDescent() + 2;
final int width = getFontMetrics(getFont()).stringWidth(getText());
g.drawLine(0, y, width, y);
}
};
Color color = UIUtil.isUnderDarcula() ? Color.ORANGE : Color.BLUE;
result.setForeground(color);
result.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent e, int clickCount) {
final AsyncResult<DataContext> callback = DataManager.getInstance().getDataContextFromFocus();
final DataContext context = callback.getResult();
if (context == null) {
return false;
}
final Presentation presentation = new PresentationFactory().getPresentation(action);
action.actionPerformed(new AnActionEvent(e, context, GradleConstants.TOOL_WINDOW_TOOLBAR_PLACE, presentation, ActionManager.getInstance(), e.getModifiers()));
return true;
}
}.installOn(result);
return result;
}
use of com.intellij.openapi.util.AsyncResult in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoRenameQuickFix method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
if (!FileModificationService.getInstance().preparePsiElementsForWrite(startElement))
return;
Runnable runnable = () -> {
AsyncResult<DataContext> dataContextContainer = DataManager.getInstance().getDataContextFromFocus();
dataContextContainer.doWhenDone(new Consumer<DataContext>() {
@Override
public void consume(DataContext dataContext) {
RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(dataContext);
if (renameHandler != null) {
renameHandler.invoke(project, new PsiElement[] { startElement }, dataContext);
} else {
RefactoringActionHandler renameRefactoringHandler = RefactoringActionHandlerFactory.getInstance().createRenameHandler();
renameRefactoringHandler.invoke(project, new PsiElement[] { startElement }, dataContext);
}
}
});
};
if (ApplicationManager.getApplication().isUnitTestMode()) {
runnable.run();
} else {
ApplicationManager.getApplication().invokeLater(runnable, project.getDisposed());
}
}
Aggregations