cleanup: employ DumbAwareAction.create

This commit is contained in:
Gregory.Shrago
2017-10-10 19:37:21 +03:00
parent 70071f1fd5
commit 31fe10e3ef
25 changed files with 170 additions and 296 deletions
@@ -2,7 +2,6 @@ package com.jetbrains.jsonSchema;
import com.intellij.json.JsonBundle;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonShortcuts;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
@@ -126,22 +125,19 @@ public class JsonSchemaMappingsView implements Disposable {
}
private void attachNavigateToSchema() {
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
final String pathToSchema = mySchemaField.getText();
if (StringUtil.isEmptyOrSpaces(pathToSchema)) return;
final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(pathToSchema));
if (virtualFile == null) {
BalloonBuilder balloonBuilder = JBPopupFactory.getInstance()
.createHtmlTextBalloonBuilder("File not found", UIUtil.getBalloonErrorIcon(), MessageType.ERROR.getPopupBackground(), null);
final Balloon balloon = balloonBuilder.setFadeoutTime(TimeUnit.SECONDS.toMillis(3)).createBalloon();
balloon.showInCenterOf(mySchemaField);
return;
}
new OpenFileDescriptor(myProject, virtualFile).navigate(true);
DumbAwareAction.create(e -> {
String pathToSchema = mySchemaField.getText();
if (StringUtil.isEmptyOrSpaces(pathToSchema)) return;
VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(pathToSchema));
if (virtualFile == null) {
BalloonBuilder balloonBuilder = JBPopupFactory.getInstance()
.createHtmlTextBalloonBuilder("File not found", UIUtil.getBalloonErrorIcon(), MessageType.ERROR.getPopupBackground(), null);
Balloon balloon = balloonBuilder.setFadeoutTime(TimeUnit.SECONDS.toMillis(3)).createBalloon();
balloon.showInCenterOf(mySchemaField);
return;
}
}.registerCustomShortcutSet(CommonShortcuts.getEditSource(), mySchemaField);
new OpenFileDescriptor(myProject, virtualFile).navigate(true);
}).registerCustomShortcutSet(CommonShortcuts.getEditSource(), mySchemaField);
}
public List<UserDefinedJsonSchemaConfiguration.Item> getData() {
@@ -65,12 +65,7 @@ public abstract class DiffGutterRenderer extends GutterIconRenderer implements N
@Nullable
@Override
public AnAction getClickAction() {
return new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
performAction(e);
}
};
return DumbAwareAction.create(e -> performAction(e));
}
@Override
@@ -640,12 +640,8 @@ public class DirDiffPanel implements Disposable, DataProvider {
public MyFilterComponent() {
super("dir.diff.filter", 15, false);
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
userTriggeredFilter();
}
}.registerCustomShortcutSet(CommonShortcuts.ENTER, this);
DumbAwareAction.create(e -> userTriggeredFilter())
.registerCustomShortcutSet(CommonShortcuts.ENTER, this);
}
@Override
@@ -20,7 +20,6 @@ import com.intellij.injected.editor.DocumentWindow;
import com.intellij.lang.Language;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonShortcuts;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.undo.UndoManager;
@@ -226,12 +225,8 @@ public class QuickEditHandler implements Disposable, DocumentListener {
.setHideOnAction(false)
.setFillColor(UIUtil.getControlColor())
.createBalloon();
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
balloon.hide();
}
}.registerCustomShortcutSet(CommonShortcuts.ESCAPE, component);
DumbAwareAction.create(e -> balloon.hide())
.registerCustomShortcutSet(CommonShortcuts.ESCAPE, component);
Disposer.register(newFile.getProject(), balloon);
final Balloon.Position position = QuickEditAction.getBalloonPosition(editor);
RelativePoint point = JBPopupFactory.getInstance().guessBestPopupLocation(editor);
@@ -106,16 +106,13 @@ public class ProjectStartupConfigurable implements SearchableConfigurable, Confi
defaultEditor.setClickCountToStart(1);
myTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
final int row = myTable.getSelectedRow();
if (row >= 0 && myModel.isCellEditable(row, ProjectStartupTasksTableModel.IS_SHARED_COLUMN)) {
myModel.setValueAt(!Boolean.TRUE.equals(myTable.getValueAt(row, ProjectStartupTasksTableModel.IS_SHARED_COLUMN)),
row, ProjectStartupTasksTableModel.IS_SHARED_COLUMN);
}
DumbAwareAction.create(e -> {
int row = myTable.getSelectedRow();
if (row >= 0 && myModel.isCellEditable(row, ProjectStartupTasksTableModel.IS_SHARED_COLUMN)) {
myModel.setValueAt(!Boolean.TRUE.equals(myTable.getValueAt(row, ProjectStartupTasksTableModel.IS_SHARED_COLUMN)),
row, ProjectStartupTasksTableModel.IS_SHARED_COLUMN);
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyEvent.VK_SPACE), myTable);
}).registerCustomShortcutSet(new CustomShortcutSet(KeyEvent.VK_SPACE), myTable);
myTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
@@ -189,15 +189,12 @@ public class SearchTextArea extends NonOpaquePanel implements PropertyChangeList
myHelper = createHelper();
myHistoryPopupButton = createButton(new ShowHistoryAction());
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
IdeTooltipManager.getInstance().show(new IdeTooltip(myTextArea, new Point(), new JLabel("The shortcut was changed. Press " +
KeymapUtil.getKeystrokeText(
SearchTextField.SHOW_HISTORY_KEYSTROKE) +
" to open search history.")), true, true);
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_DOWN_MASK)), myTextArea);
DumbAwareAction.create(e -> IdeTooltipManager.getInstance().show(
new IdeTooltip(myTextArea, new Point(), new JLabel(
"The shortcut was changed. Press " +
KeymapUtil.getKeystrokeText(SearchTextField.SHOW_HISTORY_KEYSTROKE) +
" to open search history.")), true, true))
.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_DOWN_MASK)), myTextArea);
myClearButton = createButton(new ClearAction());
myNewLineButton = createButton(new NewLineAction());
myNewLineButton.setVisible(searchMode);
@@ -655,13 +655,10 @@ public class FindDialog extends DialogWrapper implements FindUI {
pane.insertTab("Options", null, optionsPanel, null, 0);
pane.insertTab(PREVIEW_TITLE, null, myPreviewSplitter, null, RESULTS_PREVIEW_TAB_INDEX);
myContent = pane;
final AnAction anAction = new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
int selectedIndex = myContent.getSelectedIndex();
myContent.setSelectedIndex(1 - selectedIndex);
}
};
AnAction anAction = DumbAwareAction.create(e -> {
int selectedIndex = myContent.getSelectedIndex();
myContent.setSelectedIndex(1 - selectedIndex);
});
final ShortcutSet shortcutSet = ActionManager.getInstance().getAction(IdeActions.ACTION_SWITCHER).getShortcutSet();
@@ -477,26 +477,22 @@ public class FindPopupPanel extends JBPanel implements FindUI {
myOKButton.addActionListener(myOkActionListener);
boolean enterAsOK = Registry.is("ide.find.enter.as.ok", false);
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
if (enterAsOK ) {
myOkActionListener.actionPerformed(null);
} else {
navigateToSelectedUsage();
}
DumbAwareAction.create(e -> {
if (enterAsOK) {
myOkActionListener.actionPerformed(null);
}
}.registerCustomShortcutSet(new CustomShortcutSet(ENTER), this);
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
if (enterAsOK) {
navigateToSelectedUsage();
} else {
myOkActionListener.actionPerformed(null);
}
else {
navigateToSelectedUsage();
}
}.registerCustomShortcutSet(new CustomShortcutSet(ENTER_WITH_MODIFIERS), this);
}).registerCustomShortcutSet(new CustomShortcutSet(ENTER), this);
DumbAwareAction.create(e -> {
if (enterAsOK) {
navigateToSelectedUsage();
}
else {
myOkActionListener.actionPerformed(null);
}
}).registerCustomShortcutSet(new CustomShortcutSet(ENTER_WITH_MODIFIERS), this);
List<Shortcut> navigationKeyStrokes = ContainerUtil.newArrayList();
KeyStroke viewSourceKeyStroke = KeymapUtil.getKeyStroke(CommonShortcuts.getViewSource());
@@ -756,16 +752,12 @@ public class FindPopupPanel extends JBPanel implements FindUI {
private void registerCloseAction(JBPopup popup) {
final AnAction escape = ActionManager.getInstance().getAction("EditorEscape");
DumbAwareAction closeAction = new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
if (canBeClosedImmediately() && myBalloon != null && myBalloon.isVisible()) {
myIsPinned.set(false);
myBalloon.cancel();
}
DumbAwareAction.create(e -> {
if (canBeClosedImmediately() && myBalloon != null && myBalloon.isVisible()) {
myIsPinned.set(false);
myBalloon.cancel();
}
};
closeAction.registerCustomShortcutSet(escape == null ? CommonShortcuts.ESCAPE : escape.getShortcutSet(), popup.getContent(), popup);
}).registerCustomShortcutSet(escape == null ? CommonShortcuts.ESCAPE : escape.getShortcutSet(), popup.getContent(), popup);
}
@Override
@@ -96,7 +96,7 @@ public class GotoActionAction extends GotoActionBase implements DumbAware {
String initialText,
int initialIndex,
final Component component,
final AnActionEvent e) {
final AnActionEvent event) {
ChooseByNamePopup oldPopup = project == null ? null : project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
if (oldPopup != null) {
oldPopup.close(false);
@@ -190,8 +190,9 @@ public class GotoActionAction extends GotoActionBase implements DumbAware {
protected boolean closeForbidden(boolean ok) {
if (!ok) return false;
Object element = getChosenElement();
return element instanceof GotoActionModel.MatchedValue && processOptionInplace(((GotoActionModel.MatchedValue)element).value, this, component, e)
|| super.closeForbidden(true);
return element instanceof GotoActionModel.MatchedValue &&
processOptionInplace(((GotoActionModel.MatchedValue)element).value, this, component, event) ||
super.closeForbidden(true);
}
@Override
@@ -225,7 +226,7 @@ public class GotoActionAction extends GotoActionBase implements DumbAware {
public void mouseClicked(@NotNull MouseEvent me) {
Object element = popup.getSelectionByPoint(me.getPoint());
if (element instanceof GotoActionModel.MatchedValue) {
if (processOptionInplace(((GotoActionModel.MatchedValue)element).value, popup, component, e)) {
if (processOptionInplace(((GotoActionModel.MatchedValue)element).value, popup, component, event)) {
me.consume();
}
}
@@ -233,29 +234,25 @@ public class GotoActionAction extends GotoActionBase implements DumbAware {
});
ShortcutSet shortcutSet = getActiveKeymapShortcuts(IdeActions.ACTION_SHOW_INTENTION_ACTIONS);
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
Object o = popup.getChosenElement();
if (o instanceof GotoActionModel.MatchedValue) {
Comparable value = ((GotoActionModel.MatchedValue)o).value;
if (value instanceof GotoActionModel.ActionWrapper) {
GotoActionModel.ActionWrapper aw = (GotoActionModel.ActionWrapper)value;
boolean available = aw.isAvailable();
if (available) {
AnAction action = aw.getAction();
String id = ActionManager.getInstance().getId(action);
KeymapManagerImpl km = ((KeymapManagerImpl)KeymapManager.getInstance());
Keymap k = km.getActiveKeymap();
if (k == null || !k.canModify()) return;
KeymapPanel.addKeyboardShortcut(id, ActionShortcutRestrictions.getInstance().getForActionId(id), k, component);
popup.repaintListImmediate();
}
DumbAwareAction.create(e -> {
Object o = popup.getChosenElement();
if (o instanceof GotoActionModel.MatchedValue) {
Comparable value = ((GotoActionModel.MatchedValue)o).value;
if (value instanceof GotoActionModel.ActionWrapper) {
GotoActionModel.ActionWrapper aw = (GotoActionModel.ActionWrapper)value;
boolean available = aw.isAvailable();
if (available) {
AnAction action = aw.getAction();
String id = ActionManager.getInstance().getId(action);
KeymapManagerImpl km = ((KeymapManagerImpl)KeymapManager.getInstance());
Keymap k = km.getActiveKeymap();
if (k == null || !k.canModify()) return;
KeymapPanel.addKeyboardShortcut(id, ActionShortcutRestrictions.getInstance().getForActionId(id), k, component);
popup.repaintListImmediate();
}
}
}
}.registerCustomShortcutSet(shortcutSet, popup.getTextField(), disposable);
}).registerCustomShortcutSet(shortcutSet, popup.getTextField(), disposable);
return popup;
}
@@ -908,40 +908,26 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA
private void initSearchActions(JBPopup balloon, MySearchTextField searchTextField) {
final JTextField editor = searchTextField.getTextEditor();
new DumbAwareAction(){
@Override
public void actionPerformed(AnActionEvent e) {
jumpNextGroup(true);
DumbAwareAction.create(e -> jumpNextGroup(true))
.registerCustomShortcutSet(CustomShortcutSet.fromString("TAB"), editor, balloon);
DumbAwareAction.create(e -> jumpNextGroup(false))
.registerCustomShortcutSet(CustomShortcutSet.fromString("shift TAB"), editor, balloon);
AnAction escape = ActionManager.getInstance().getAction("EditorEscape");
DumbAwareAction.create(e -> {
if (myBalloon != null && myBalloon.isVisible()) {
myBalloon.cancel();
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("TAB"), editor, balloon);
new DumbAwareAction(){
@Override
public void actionPerformed(AnActionEvent e) {
jumpNextGroup(false);
if (myPopup != null && myPopup.isVisible()) {
myPopup.cancel();
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("shift TAB"), editor, balloon);
final AnAction escape = ActionManager.getInstance().getAction("EditorEscape");
new DumbAwareAction(){
@Override
public void actionPerformed(AnActionEvent e) {
if (myBalloon != null && myBalloon.isVisible()) {
myBalloon.cancel();
}
if (myPopup != null && myPopup.isVisible()) {
myPopup.cancel();
}
}).registerCustomShortcutSet(escape == null ? CommonShortcuts.ESCAPE : escape.getShortcutSet(), editor, balloon);
DumbAwareAction.create(e -> {
int index = myList.getSelectedIndex();
if (index != -1) {
doNavigate(index);
}
}.registerCustomShortcutSet(escape == null ? CommonShortcuts.ESCAPE : escape.getShortcutSet(), editor, balloon);
new DumbAwareAction(){
@Override
public void actionPerformed(AnActionEvent e) {
final int index = myList.getSelectedIndex();
if (index != -1) {
doNavigate(index);
}
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("ENTER", "shift ENTER"), editor, balloon);
new DumbAwareAction(){
}).registerCustomShortcutSet(CustomShortcutSet.fromString("ENTER", "shift ENTER"), editor, balloon);
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
final PropertiesComponent storage = PropertiesComponent.getInstance(e.getProject());
@@ -16,7 +16,6 @@
package com.intellij.ide.actions;
import com.intellij.ide.ui.UISettings;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CustomShortcutSet;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.util.Trinity;
@@ -86,15 +85,12 @@ public class TemplateKindCombo extends ComboboxWithBrowseButton {
}
public void registerUpDownHint(JComponent component) {
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
if (e.getInputEvent() instanceof KeyEvent) {
final int code = ((KeyEvent)e.getInputEvent()).getKeyCode();
scrollBy(code == KeyEvent.VK_DOWN ? 1 : code == KeyEvent.VK_UP ? -1 : 0);
}
DumbAwareAction.create(e -> {
if (e.getInputEvent() instanceof KeyEvent) {
int code = ((KeyEvent)e.getInputEvent()).getKeyCode();
scrollBy(code == KeyEvent.VK_DOWN ? 1 : code == KeyEvent.VK_UP ? -1 : 0);
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN), component);
}).registerCustomShortcutSet(new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN), component);
}
private void scrollBy(int delta) {
@@ -16,9 +16,9 @@
package com.intellij.ide.util.projectWizard;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.DialogWrapperPeer;
@@ -70,12 +70,8 @@ public abstract class AbstractNewProjectDialog extends DialogWrapper {
Pair<JPanel, JBList<AnAction>> pair = FlatWelcomeFrame.createActionGroupPanel(root, getRootPane(), null, getDisposable());
JPanel component = pair.first;
new AnAction() {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
close(CANCEL_EXIT_CODE);
}
}.registerCustomShortcutSet(KeyEvent.VK_ESCAPE, 0, component);
DumbAwareAction.create(e -> close(CANCEL_EXIT_CODE))
.registerCustomShortcutSet(KeyEvent.VK_ESCAPE, 0, component);
myPair = pair;
UiNotifyConnector.doWhenFirstShown(myPair.second, () -> ScrollingUtil.ensureSelectionExists(myPair.second));
@@ -2,11 +2,10 @@ package com.intellij.lang.javascript.boilerplate;
import com.intellij.ide.BrowserUtil;
import com.intellij.ide.util.projectWizard.WebProjectTemplate;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.io.FileUtil;
@@ -157,12 +156,8 @@ public abstract class AbstractGithubTagDownloadedProjectGenerator extends WebPro
}
public ActionLink createGitHubLink() {
final ActionLink link = new ActionLink(getName() + " on GitHub", new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
BrowserUtil.open("https://github.com/" + getGithubUserName() + "/" + getGithubRepositoryName());
}
});
ActionLink link = new ActionLink(getName() + " on GitHub", DumbAwareAction.create(e ->
BrowserUtil.open("https://github.com/" + getGithubUserName() + "/" + getGithubRepositoryName())));
link.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
return link;
}
@@ -22,6 +22,7 @@ import com.intellij.history.core.revisions.Difference;
import com.intellij.history.integration.IdeaGateway;
import com.intellij.history.integration.ui.models.DirectoryHistoryDialogModel;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.Pair;
@@ -105,13 +106,8 @@ public class DirectoryHistoryDialog extends HistoryDialog<DirectoryHistoryDialog
});
}
});
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
field.requestFocusInWindow();
}
}.registerCustomShortcutSet(CommonShortcuts.getFind(), root, this);
DumbAwareAction.create(e -> field.requestFocusInWindow())
.registerCustomShortcutSet(CommonShortcuts.getFind(), root, this);
return field;
}
@@ -1287,12 +1287,7 @@ public abstract class DialogWrapper {
myPeer.setContentPane(root);
final CustomShortcutSet sc = new CustomShortcutSet(SHOW_OPTION_KEYSTROKE);
final AnAction toggleShowOptions = new DumbAwareAction() {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
expandNextOptionButton();
}
};
AnAction toggleShowOptions = DumbAwareAction.create(e -> expandNextOptionButton());
toggleShowOptions.registerCustomShortcutSet(sc, root, myDisposable);
JComponent titlePane = createTitlePane();
@@ -15,10 +15,9 @@
*/
package com.intellij.ui;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonShortcuts;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.FixedSizeButton;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
@@ -199,12 +198,7 @@ public abstract class AbstractFieldPanel extends JPanel {
}
});
new AnAction() {
public void actionPerformed(AnActionEvent e) {
doOKAction();
}
}.registerCustomShortcutSet(CommonShortcuts.ENTER, myTextArea);
DumbAwareAction.create(e -> doOKAction()).registerCustomShortcutSet(CommonShortcuts.ENTER, myTextArea);
return ScrollPaneFactory.createScrollPane(myTextArea);
}
}
@@ -20,7 +20,6 @@ import com.intellij.ide.BrowserUtil;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.ui.UISettings;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CustomShortcutSet;
import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.application.ApplicationNamesInfo;
@@ -588,12 +587,8 @@ public class AboutPopup {
public void setInfoSurface(InfoSurface infoSurface) {
myInfoSurface = infoSurface;
add(infoSurface, BorderLayout.NORTH);
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
copyInfoToClipboard(myInfoSurface.getText());
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("meta C", "control C"), this);
DumbAwareAction.create(e -> copyInfoToClipboard(myInfoSurface.getText()))
.registerCustomShortcutSet(CustomShortcutSet.fromString("meta C", "control C"), this);
}
protected class AccessiblePopupPanel extends AccessibleJPanel implements AccessibleAction {
@@ -56,6 +56,7 @@ import com.intellij.openapi.editor.ex.EditorGutterComponentEx;
import com.intellij.openapi.editor.ex.EditorMarkupModel;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Pair;
@@ -214,16 +215,13 @@ public class DiffPanelImpl implements DiffPanelEx, ContentChangeListener, TwoSid
private void registerActions() {
//control+tab switches editors
new AnAction(){
@Override
public void actionPerformed(AnActionEvent e) {
if (getEditor1() != null && getEditor2() != null) {
Editor focus = getEditor1().getContentComponent().hasFocus() ? getEditor2() : getEditor1();
IdeFocusManager.getGlobalInstance().requestFocus(focus.getContentComponent(), true);
focus.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
}
DumbAwareAction.create(e -> {
if (getEditor1() != null && getEditor2() != null) {
Editor focus = getEditor1().getContentComponent().hasFocus() ? getEditor2() : getEditor1();
IdeFocusManager.getGlobalInstance().requestFocus(focus.getContentComponent(), true);
focus.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("control TAB"), myPanel, this);
}).registerCustomShortcutSet(CustomShortcutSet.fromString("control TAB"), myPanel, this);
}
protected DiffPanelState createDiffPanelState(@NotNull Disposable parentDisposable) {
@@ -114,25 +114,22 @@ public class JBTerminalPanel extends TerminalPanel implements FocusListener, Ter
for (String actionId : ACTIONS_TO_SKIP) {
final AnAction action = actionManager.getAction(actionId);
if (action != null) {
AnAction a = new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
if (e.getInputEvent() instanceof KeyEvent) {
AnActionEvent event =
new AnActionEvent(e.getInputEvent(), e.getDataContext(), e.getPlace(), new Presentation(), e.getActionManager(),
e.getModifiers());
action.update(event);
if (event.getPresentation().isEnabled()) {
action.actionPerformed(event);
}
else {
terminalPanel.handleKeyEvent((KeyEvent)event.getInputEvent());
}
event.getInputEvent().consume();
AnAction a = DumbAwareAction.create(e -> {
if (e.getInputEvent() instanceof KeyEvent) {
AnActionEvent event =
new AnActionEvent(e.getInputEvent(), e.getDataContext(), e.getPlace(), new Presentation(), e.getActionManager(),
e.getModifiers());
action.update(event);
if (event.getPresentation().isEnabled()) {
action.actionPerformed(event);
}
else {
terminalPanel.handleKeyEvent((KeyEvent)event.getInputEvent());
}
event.getInputEvent().consume();
}
};
});
for (Shortcut sc : action.getShortcutSet().getShortcuts()) {
if (sc.isKeyboard() && sc instanceof KeyboardShortcut) {
KeyboardShortcut ksc = (KeyboardShortcut)sc;
@@ -15,17 +15,15 @@
*/
package com.intellij.ui.stripe;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAwareAction;
import java.beans.EventHandler;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.*;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import java.beans.EventHandler;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
/**
* @author Sergey.Malenkov
@@ -50,18 +48,10 @@ public class TreeUpdater<Painter extends ErrorStripePainter> extends Updater<Pai
myTree.addPropertyChangeListener(JTree.TREE_MODEL_PROPERTY, myPropertyChangeListener);
TreeModel model = myTree.getModel();
if (model != null) model.addTreeModelListener(myTreeModelListener);
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent event) {
selectNext(myTree.getMaxSelectionRow());
}
}.registerCustomShortcutSet(getNextErrorShortcut(), myTree, this);
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent event) {
selectPrevious(myTree.getMinSelectionRow());
}
}.registerCustomShortcutSet(getPreviousErrorShortcut(), myTree, this);
DumbAwareAction.create(e -> selectNext(myTree.getMaxSelectionRow()))
.registerCustomShortcutSet(getNextErrorShortcut(), myTree, this);
DumbAwareAction.create(e -> selectPrevious(myTree.getMinSelectionRow()))
.registerCustomShortcutSet(getPreviousErrorShortcut(), myTree, this);
}
@Override
@@ -139,12 +139,10 @@ public class XDebuggerEvaluationDialog extends DialogWrapper {
mySwitchModeAction = new SwitchModeAction();
// preserve old mode switch shortcut
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
mySwitchModeAction.actionPerformed(null);
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_M, InputEvent.ALT_DOWN_MASK)) ,getRootPane(), myDisposable);
DumbAwareAction.create(e -> mySwitchModeAction.actionPerformed(null))
.registerCustomShortcutSet(
new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_M, InputEvent.ALT_DOWN_MASK)),
getRootPane(), myDisposable);
new AnAction(){
@Override
@@ -21,7 +21,6 @@ import com.intellij.execution.impl.ConsoleViewImpl;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.ShortcutSet;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
@@ -223,12 +222,8 @@ public class XValueHint extends AbstractValueHint {
disposeVisibleHint();
myDisposable = Disposer.newDisposable();
ShortcutSet shortcut = ActionManager.getInstance().getAction("ShowErrorDescription").getShortcutSet();
new DumbAwareAction() {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
showTree(result);
}
}.registerCustomShortcutSet(shortcut, getEditor().getContentComponent(), myDisposable);
DumbAwareAction.create(e -> showTree(result))
.registerCustomShortcutSet(shortcut, getEditor().getContentComponent(), myDisposable);
}
showHint(createExpandableHintComponent(text, () -> showTree(result)));
@@ -97,22 +97,12 @@ public class XDebuggerExpressionEditor extends XDebuggerEditorBase {
if (multiline) {
ShortcutSet shortcut = ActionManager.getInstance().getAction(IdeActions.ACTION_NEXT_OCCURENCE).getShortcutSet();
if (shortcut != null) {
new DumbAwareAction() {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
goForward();
}
}.registerCustomShortcutSet(shortcut, myEditorTextField);
DumbAwareAction.create(e -> goForward()).registerCustomShortcutSet(shortcut, myEditorTextField);
}
shortcut = ActionManager.getInstance().getAction(IdeActions.ACTION_PREVIOUS_OCCURENCE).getShortcutSet();
if (shortcut != null) {
new DumbAwareAction() {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
goBackward();
}
}.registerCustomShortcutSet(shortcut, myEditorTextField);
DumbAwareAction.create(e -> goBackward()).registerCustomShortcutSet(shortcut, myEditorTextField);
}
}
@@ -18,9 +18,9 @@ package org.intellij.plugins.intelliLang.inject;
import com.intellij.lang.Language;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.DialogWrapper;
@@ -99,17 +99,14 @@ public abstract class AbstractLanguageInjectionSupport extends LanguageInjection
return createDefaultEditAction(project, producer);
}
public static AnAction createDefaultEditAction(final Project project, final Factory<BaseInjection> producer) {
return new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
final BaseInjection originalInjection = producer.create();
final BaseInjection newInjection = showDefaultInjectionUI(project, originalInjection.copy());
if (newInjection != null) {
originalInjection.copyFrom(newInjection);
}
public static AnAction createDefaultEditAction(Project project, Factory<BaseInjection> producer) {
return DumbAwareAction.create(e -> {
BaseInjection originalInjection = producer.create();
BaseInjection newInjection = showDefaultInjectionUI(project, originalInjection.copy());
if (newInjection != null) {
originalInjection.copyFrom(newInjection);
}
};
});
}
public static AnAction createDefaultAddAction(final Project project,
@@ -117,17 +114,17 @@ public abstract class AbstractLanguageInjectionSupport extends LanguageInjection
final AbstractLanguageInjectionSupport support) {
final String supportTitle = StringUtil.capitalize(support.getId());
Icon icon = FileTypeManager.getInstance().getFileTypeByExtension(support.getId()).getIcon();
return new AnAction("Generic "+ supportTitle, null, icon) {
@Override
public void actionPerformed(AnActionEvent e) {
final BaseInjection injection = new BaseInjection(support.getId());
injection.setDisplayName("New "+ supportTitle +" Injection");
final BaseInjection newInjection = showDefaultInjectionUI(project, injection);
if (newInjection != null) {
consumer.consume(injection);
}
AnAction action = DumbAwareAction.create(e -> {
BaseInjection injection = new BaseInjection(support.getId());
injection.setDisplayName("New " + supportTitle + " Injection");
final BaseInjection newInjection = showDefaultInjectionUI(project, injection);
if (newInjection != null) {
consumer.consume(injection);
}
};
});
action.getTemplatePresentation().setText("Generic " + supportTitle);
action.getTemplatePresentation().setIcon(icon);
return action;
}
@Nullable
@@ -23,8 +23,6 @@ import com.intellij.ide.dnd.DnDSupport;
import com.intellij.ide.dnd.TransferableWrapper;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.fileEditor.impl.EditorTabbedContainer;
import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl;
@@ -116,18 +114,14 @@ public class JBTabbedTerminalWidget extends TabbedTerminalWidget implements Disp
if (action.isHidden()) {
continue;
}
AnAction a = new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
KeyEvent event = e.getInputEvent() instanceof KeyEvent ? (KeyEvent)e.getInputEvent() : null;
if (!action.perform(event)) {
if (elseAction != null) {
elseAction.apply(event);
}
DumbAwareAction.create(e -> {
KeyEvent event = e.getInputEvent() instanceof KeyEvent ? (KeyEvent)e.getInputEvent() : null;
if (!action.perform(event)) {
if (elseAction != null) {
elseAction.apply(event);
}
}
};
a.registerCustomShortcutSet(action.getKeyCode(), action.getModifiers(), component);
}).registerCustomShortcutSet(action.getKeyCode(), action.getModifiers(), component);
}
}