DBE-12260 Support custom shortcut text in actions popup menu
authorLiudmila Kornilova <kornilova203@gmail.com>
Thu, 17 Dec 2020 11:59:06 +0000 (14:59 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Tue, 22 Dec 2020 09:15:29 +0000 (09:15 +0000)
Show users that they can add a column to sorted columns by pressing alt+click

GitOrigin-RevId: 65c6494236fcd6ce3fb936763e799a8037e6afdb

platform/platform-impl/src/com/intellij/ui/plaf/beg/BegMenuItemUI.java

index 48e5ad17c810324eea8c169b86b11f514445b214..f8084d4db8cf885c5d9ea66a11cd7e968844e060 100644 (file)
@@ -9,9 +9,8 @@ import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.actionSystem.impl.ActionMenuItem;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.keymap.KeymapUtil;
-import com.intellij.openapi.util.NlsContexts;
-import com.intellij.openapi.util.NlsSafe;
-import com.intellij.openapi.util.SystemInfoRt;
+import com.intellij.openapi.util.*;
+import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.util.IconUtil;
 import com.intellij.util.ui.StartupUiUtil;
 import com.intellij.util.ui.UIUtil;
@@ -53,6 +52,7 @@ public final class BegMenuItemUI extends BasicMenuItemUI {
   @NonNls public static final String PLAY_SOUND_METHOD = "playSound";
   @NonNls public static final String AQUA_LOOK_AND_FEEL_CLASS_NAME = "apple.laf.AquaLookAndFeel";
   @NonNls public static final String GET_KEY_MODIFIERS_TEXT = "getKeyModifiersText";
+  public static final Key<String> CUSTOM_KEY_STROKE_TEXT = new Key<>("CUSTOM_KEY_STROKE_TEXT");
 
   private Border myAquaSelectedBackgroundPainter;
 
@@ -223,9 +223,15 @@ public final class BegMenuItemUI extends BasicMenuItemUI {
   }
 
   private static @NlsSafe String getKeyStrokeText(@NotNull JMenuItem item) {
-    return item instanceof ActionMenuItem
-           ? ((ActionMenuItem)item).getFirstShortcutText()
-           : getKeyStrokeText(item.getAccelerator());
+    if (item instanceof ActionMenuItem) {
+      AnAction action = ((ActionMenuItem)item).getAnAction();
+      if (action instanceof UserDataHolder) {
+        String customText = ((UserDataHolder)action).getUserData(CUSTOM_KEY_STROKE_TEXT);
+        if (!StringUtil.isEmptyOrSpaces(customText)) return customText;
+      }
+      return ((ActionMenuItem)item).getFirstShortcutText();
+    }
+    return getKeyStrokeText(item.getAccelerator());
   }
 
   @NlsSafe