IDEA-339585 Proper Reveal/Open In action name shortening

The problem: the action text for Reveal/Open In actions
is customized based on the action place. For RevealFileAction
it's done in the code (because it needs to figure out the file manager
name on Linux), for other actions it's done using text override
in XML. However, in practice shortened names make sense only
if the actions are located in the Reveal/Open In submenu.
If the action is in some other place of the same popup menu,
then the full name should be used ("Finder" doesn't make sense
if it's not located under "Reveal In").

The solution: do not rely on the action place in the action event.
Instead, customize RevealGroup so that it performs post-processing
of its children's presentations using the "correct" place, which is
a new string constant in ActionPlaces just for this group.
This approach allows to use the XML text override mechanism by
specifying this new place instead of listing all popups containing
the reveal in group.

For RevealFileAction, because the customization is performed
in the code, we have to override applyTextOverride. It's a big ugly,
but the alternative, to call addTextOverride() somewhere once,
isn't very elegant either because there doesn't seem to be a good
place to call it.

GitOrigin-RevId: 5c9e9a81bec1a29dcca29532208a930f16cd75d9
This commit is contained in:
Sergei Tachenov
2023-12-06 15:19:51 +02:00
committed by intellij-monorepo-bot
parent ba07117b33
commit 7b19a2dd37
9 changed files with 48 additions and 17 deletions

View File

@@ -56,6 +56,8 @@ public abstract class ActionPlaces {
public static final String PROJECT_VIEW_POPUP = "ProjectViewPopup";
public static final String PROJECT_VIEW_TOOLBAR = "ProjectViewToolbar";
public static final String REVEAL_IN_POPUP = "RevealInPopup";
/** @deprecated replaced by {@link #BOOKMARKS_VIEW_POPUP} */
@Deprecated(forRemoval = true)
public static final String FAVORITES_VIEW_POPUP = "FavoritesPopup";
@@ -251,7 +253,8 @@ public abstract class ActionPlaces {
RUN_ANYTHING_POPUP, RUN_TOOLBAR_LEFT_SIDE,
VCS_LOG_TABLE_PLACE, VCS_HISTORY_PLACE, VCS_LOG_TOOLBAR_POPUP_PLACE, VCS_LOG_BRANCHES_PLACE, VCS_TOOLBAR_WIDGET,
PROJECT_WIDGET_POPUP,
JUPYTER_NOTEBOOK_CELL_OUTPUT_POPUP
JUPYTER_NOTEBOOK_CELL_OUTPUT_POPUP,
REVEAL_IN_POPUP
);
private static final String POPUP_PREFIX = "popup@";

View File

@@ -4,6 +4,8 @@ package com.intellij.openapi.actionSystem;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class ActionGroupWrapper extends ActionGroup implements ActionWithDelegate<ActionGroup>, PerformWithDocumentsCommitted {
private final ActionGroup myDelegate;
@@ -81,5 +83,11 @@ public class ActionGroupWrapper extends ActionGroup implements ActionWithDelegat
public boolean disableIfNoVisibleChildren() {
return myDelegate.disableIfNoVisibleChildren();
}
@Override
public @NotNull List<AnAction> postProcessVisibleChildren(@NotNull List<? extends AnAction> visibleChildren,
@NotNull UpdateSession updateSession) {
return myDelegate.postProcessVisibleChildren(visibleChildren, updateSession);
}
}

View File

@@ -11,10 +11,7 @@ import com.intellij.idea.ActionsBundle;
import com.intellij.jna.JnaLoader;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationListener;
import com.intellij.openapi.actionSystem.ActionPlaces;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.remoting.ActionRemoteBehaviorSpecification;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
@@ -122,7 +119,7 @@ public class RevealFileAction extends DumbAwareAction implements LightEditCompat
}
public static @ActionText @NotNull String getActionName(@Nullable String place) {
var shortName = ActionPlaces.EDITOR_TAB_POPUP.equals(place) || ActionPlaces.EDITOR_POPUP.equals(place) || ActionPlaces.PROJECT_VIEW_POPUP.equals(place);
var shortName = ActionPlaces.REVEAL_IN_POPUP.equals(place);
return shortName ? getFileManagerName() : getActionName(false);
}
@@ -130,6 +127,16 @@ public class RevealFileAction extends DumbAwareAction implements LightEditCompat
return SystemInfo.isMac ? ActionsBundle.message("action.RevealIn.name.mac") : ActionsBundle.message("action.RevealIn.name.other", getFileManagerName(skipDetection));
}
@Override
public void applyTextOverride(@NotNull String place, @NotNull Presentation presentation) {
if (ActionPlaces.REVEAL_IN_POPUP.equals(place)) {
presentation.setText(getActionName(place));
}
else {
super.applyTextOverride(place, presentation);
}
}
public static @NotNull @ActionText String getFileManagerName() {
return getFileManagerName(false);
}

