use of com.intellij.openapi.project.DumbAwareAction in project intellij-community by JetBrains.
the class MergeList method addActions.
private void addActions(@NotNull final FragmentSide side) {
ChangeList changeList = getChanges(side);
final FragmentSide originalSide = BRANCH_SIDE;
for (int i = 0; i < changeList.getCount(); i++) {
final Change change = changeList.getChange(i);
if (!change.canHasActions(originalSide))
continue;
Icon arrowIcon = side == FragmentSide.SIDE1 ? AllIcons.Diff.ArrowRight : AllIcons.Diff.Arrow;
AnAction applyAction = new DumbAwareAction(DiffBundle.message("merge.dialog.apply.change.action.name"), null, arrowIcon) {
@Override
public void actionPerformed(@Nullable AnActionEvent e) {
apply(change);
}
};
AnAction ignoreAction = new DumbAwareAction(DiffBundle.message("merge.dialog.ignore.change.action.name"), null, AllIcons.Diff.Remove) {
@Override
public void actionPerformed(@Nullable AnActionEvent e) {
change.removeFromList();
}
};
change.getChangeSide(originalSide).getHighlighterHolder().setActions(new AnAction[] { applyAction, ignoreAction });
}
}
use of com.intellij.openapi.project.DumbAwareAction in project intellij-community by JetBrains.
the class KeymapPanel method createEditActionGroup.
@NotNull
private DefaultActionGroup createEditActionGroup(@NotNull final String actionId) {
DefaultActionGroup group = new DefaultActionGroup();
final ShortcutRestrictions restrictions = ActionShortcutRestrictions.getInstance().getForActionId(actionId);
if (restrictions.allowKeyboardShortcut) {
group.add(new DumbAwareAction("Add Keyboard Shortcut") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Keymap keymapSelected = myEditor.getModel().getSelected();
assert keymapSelected != null;
addKeyboardShortcut(actionId, restrictions, keymapSelected, KeymapPanel.this, myQuickLists);
repaintLists();
currentKeymapChanged();
}
});
}
if (restrictions.allowMouseShortcut) {
group.add(new DumbAwareAction("Add Mouse Shortcut") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Keymap keymapSelected = myEditor.getModel().getSelected();
assert keymapSelected != null;
addMouseShortcut(actionId, restrictions, keymapSelected, KeymapPanel.this, myQuickLists);
repaintLists();
currentKeymapChanged();
}
});
}
if (Registry.is("actionSystem.enableAbbreviations") && restrictions.allowAbbreviation) {
group.add(new DumbAwareAction("Add Abbreviation") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
String abbr = Messages.showInputDialog("Enter new abbreviation:", "Abbreviation", null);
if (abbr != null) {
AbbreviationManager.getInstance().register(abbr, myActionsTree.getSelectedActionId());
repaintLists();
}
}
@Override
public void update(@NotNull AnActionEvent e) {
e.getPresentation().setEnabledAndVisible(myActionsTree.getSelectedActionId() != null);
}
});
}
group.addSeparator();
Keymap keymap = myEditor.getModel().getSelected();
assert keymap != null;
for (final Shortcut shortcut : keymap.getShortcuts(actionId)) {
group.add(new DumbAwareAction("Remove " + KeymapUtil.getShortcutText(shortcut)) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Keymap keymap = createKeymapCopyIfNeeded();
keymap.removeShortcut(actionId, shortcut);
if (StringUtil.startsWithChar(actionId, '$')) {
keymap.removeShortcut(KeyMapBundle.message("editor.shortcut", actionId.substring(1)), shortcut);
}
repaintLists();
currentKeymapChanged();
}
});
}
if (Registry.is("actionSystem.enableAbbreviations")) {
for (final String abbreviation : AbbreviationManager.getInstance().getAbbreviations(actionId)) {
group.addAction(new DumbAwareAction("Remove Abbreviation '" + abbreviation + "'") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
AbbreviationManager.getInstance().remove(abbreviation, actionId);
repaintLists();
}
});
}
}
group.add(new Separator());
group.add(new DumbAwareAction("Reset Shortcuts") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
((KeymapImpl) createKeymapCopyIfNeeded()).clearOwnActionsId(actionId);
currentKeymapChanged();
repaintLists();
}
@Override
public void update(@NotNull AnActionEvent e) {
e.getPresentation().setVisible(((KeymapImpl) myEditor.getModel().getSelected()).hasOwnActionId(actionId));
}
});
return group;
}
use of com.intellij.openapi.project.DumbAwareAction in project intellij-community by JetBrains.
the class KeymapPanel method createToolbarPanel.
private JPanel createToolbarPanel() {
final JPanel panel = new JPanel(new GridBagLayout());
DefaultActionGroup group = new DefaultActionGroup();
final JComponent toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true).getComponent();
final CommonActionsManager commonActionsManager = CommonActionsManager.getInstance();
final TreeExpander treeExpander = new TreeExpander() {
@Override
public void expandAll() {
TreeUtil.expandAll(myActionsTree.getTree());
}
@Override
public boolean canExpand() {
return true;
}
@Override
public void collapseAll() {
TreeUtil.collapseAll(myActionsTree.getTree(), 0);
}
@Override
public boolean canCollapse() {
return true;
}
};
group.add(commonActionsManager.createExpandAllAction(treeExpander, myActionsTree.getTree()));
group.add(commonActionsManager.createCollapseAllAction(treeExpander, myActionsTree.getTree()));
group.add(new AnAction("Edit Shortcut", "Edit Shortcut", AllIcons.ToolbarDecorator.Edit) {
{
registerCustomShortcutSet(CommonShortcuts.ENTER, myActionsTree.getTree());
}
@Override
public void update(@NotNull AnActionEvent e) {
final String actionId = myActionsTree.getSelectedActionId();
e.getPresentation().setEnabled(actionId != null);
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
editSelection(e.getInputEvent(), false);
}
});
panel.add(toolbar, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 0, 0, 0), 0, 0));
group = new DefaultActionGroup();
ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
actionToolbar.setReservePlaceAutoPopupIcon(false);
final JComponent searchToolbar = actionToolbar.getComponent();
final Alarm alarm = new Alarm();
myFilterComponent = new FilterComponent("KEYMAP", 5) {
@Override
public void filter() {
alarm.cancelAllRequests();
alarm.addRequest(() -> {
if (!myFilterComponent.isShowing())
return;
myTreeExpansionMonitor.freeze();
myFilteringPanel.setShortcut(null);
final String filter = getFilter();
myActionsTree.filter(filter, myQuickLists);
final JTree tree = myActionsTree.getTree();
TreeUtil.expandAll(tree);
if (filter == null || filter.length() == 0) {
TreeUtil.collapseAll(tree, 0);
myTreeExpansionMonitor.restore();
} else {
myTreeExpansionMonitor.unfreeze();
}
}, 300);
}
};
myFilterComponent.reset();
panel.add(myFilterComponent, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(8, 0, 0, 0), 0, 0));
group.add(new DumbAwareAction(KeyMapBundle.message("filter.shortcut.action.text"), KeyMapBundle.message("filter.shortcut.action.text"), AllIcons.Actions.ShortcutFilter) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
myFilterComponent.reset();
//noinspection ConstantConditions
myActionsTree.reset(myEditor.getModel().getSelected(), myQuickLists);
myFilteringPanel.showPopup(searchToolbar);
}
});
group.add(new DumbAwareAction(KeyMapBundle.message("filter.clear.action.text"), KeyMapBundle.message("filter.clear.action.text"), AllIcons.Actions.GC) {
@Override
public void update(AnActionEvent event) {
boolean enabled = null != myFilteringPanel.getShortcut();
Presentation presentation = event.getPresentation();
presentation.setEnabled(enabled);
presentation.setIcon(enabled ? AllIcons.Actions.Cancel : EmptyIcon.ICON_16);
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
myTreeExpansionMonitor.freeze();
myFilteringPanel.setShortcut(null);
//clear filtering
myActionsTree.filter(null, myQuickLists);
TreeUtil.collapseAll(myActionsTree.getTree(), 0);
myTreeExpansionMonitor.restore();
}
});
panel.add(searchToolbar, new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(8, 0, 0, 0), 0, 0));
return panel;
}
use of com.intellij.openapi.project.DumbAwareAction in project intellij-community by JetBrains.
the class ToolWindowContentUi method toggleContentPopup.
public void toggleContentPopup() {
if (myShouldNotShowPopup) {
myShouldNotShowPopup = false;
return;
}
final Ref<AnAction> selected = Ref.create();
final Ref<AnAction> selectedTab = Ref.create();
final Content[] contents = myManager.getContents();
final Content selectedContent = myManager.getSelectedContent();
final AnAction[] actions = new AnAction[contents.length];
for (int i = 0; i < actions.length; i++) {
final Content content = contents[i];
if (content instanceof TabbedContent) {
final TabbedContent tabbedContent = (TabbedContent) content;
final List<Pair<String, JComponent>> tabs = ((TabbedContent) content).getTabs();
final AnAction[] tabActions = new AnAction[tabs.size()];
for (int j = 0; j < tabActions.length; j++) {
final int index = j;
tabActions[j] = new DumbAwareAction(tabs.get(index).first) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
myManager.setSelectedContent(tabbedContent);
tabbedContent.selectContent(index);
}
};
}
final DefaultActionGroup group = new DefaultActionGroup(tabActions);
group.getTemplatePresentation().setText(((TabbedContent) content).getTitlePrefix());
group.setPopup(true);
actions[i] = group;
if (content == selectedContent) {
selected.set(group);
final int selectedIndex = ContentUtilEx.getSelectedTab(tabbedContent);
if (selectedIndex != -1) {
selectedTab.set(tabActions[selectedIndex]);
}
}
} else {
actions[i] = new DumbAwareAction() {
{
getTemplatePresentation().setText(content.getTabName(), false);
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
myManager.setSelectedContent(content, true, true);
}
};
if (content == selectedContent) {
selected.set(actions[i]);
}
}
}
final ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, new DefaultActionGroup(actions), DataManager.getInstance().getDataContext(myManager.getComponent()), false, true, true, null, -1, action -> action == selected.get() || action == selectedTab.get());
getCurrentLayout().showContentPopup(popup);
if (selectedContent instanceof TabbedContent) {
new Alarm(Alarm.ThreadToUse.SWING_THREAD, popup).addRequest(() -> popup.handleSelect(true), 30);
}
}
use of com.intellij.openapi.project.DumbAwareAction in project intellij-community by JetBrains.
the class QuickChangeLookAndFeel method fillActions.
protected void fillActions(Project project, @NotNull DefaultActionGroup group, @NotNull DataContext dataContext) {
LafManager lafMan = LafManager.getInstance();
UIManager.LookAndFeelInfo[] lfs = lafMan.getInstalledLookAndFeels();
UIManager.LookAndFeelInfo current = lafMan.getCurrentLookAndFeel();
for (UIManager.LookAndFeelInfo lf : lfs) {
group.add(new DumbAwareAction(lf.getName(), "", lf == current ? ourCurrentAction : ourNotCurrentAction) {
public void actionPerformed(AnActionEvent e) {
switchLafAndUpdateUI(lafMan, lf);
}
});
}
}
Aggregations