use of com.intellij.openapi.project.DumbAwareAction in project intellij-community by JetBrains.
the class XValueHint method showHint.
@Override
protected boolean showHint(final JComponent component) {
boolean result = super.showHint(component);
if (result && getType() == ValueHintType.MOUSE_OVER_HINT) {
myDisposable = Disposer.newDisposable();
ShortcutSet shortcut = ActionManager.getInstance().getAction("ShowErrorDescription").getShortcutSet();
new DumbAwareAction() {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
hideHint();
final Point point = new Point(myPoint.x, myPoint.y + getEditor().getLineHeight());
new XValueHint(getProject(), getEditor(), point, ValueHintType.MOUSE_CLICK_HINT, myExpressionInfo, myEvaluator, myDebugSession).invokeHint();
}
}.registerCustomShortcutSet(shortcut, getEditor().getContentComponent(), myDisposable);
}
if (result) {
XValueHint prev = getEditor().getUserData(HINT_KEY);
if (prev != null) {
prev.hideHint();
}
getEditor().putUserData(HINT_KEY, this);
}
return result;
}
use of com.intellij.openapi.project.DumbAwareAction in project intellij-community by JetBrains.
the class InjectionsSettingsUI method createActions.
private void createActions(ToolbarDecorator decorator) {
final Consumer<BaseInjection> consumer = injection -> addInjection(injection);
final Factory<BaseInjection> producer = (NullableFactory<BaseInjection>) () -> {
final InjInfo info = getSelectedInjection();
return info == null ? null : info.injection;
};
for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
ContainerUtil.addAll(myAddActions, support.createAddActions(myProject, consumer));
final AnAction action = support.createEditAction(myProject, producer);
myEditActions.put(support.getId(), action == null ? AbstractLanguageInjectionSupport.createDefaultEditAction(myProject, producer) : action);
mySupports.put(support.getId(), support);
}
Collections.sort(myAddActions, (o1, o2) -> Comparing.compare(o1.getTemplatePresentation().getText(), o2.getTemplatePresentation().getText()));
decorator.disableUpDownActions();
decorator.setAddActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
return !myAddActions.isEmpty();
}
});
decorator.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
performAdd(button);
}
});
decorator.setRemoveActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
boolean enabled = false;
for (InjInfo info : getSelectedInjections()) {
if (!info.bundled) {
enabled = true;
break;
}
}
return enabled;
}
});
decorator.setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
performRemove();
}
});
decorator.setEditActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
AnAction edit = getEditAction();
if (edit != null)
edit.update(e);
return edit != null && edit.getTemplatePresentation().isEnabled();
}
});
decorator.setEditAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
performEditAction();
}
});
decorator.addExtraAction(new DumbAwareActionButton("Duplicate", "Duplicate", PlatformIcons.COPY_ICON) {
@Override
public boolean isEnabled() {
return getEditAction() != null;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final InjInfo injection = getSelectedInjection();
if (injection != null) {
addInjection(injection.injection.copy());
//performEditAction(e);
}
}
});
decorator.addExtraAction(new DumbAwareActionButton("Enable Selected Injections", "Enable Selected Injections", PlatformIcons.SELECT_ALL_ICON) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
performSelectedInjectionsEnabled(true);
}
});
decorator.addExtraAction(new DumbAwareActionButton("Disable Selected Injections", "Disable Selected Injections", PlatformIcons.UNSELECT_ALL_ICON) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
performSelectedInjectionsEnabled(false);
}
});
new DumbAwareAction("Toggle") {
@Override
public void update(@NotNull AnActionEvent e) {
SpeedSearchSupply supply = SpeedSearchSupply.getSupply(myInjectionsTable);
e.getPresentation().setEnabled(supply == null || !supply.isPopupActive());
}
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
performToggleAction();
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)), myInjectionsTable);
if (myInfos.length > 1) {
AnActionButton shareAction = new DumbAwareActionButton("Move to IDE Scope", null, PlatformIcons.IMPORT_ICON) {
{
addCustomUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
CfgInfo cfg = getTargetCfgInfo(getSelectedInjections());
e.getPresentation().setText(cfg == getDefaultCfgInfo() ? "Move to IDE Scope" : "Move to Project Scope");
return cfg != null;
}
});
}
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
final List<InjInfo> injections = getSelectedInjections();
final CfgInfo cfg = getTargetCfgInfo(injections);
if (cfg == null)
return;
for (InjInfo info : injections) {
if (info.cfgInfo == cfg)
continue;
if (info.bundled)
continue;
info.cfgInfo.injectionInfos.remove(info);
cfg.addInjection(info.injection);
}
final int[] selectedRows = myInjectionsTable.getSelectedRows();
myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos));
TableUtil.selectRows(myInjectionsTable, selectedRows);
}
@Nullable
private CfgInfo getTargetCfgInfo(final List<InjInfo> injections) {
CfgInfo cfg = null;
for (InjInfo info : injections) {
if (info.bundled) {
continue;
}
if (cfg == null)
cfg = info.cfgInfo;
else if (cfg != info.cfgInfo)
return info.cfgInfo;
}
if (cfg == null)
return null;
for (CfgInfo info : myInfos) {
if (info != cfg)
return info;
}
throw new AssertionError();
}
};
shareAction.setShortcut(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_DOWN_MASK)));
decorator.addExtraAction(shareAction);
}
decorator.addExtraAction(new DumbAwareActionButton("Import", "Import", AllIcons.Actions.Install) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
doImportAction(e.getDataContext());
updateCountLabel();
}
});
decorator.addExtraAction(new DumbAwareActionButton("Export", "Export", AllIcons.Actions.Export) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
final List<BaseInjection> injections = getInjectionList(getSelectedInjections());
final VirtualFileWrapper wrapper = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Export Selected Injections to File...", "", "xml"), myProject).save(null, null);
if (wrapper == null)
return;
final Configuration configuration = new Configuration();
configuration.setInjections(injections);
try {
JdomKt.write(configuration.getState(), wrapper.getFile().toPath());
} catch (IOException ex) {
final String msg = ex.getLocalizedMessage();
Messages.showErrorDialog(myProject, msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
}
}
@Override
public boolean isEnabled() {
return !getSelectedInjections().isEmpty();
}
});
}
use of com.intellij.openapi.project.DumbAwareAction in project android by JetBrains.
the class AbstractDependenciesPanel method createActionsPanel.
@NotNull
protected final JPanel createActionsPanel() {
JPanel actionsPanel = new JPanel(new BorderLayout());
DefaultActionGroup actions = new DefaultActionGroup();
AnAction addDependencyAction = new DumbAwareAction("Add Dependency", "", IconUtil.getAddIcon()) {
@Override
public void actionPerformed(AnActionEvent e) {
JBPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<AbstractPopupAction>(null, getPopupActions()) {
@Override
public Icon getIconFor(AbstractPopupAction action) {
return action.icon;
}
@Override
public boolean isMnemonicsNavigationEnabled() {
return true;
}
@Override
public PopupStep onChosen(AbstractPopupAction action, boolean finalChoice) {
return doFinalStep(action::execute);
}
@Override
@NotNull
public String getTextFor(AbstractPopupAction action) {
return "&" + action.index + " " + action.text;
}
});
popup.show(new RelativePoint(actionsPanel, new Point(0, actionsPanel.getHeight() - 1)));
}
};
actions.add(addDependencyAction);
List<AnAction> extraToolbarActions = getExtraToolbarActions();
if (!extraToolbarActions.isEmpty()) {
actions.addSeparator();
actions.addAll(extraToolbarActions);
}
ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("TOP", actions, true);
JComponent toolbarComponent = toolbar.getComponent();
toolbarComponent.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
actionsPanel.add(toolbarComponent, BorderLayout.CENTER);
return actionsPanel;
}
use of com.intellij.openapi.project.DumbAwareAction in project intellij-community by JetBrains.
the class TemplateListPanel method addTemplateOrGroup.
private void addTemplateOrGroup(AnActionButton button) {
DefaultActionGroup group = new DefaultActionGroup();
group.add(new DumbAwareAction("Live Template") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
addTemplate();
}
});
group.add(new DumbAwareAction("Template Group...") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
String newName = Messages.showInputDialog(myTree, "Enter the new group name:", "Create New Group", null, "", new TemplateGroupInputValidator(null));
if (newName != null) {
TemplateGroup newGroup = new TemplateGroup(newName);
setSelectedNode(insertNewGroup(newGroup));
}
}
});
DataContext context = DataManager.getInstance().getDataContext(button.getContextComponent());
ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, group, context, JBPopupFactory.ActionSelectionAid.ALPHA_NUMBERING, true, null);
popup.show(button.getPreferredPopupPoint());
}
use of com.intellij.openapi.project.DumbAwareAction in project intellij-community by JetBrains.
the class JsonSchemaMappingsConfigurable method createActions.
@Nullable
@Override
protected ArrayList<AnAction> createActions(boolean fromPopup) {
final ArrayList<AnAction> result = new ArrayList<>();
result.add(new DumbAwareAction("Add", "Add", IconUtil.getAddIcon()) {
{
registerCustomShortcutSet(CommonShortcuts.INSERT, myTree);
}
@Override
public void actionPerformed(AnActionEvent e) {
addProjectSchema();
}
});
result.add(new MyDeleteAction());
return result;
}
Aggregations