View File

@@ -0,0 +1,19 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide.actions
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.actionSystem.UpdateSession
import com.intellij.openapi.project.DumbAware
class RevealGroup : DefaultActionGroup(), DumbAware {
override fun postProcessVisibleChildren(visibleChildren: MutableList<out AnAction>, updateSession: UpdateSession): List<AnAction> =
visibleChildren.map { child ->
child.apply {
applyTextOverride(ActionPlaces.REVEAL_IN_POPUP, updateSession.presentation(child))
}
}
}

View File

@@ -2697,7 +2697,7 @@ action.ActivateDebugToolWindow.text=Debug
action.ActivateHierarchyToolWindow.text=Hierarchy
group.RunContextGroupMore.text=More Run/Debug
group.RevealGroup.text=Open In
group.OpenInBrowserGroup.EditorTabPopup.text=Browser
group.OpenInBrowserGroup.RevealInPopup.text=Browser
action.ResetWindowsDefenderNotification.text=Reset Microsoft Defender Notification
action.FindSelectionInPath.text=Find in Files

View File

@@ -36,10 +36,7 @@
<group id="OpenInBrowserGroup" class="com.intellij.ide.browsers.actions.OpenInBrowserBaseGroupAction$OpenInBrowserGroupAction">
<add-to-group group-id="ViewMenu" anchor="after" relative-to-action="ViewSource"/>
<add-to-group group-id="RevealGroup" anchor="last"/>
<override-text place="EditorTabPopup"/>
<override-text place="ProjectViewPopup" use-text-of-place="EditorTabPopup"/>
<override-text place="EditorPopup" use-text-of-place="EditorTabPopup"/>
<override-text place="FavoritesPopup" use-text-of-place="EditorTabPopup"/>
<override-text place="RevealInPopup"/>
</group>
<group id="OpenInBrowserEditorContextBarGroupAction"
class="com.intellij.ide.browsers.actions.OpenInBrowserBaseGroupAction$OpenInBrowserEditorContextBarGroupAction">

View File

@@ -757,7 +757,7 @@
<add-to-group group-id="RunContextPopupGroup" anchor="after" relative-to-action="OpenInRightSplit"/>
</reference>
<group id="RevealGroup" popup="true">
<group id="RevealGroup" popup="true" class="com.intellij.ide.actions.RevealGroup">
<action id="RevealIn" class="com.intellij.ide.actions.RevealFileAction"/>
<reference ref="ShowFilePath"/>

View File

@@ -24,10 +24,7 @@
<action id="Terminal.OpenInTerminal" class="org.jetbrains.plugins.terminal.action.RevealFileInTerminalAction"
icon="org.jetbrains.plugins.terminal.TerminalIcons.OpenTerminal_13x13">
<add-to-group group-id="RevealGroup" anchor="last"/>
<override-text place="EditorTabPopup"/>
<override-text place="ProjectViewPopup" use-text-of-place="EditorTabPopup"/>
<override-text place="EditorPopup" use-text-of-place="EditorTabPopup"/>
<override-text place="FavoritesPopup" use-text-of-place="EditorTabPopup"/>
<override-text place="RevealInPopup"/>
<add-to-group group-id="TouchBarDefault_alt" anchor="last"/>
</action>
<action id="Terminal.CloseTab" class="com.intellij.openapi.actionSystem.EmptyAction" use-shortcut-of="CloseContent"/>

View File

@@ -7,7 +7,7 @@ action.Terminal.MoveToolWindowTabLeft.text=Move Tab Left
action.Terminal.MoveToEditor.text=Move to Editor
action.Terminal.RenameSession.text=Rename Session
action.Terminal.OpenInTerminal.text=Open in Terminal
action.Terminal.OpenInTerminal.EditorTabPopup.text=Terminal
action.Terminal.OpenInTerminal.RevealInPopup.text=Terminal
action.Terminal.OpenInTerminal.description=Open current file location in terminal
action.Terminal.CopySelectedText.text=Copy
action.Terminal.CopySelectedText.description=Copy selected text to clipboard