From be04e5725f184afe8c8462d9f98e1eee93892df3 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Fri, 28 Jun 2024 19:13:46 +0400 Subject: [PATCH] move action customization keys to `ActionUtil` See IJPL-157278 Make `ActionMenu.SECONDARY_ICON` public API GitOrigin-RevId: 2da0f7c6e489169f55ee9ede092a63b14cb3ee71 --- platform/platform-api/api-dump-unreviewed.txt | 5 ++ .../openapi/actionSystem/ex/ActionUtil.kt | 63 +++++++++++++++---- .../actionSystem/impl/ActionButton.java | 14 +---- .../openapi/actionSystem/impl/ActionMenu.kt | 26 +++----- 4 files changed, 68 insertions(+), 40 deletions(-) diff --git a/platform/platform-api/api-dump-unreviewed.txt b/platform/platform-api/api-dump-unreviewed.txt index e4a4a25c2b03..8a724682aa31 100644 --- a/platform/platform-api/api-dump-unreviewed.txt +++ b/platform/platform-api/api-dump-unreviewed.txt @@ -1944,10 +1944,15 @@ com.intellij.openapi.actionSystem.ex.ActionPopupMenuListener - actionPopupMenuReleased(com.intellij.openapi.actionSystem.ActionPopupMenu):V f:com.intellij.openapi.actionSystem.ex.ActionUtil - sf:ALLOW_PlAIN_LETTER_SHORTCUTS:com.intellij.openapi.util.Key +- sf:ALWAYS_VISIBLE_GROUP:com.intellij.openapi.util.Key +- sf:HIDE_DROPDOWN_ICON:com.intellij.openapi.util.Key - sf:INLINE_ACTIONS:com.intellij.openapi.util.Key - sf:INSTANCE:com.intellij.openapi.actionSystem.ex.ActionUtil +- sf:KEYBOARD_SHORTCUT_SUFFIX:com.intellij.openapi.util.Key - sf:SEARCH_TAG:com.intellij.openapi.util.Key +- sf:SECONDARY_ICON:com.intellij.openapi.util.Key - sf:SECONDARY_TEXT:com.intellij.openapi.util.Key +- sf:SUPPRESS_SUBMENU:com.intellij.openapi.util.Key - sf:clearActions(javax.swing.JComponent):V - sf:copyFrom(com.intellij.openapi.actionSystem.AnAction,java.lang.String):com.intellij.openapi.actionSystem.AnAction - sf:copyRegisteredShortcuts(javax.swing.JComponent,javax.swing.JComponent):V diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.kt b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.kt index 5360be3a3e3e..9e56ee12a08a 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.kt +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.kt @@ -26,6 +26,7 @@ import com.intellij.openapi.util.Computable import com.intellij.openapi.util.Key import com.intellij.openapi.util.NlsActions.ActionText import com.intellij.openapi.util.NlsContexts +import com.intellij.openapi.util.NlsSafe import com.intellij.openapi.util.ThrowableComputable import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.util.text.StringUtil @@ -44,6 +45,7 @@ import java.util.* import java.util.concurrent.TimeUnit import java.util.function.Consumer import javax.swing.Action +import javax.swing.Icon import javax.swing.JComponent import javax.swing.KeyStroke @@ -52,6 +54,41 @@ private val InputEventDummyAction = EmptyAction.createEmptyAction(null, null, tr object ActionUtil { + /** + * By default, a "performable" non-empty popup action group menu item still shows a submenu. + * Use this key to disable the submenu and avoid children expansion on update as follows: + * + * `presentation.putClientProperty(ActionMenu.SUPPRESS_SUBMENU, true)`. + * + * Both ordinary and template presentations are supported. + * @see Presentation.setPerformGroup + */ + @JvmField + val SUPPRESS_SUBMENU: Key = Key.create("SUPPRESS_SUBMENU") + + /** + * By default, a toolbar button for a popup action group paints the additional "drop-down-arrow" mark over its icon. + * Use this key to disable the painting of that mark as follows: + * + * `presentation.putClientProperty(ActionButton.HIDE_DROPDOWN_ICON, true)` + * + * Both ordinary and template presentations are supported. + * @see Presentation.setPerformGroup + */ + @JvmField + val HIDE_DROPDOWN_ICON: Key = Key.create("HIDE_DROPDOWN_ICON"); + + @JvmField + val KEYBOARD_SHORTCUT_SUFFIX: Key<@NlsSafe String> = Key.create("KEYBOARD_SHORTCUT_SUFFIX"); + + /** The icon that will be placed after the text */ + @JvmField + val SECONDARY_ICON: Key = Key.create("SECONDARY_ICON") + + /** Same as [AlwaysVisibleActionGroup] */ + @JvmField + val ALWAYS_VISIBLE_GROUP: Key = Key.create("ALWAYS_VISIBLE_GROUP") + @JvmField val ALLOW_PlAIN_LETTER_SHORTCUTS: Key = Key.create("ALLOW_PlAIN_LETTER_SHORTCUTS") @@ -59,25 +96,27 @@ object ActionUtil { @JvmField val ALLOW_ACTION_PERFORM_WHEN_HIDDEN: Key = Key.create("ALLOW_ACTION_PERFORM_WHEN_HIDDEN") + @JvmField + @Suppress("DEPRECATION", "removal") + val SECONDARY_TEXT: Key<@Nls String> = Presentation.PROP_VALUE + + @JvmField + val SEARCH_TAG: Key<@NonNls String> = Key.create("SEARCH_TAG") + + @JvmField + val INLINE_ACTIONS: Key> = Key.create("INLINE_ACTIONS") + + // Internal keys + @JvmStatic - private val WAS_ENABLED_BEFORE_DUMB = Key.create("WAS_ENABLED_BEFORE_DUMB") + private val WAS_ENABLED_BEFORE_DUMB: Key = Key.create("WAS_ENABLED_BEFORE_DUMB") @ApiStatus.Internal @JvmField val WOULD_BE_ENABLED_IF_NOT_DUMB_MODE: Key = Key.create("WOULD_BE_ENABLED_IF_NOT_DUMB_MODE") @JvmStatic - private val WOULD_BE_VISIBLE_IF_NOT_DUMB_MODE = Key.create("WOULD_BE_VISIBLE_IF_NOT_DUMB_MODE") - - @JvmField - @Suppress("DEPRECATION", "removal") - val SECONDARY_TEXT: Key<@Nls String> = Presentation.PROP_VALUE - - @JvmField - val SEARCH_TAG: Key = Key.create<@NonNls String?>("SEARCH_TAG") - - @JvmField - val INLINE_ACTIONS: Key> = Key.create("INLINE_ACTIONS") + private val WOULD_BE_VISIBLE_IF_NOT_DUMB_MODE: Key = Key.create("WOULD_BE_VISIBLE_IF_NOT_DUMB_MODE") @JvmStatic fun showDumbModeWarning(project: Project?, diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionButton.java b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionButton.java index 71ffa773ffc0..bf0d0385f128 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionButton.java +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionButton.java @@ -52,17 +52,9 @@ public class ActionButton extends JComponent implements ActionButtonComponent, A // Contains action IDs which descriptions are permitted for displaying in the ActionButton tooltip private static final @NonNls Set WHITE_LIST = Set.of("ExternalSystem.ProjectRefreshAction", "LoadConfigurationAction"); - /** - * By default, a toolbar button for a popup action group paints additional "drop-down-arrow" mark over its icon. - * Set this key to disable the painting of that mark as follows: - *

- * {@code presentation.putClientProperty(ActionButton.HIDE_DROPDOWN_ICON, true)}. - *

- * Both ordinary and template presentations are supported. - * - * @see Presentation#setPerformGroup(boolean) - */ - public static final Key HIDE_DROPDOWN_ICON = Key.create("HIDE_DROPDOWN_ICON"); + /** @deprecated Use {@link ActionUtil#HIDE_DROPDOWN_ICON} instead */ + @Deprecated + public static final Key HIDE_DROPDOWN_ICON = ActionUtil.HIDE_DROPDOWN_ICON; public static final Key CUSTOM_HELP_TOOLTIP = Key.create("CUSTOM_HELP_TOOLTIP"); diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionMenu.kt b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionMenu.kt index 9ebbd13b0901..00ea1f880e6a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionMenu.kt +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionMenu.kt @@ -10,6 +10,7 @@ import com.intellij.internal.inspector.UiInspectorContextProvider import com.intellij.internal.inspector.UiInspectorUtil import com.intellij.openapi.Disposable import com.intellij.openapi.actionSystem.* +import com.intellij.openapi.actionSystem.ex.ActionUtil import com.intellij.openapi.actionSystem.ex.MainMenuPresentationAware import com.intellij.openapi.actionSystem.impl.ActionPresentationDecorator.decorateTextIfNeeded import com.intellij.openapi.actionSystem.impl.actionholder.createActionRef @@ -93,30 +94,21 @@ class ActionMenu constructor(private val context: DataContext?, } companion object { - /** - * By default, a "performable" non-empty popup action group menu item still shows a submenu. - * Use this key to disable the submenu and avoid children expansion on update as follows: - * - * `presentation.putClientProperty(ActionMenu.SUPPRESS_SUBMENU, true)`. - * - * Both ordinary and template presentations are supported. - * @see Presentation.setPerformGroup - */ + @Deprecated("Use ActionUtil.SUPPRESS_SUBMENU") @JvmField - val SUPPRESS_SUBMENU: Key = Key.create("SUPPRESS_SUBMENU") + val SUPPRESS_SUBMENU = ActionUtil.SUPPRESS_SUBMENU - /** - * Same as [AlwaysVisibleActionGroup] - */ + @Deprecated("Use ActionUtil.ALWAYS_VISIBLE_GROUP") @JvmField - val ALWAYS_VISIBLE: Key = Key.create("ALWAYS_VISIBLE") + val ALWAYS_VISIBLE = ActionUtil.ALWAYS_VISIBLE_GROUP + @Deprecated("Use ActionUtil.KEYBOARD_SHORTCUT_SUFFIX") @JvmField - val KEYBOARD_SHORTCUT_SUFFIX: Key<@NlsSafe String> = Key.create("keyboardShortcutTextSuffix"); + val KEYBOARD_SHORTCUT_SUFFIX = ActionUtil.KEYBOARD_SHORTCUT_SUFFIX - /** The icon that will be placed after the text */ + @Deprecated("Use ActionUtil.SECONDARY_ICON") @JvmField - val SECONDARY_ICON: Key = Key.create("SECONDARY_ICON") + val SECONDARY_ICON = ActionUtil.SECONDARY_ICON @JvmStatic fun shouldConvertIconToDarkVariant(): Boolean {