From cdae8b813804c9258ea44ed9709021e850c75ac6 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Thu, 12 Oct 2023 17:55:29 +0300 Subject: [PATCH] improve messages for action system errors See EA-922947 - T: Unsafe.unpark GitOrigin-RevId: 9656515a3d16993cbec3e62c3cd0c984f596a135 --- .../intellij/ui/mac/touchbar/Touchbar.java | 79 +++++++++++-------- 1 file changed, 47 insertions(+), 32 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/mac/touchbar/Touchbar.java b/platform/platform-api/src/com/intellij/ui/mac/touchbar/Touchbar.java index d449620e1559..3d476dbf7739 100644 --- a/platform/platform-api/src/com/intellij/ui/mac/touchbar/Touchbar.java +++ b/platform/platform-api/src/com/intellij/ui/mac/touchbar/Touchbar.java @@ -153,38 +153,7 @@ public final class Touchbar { boolean useTextFromAction /*for optional buttons*/) { Object anAct = action == null ? null : action.getValue(OptionAction.AN_ACTION); if (anAct == null) { - anAct = new DumbAwareAction() { - { - setEnabledInModalContext(true); - if (useTextFromAction) { - Object name = action == null ? button.getText() : action.getValue(Action.NAME); - getTemplatePresentation().setText(name instanceof String ? (String)name : ""); - } - } - - @Override - public void actionPerformed(@NotNull AnActionEvent e) { - if (action == null) { - button.doClick(); - return; - } - // also can be used something like: ApplicationManager.getApplication().invokeLater(() -> jb.doClick(), ms) - action.actionPerformed(new ActionEvent(button, ActionEvent.ACTION_PERFORMED, null)); - } - - @Override - public void update(@NotNull AnActionEvent e) { - e.getPresentation().setEnabled(action == null ? button.isEnabled() : action.isEnabled()); - if (!useTextFromAction) { - e.getPresentation().setText(DialogWrapper.extractMnemonic(button.getText()).second); - } - } - - @Override - public @NotNull ActionUpdateThread getActionUpdateThread() { - return ActionUpdateThread.EDT; - } - }; + anAct = new MyAction(useTextFromAction, action, button); } if (!(anAct instanceof AnAction)) { return null; @@ -192,4 +161,50 @@ public final class Touchbar { TouchbarActionCustomizations.setComponent((AnAction)anAct, button).setShowText(true).setShowImage(false); return (AnAction)anAct; } + + private static class MyAction extends DumbAwareAction implements ActionWithDelegate { + + final boolean useTextFromAction; + final @Nullable Action action; + final @NotNull JButton button; + + MyAction(boolean useTextFromAction, @Nullable Action action, @NotNull JButton button) { + this.useTextFromAction = useTextFromAction; + this.action = action; + this.button = button; + setEnabledInModalContext(true); + if (useTextFromAction) { + Object name = action == null ? button.getText() : action.getValue(Action.NAME); + getTemplatePresentation().setText(name instanceof String ? (String)name : ""); + } + } + + @Override + public @NotNull Object getDelegate() { + return action == null ? button : action; + } + + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.EDT; + } + + @Override + public void actionPerformed(@NotNull AnActionEvent e) { + if (action == null) { + button.doClick(); + return; + } + // also can be used something like: ApplicationManager.getApplication().invokeLater(() -> jb.doClick(), ms) + action.actionPerformed(new ActionEvent(button, ActionEvent.ACTION_PERFORMED, null)); + } + + @Override + public void update(@NotNull AnActionEvent e) { + e.getPresentation().setEnabled(action == null ? button.isEnabled() : action.isEnabled()); + if (!useTextFromAction) { + e.getPresentation().setText(DialogWrapper.extractMnemonic(button.getText()).second); + } + } + } }