mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
GotoActionModel: extract GroupMapping to a separate class as it's done in 251
#LLM-13353 Fixed GitOrigin-RevId: d57451a4136f898fdf284fd2298b9a3620bf2e13
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ec87e32b5c
commit
776a71065d
@@ -12482,7 +12482,7 @@ f:com.intellij.ide.util.gotoByName.GotoActionItemProvider
|
||||
- com.intellij.ide.util.gotoByName.ChooseByNameWeightedItemProvider
|
||||
- <init>(com.intellij.ide.util.gotoByName.GotoActionModel):V
|
||||
- clearIntentions():V
|
||||
- s:createActionWrapper(com.intellij.openapi.actionSystem.AnAction,com.intellij.ide.util.gotoByName.GotoActionModel$GroupMapping,com.intellij.ide.util.gotoByName.MatchMode,com.intellij.ide.util.gotoByName.GotoActionModel):com.intellij.ide.util.gotoByName.GotoActionModel$ActionWrapper
|
||||
- s:createActionWrapper(com.intellij.openapi.actionSystem.AnAction,com.intellij.ide.util.gotoByName.GroupMapping,com.intellij.ide.util.gotoByName.MatchMode,com.intellij.ide.util.gotoByName.GotoActionModel):com.intellij.ide.util.gotoByName.GotoActionModel$ActionWrapper
|
||||
- filterElements(com.intellij.ide.util.gotoByName.ChooseByNameViewModel,java.lang.String,Z,com.intellij.openapi.progress.ProgressIndicator,com.intellij.util.Processor):Z
|
||||
- filterElements(java.lang.String,java.util.function.Predicate):Z
|
||||
- filterElementsWithWeights(com.intellij.ide.util.gotoByName.ChooseByNameViewModel,java.lang.String,Z,com.intellij.openapi.progress.ProgressIndicator,com.intellij.util.Processor):Z
|
||||
@@ -12500,7 +12500,7 @@ f:com.intellij.ide.util.gotoByName.GotoActionModel
|
||||
- getElementName(java.lang.Object):java.lang.String
|
||||
- getElementsByName(java.lang.String,Z,java.lang.String):java.lang.Object[]
|
||||
- getFullName(java.lang.Object):java.lang.String
|
||||
- getGroupMapping(com.intellij.openapi.actionSystem.AnAction):com.intellij.ide.util.gotoByName.GotoActionModel$GroupMapping
|
||||
- getGroupMapping(com.intellij.openapi.actionSystem.AnAction):com.intellij.ide.util.gotoByName.GroupMapping
|
||||
- getGroupName(com.intellij.ide.ui.search.OptionDescription):java.lang.String
|
||||
- getHelpId():java.lang.String
|
||||
- getListCellRenderer():javax.swing.ListCellRenderer
|
||||
@@ -12515,12 +12515,12 @@ f:com.intellij.ide.util.gotoByName.GotoActionModel
|
||||
- useMiddleMatching():Z
|
||||
- willOpenEditor():Z
|
||||
c:com.intellij.ide.util.gotoByName.GotoActionModel$ActionWrapper
|
||||
- <init>(com.intellij.openapi.actionSystem.AnAction,com.intellij.ide.util.gotoByName.GotoActionModel$GroupMapping,com.intellij.ide.util.gotoByName.MatchMode,com.intellij.openapi.actionSystem.Presentation):V
|
||||
- <init>(com.intellij.openapi.actionSystem.AnAction,com.intellij.ide.util.gotoByName.GroupMapping,com.intellij.ide.util.gotoByName.MatchMode,com.intellij.openapi.actionSystem.Presentation):V
|
||||
- compareWeights(com.intellij.ide.util.gotoByName.GotoActionModel$ActionWrapper):I
|
||||
- equals(java.lang.Object):Z
|
||||
- getAction():com.intellij.openapi.actionSystem.AnAction
|
||||
- getActionText():java.lang.String
|
||||
- getGroupMapping():com.intellij.ide.util.gotoByName.GotoActionModel$GroupMapping
|
||||
- getGroupMapping():com.intellij.ide.util.gotoByName.GroupMapping
|
||||
- getGroupName():java.lang.String
|
||||
- getMode():com.intellij.ide.util.gotoByName.MatchMode
|
||||
- getPresentation():com.intellij.openapi.actionSystem.Presentation
|
||||
@@ -12534,16 +12534,6 @@ f:com.intellij.ide.util.gotoByName.GotoActionModel$GotoActionListCellRenderer
|
||||
- <init>(com.intellij.util.Function,Z):V
|
||||
- s:calcHit(com.intellij.ide.ui.search.OptionDescription):java.lang.String
|
||||
- getListCellRendererComponent(javax.swing.JList,java.lang.Object,I,Z,Z):java.awt.Component
|
||||
f:com.intellij.ide.util.gotoByName.GotoActionModel$GroupMapping
|
||||
- java.lang.Comparable
|
||||
- <init>():V
|
||||
- <init>(Z):V
|
||||
- compareTo(com.intellij.ide.util.gotoByName.GotoActionModel$GroupMapping):I
|
||||
- s:createFromText(java.lang.String,Z):com.intellij.ide.util.gotoByName.GotoActionModel$GroupMapping
|
||||
- getAllGroupNames():java.util.List
|
||||
- getBestGroupName():java.lang.String
|
||||
- getFirstGroup():java.util.List
|
||||
- updateBeforeShow(com.intellij.openapi.actionSystem.UpdateSession):V
|
||||
c:com.intellij.ide.util.gotoByName.GotoActionModel$MatchedValue
|
||||
- com.intellij.ide.actions.searcheverywhere.MergeableElement
|
||||
- com.intellij.internal.inspector.UiInspectorContextProvider
|
||||
@@ -12654,6 +12644,16 @@ c:com.intellij.ide.util.gotoByName.GotoSymbolModel2
|
||||
- loadInitialCheckBoxState():Z
|
||||
- saveInitialCheckBoxState(Z):V
|
||||
- willOpenEditor():Z
|
||||
f:com.intellij.ide.util.gotoByName.GroupMapping
|
||||
- java.lang.Comparable
|
||||
- <init>():V
|
||||
- <init>(Z):V
|
||||
- compareTo(com.intellij.ide.util.gotoByName.GroupMapping):I
|
||||
- s:createFromText(java.lang.String,Z):com.intellij.ide.util.gotoByName.GroupMapping
|
||||
- getAllGroupNames():java.util.List
|
||||
- getBestGroupName():java.lang.String
|
||||
- getFirstGroup():java.util.List
|
||||
- updateBeforeShow(com.intellij.openapi.actionSystem.UpdateSession):V
|
||||
f:com.intellij.ide.util.gotoByName.LanguageRef
|
||||
- sf:Companion:com.intellij.ide.util.gotoByName.LanguageRef$Companion
|
||||
- <init>(java.lang.String,java.lang.String,javax.swing.Icon):V
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
package com.intellij.ide.util.gotoByName;
|
||||
|
||||
@@ -55,16 +55,13 @@ import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import java.awt.*;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class GotoActionModel implements ChooseByNameModel, Comparator<Object>, DumbAware {
|
||||
private static final Logger LOG = Logger.getInstance(GotoActionModel.class);
|
||||
private static final Pattern INNER_GROUP_WITH_IDS = Pattern.compile("(.*) \\(\\d+\\)");
|
||||
private static final Icon EMPTY_ICON = EmptyIcon.ICON_16;
|
||||
|
||||
private final @Nullable Project myProject;
|
||||
@@ -519,109 +516,6 @@ public final class GotoActionModel implements ChooseByNameModel, Comparator<Obje
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final class GroupMapping implements Comparable<GroupMapping> {
|
||||
private final boolean myShowNonPopupGroups;
|
||||
private final List<List<ActionGroup>> myPaths = new ArrayList<>();
|
||||
|
||||
private @Nullable @ActionText String myBestGroupName;
|
||||
private boolean myBestNameComputed;
|
||||
|
||||
public GroupMapping() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public GroupMapping(boolean showNonPopupGroups) {
|
||||
myShowNonPopupGroups = showNonPopupGroups;
|
||||
}
|
||||
|
||||
public static @NotNull GroupMapping createFromText(@ActionText String text, boolean showGroupText) {
|
||||
GroupMapping mapping = new GroupMapping(showGroupText);
|
||||
mapping.addPath(Collections.singletonList(new DefaultActionGroup(text, false)));
|
||||
return mapping;
|
||||
}
|
||||
|
||||
private void addPath(@NotNull List<ActionGroup> path) {
|
||||
myPaths.add(path);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull GroupMapping o) {
|
||||
return Comparing.compare(getFirstGroupName(), o.getFirstGroupName());
|
||||
}
|
||||
|
||||
public @ActionText @Nullable String getBestGroupName() {
|
||||
if (myBestNameComputed) return myBestGroupName;
|
||||
return getFirstGroupName();
|
||||
}
|
||||
|
||||
public @Nullable List<ActionGroup> getFirstGroup() {
|
||||
return ContainerUtil.getFirstItem(myPaths);
|
||||
}
|
||||
|
||||
private @Nls @Nullable String getFirstGroupName() {
|
||||
List<ActionGroup> path = getFirstGroup();
|
||||
return path != null ? getPathName(path) : null;
|
||||
}
|
||||
|
||||
public void updateBeforeShow(@NotNull UpdateSession session) {
|
||||
if (myBestNameComputed) return;
|
||||
myBestNameComputed = true;
|
||||
|
||||
for (List<ActionGroup> path : myPaths) {
|
||||
String name = getActualPathName(path, session);
|
||||
if (name != null) {
|
||||
myBestGroupName = name;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public @NotNull List<String> getAllGroupNames() {
|
||||
return ContainerUtil.map(myPaths, path -> getPathName(path));
|
||||
}
|
||||
|
||||
private @Nls @Nullable String getPathName(@NotNull List<? extends ActionGroup> path) {
|
||||
String name = "";
|
||||
for (ActionGroup group : path) {
|
||||
name = appendGroupName(name, group, group.getTemplatePresentation());
|
||||
}
|
||||
return StringUtil.nullize(name);
|
||||
}
|
||||
|
||||
private @Nls @Nullable String getActualPathName(@NotNull List<? extends ActionGroup> path, @NotNull UpdateSession session) {
|
||||
String name = "";
|
||||
for (ActionGroup group : path) {
|
||||
Presentation presentation = session.presentation(group);
|
||||
if (!presentation.isVisible()) return null;
|
||||
name = appendGroupName(name, group, presentation);
|
||||
}
|
||||
return StringUtil.nullize(name);
|
||||
}
|
||||
|
||||
private @Nls @NotNull String appendGroupName(@NotNull @Nls String prefix, @NotNull ActionGroup group, @NotNull Presentation presentation) {
|
||||
if (group.isPopup() || myShowNonPopupGroups) {
|
||||
String groupName = getActionGroupName(presentation);
|
||||
if (!StringUtil.isEmptyOrSpaces(groupName)) {
|
||||
return prefix.isEmpty()
|
||||
? groupName
|
||||
: prefix + " | " + groupName;
|
||||
}
|
||||
}
|
||||
return prefix;
|
||||
}
|
||||
|
||||
private static @ActionText @Nullable String getActionGroupName(@NotNull Presentation presentation) {
|
||||
String text = presentation.getText();
|
||||
if (text == null) return null;
|
||||
|
||||
Matcher matcher = INNER_GROUP_WITH_IDS.matcher(text);
|
||||
if (matcher.matches()) return matcher.group(1);
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ActionWrapper {
|
||||
private final @NotNull AnAction myAction;
|
||||
private final @NotNull MatchMode myMode;
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.ide.util.gotoByName;
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionGroup;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.actionSystem.UpdateSession;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.NlsActions;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class GroupMapping implements Comparable<GroupMapping> {
|
||||
private static final Pattern INNER_GROUP_WITH_IDS = Pattern.compile("(.*) \\(\\d+\\)");
|
||||
|
||||
private final boolean myShowNonPopupGroups;
|
||||
private final List<List<ActionGroup>> myPaths = new ArrayList<>();
|
||||
|
||||
private @Nullable @NlsActions.ActionText String myBestGroupName;
|
||||
private boolean myBestNameComputed;
|
||||
|
||||
public GroupMapping() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public GroupMapping(boolean showNonPopupGroups) {
|
||||
myShowNonPopupGroups = showNonPopupGroups;
|
||||
}
|
||||
|
||||
public static @NotNull GroupMapping createFromText(@NlsActions.ActionText String text, boolean showGroupText) {
|
||||
GroupMapping mapping = new GroupMapping(showGroupText);
|
||||
mapping.addPath(Collections.singletonList(new DefaultActionGroup(text, false)));
|
||||
return mapping;
|
||||
}
|
||||
|
||||
void addPath(@NotNull List<ActionGroup> path) {
|
||||
myPaths.add(path);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull GroupMapping o) {
|
||||
return Comparing.compare(getFirstGroupName(), o.getFirstGroupName());
|
||||
}
|
||||
|
||||
public @NlsActions.ActionText @Nullable String getBestGroupName() {
|
||||
if (myBestNameComputed) return myBestGroupName;
|
||||
return getFirstGroupName();
|
||||
}
|
||||
|
||||
public @Nullable List<ActionGroup> getFirstGroup() {
|
||||
return ContainerUtil.getFirstItem(myPaths);
|
||||
}
|
||||
|
||||
private @Nls @Nullable String getFirstGroupName() {
|
||||
List<ActionGroup> path = getFirstGroup();
|
||||
return path != null ? getPathName(path) : null;
|
||||
}
|
||||
|
||||
public void updateBeforeShow(@NotNull UpdateSession session) {
|
||||
if (myBestNameComputed) return;
|
||||
myBestNameComputed = true;
|
||||
|
||||
for (List<ActionGroup> path : myPaths) {
|
||||
String name = getActualPathName(path, session);
|
||||
if (name != null) {
|
||||
myBestGroupName = name;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public @NotNull List<String> getAllGroupNames() {
|
||||
return ContainerUtil.map(myPaths, path -> getPathName(path));
|
||||
}
|
||||
|
||||
private @Nls @Nullable String getPathName(@NotNull List<? extends ActionGroup> path) {
|
||||
String name = "";
|
||||
for (ActionGroup group : path) {
|
||||
name = appendGroupName(name, group, group.getTemplatePresentation());
|
||||
}
|
||||
return StringUtil.nullize(name);
|
||||
}
|
||||
|
||||
private @Nls @Nullable String getActualPathName(@NotNull List<? extends ActionGroup> path, @NotNull UpdateSession session) {
|
||||
String name = "";
|
||||
for (ActionGroup group : path) {
|
||||
Presentation presentation = session.presentation(group);
|
||||
if (!presentation.isVisible()) return null;
|
||||
name = appendGroupName(name, group, presentation);
|
||||
}
|
||||
return StringUtil.nullize(name);
|
||||
}
|
||||
|
||||
private @Nls @NotNull String appendGroupName(@NotNull @Nls String prefix, @NotNull ActionGroup group, @NotNull Presentation presentation) {
|
||||
if (group.isPopup() || myShowNonPopupGroups) {
|
||||
String groupName = getActionGroupName(presentation);
|
||||
if (!StringUtil.isEmptyOrSpaces(groupName)) {
|
||||
return prefix.isEmpty()
|
||||
? groupName
|
||||
: prefix + " | " + groupName;
|
||||
}
|
||||
}
|
||||
return prefix;
|
||||
}
|
||||
|
||||
private static @NlsActions.ActionText @Nullable String getActionGroupName(@NotNull Presentation presentation) {
|
||||
String text = presentation.getText();
|
||||
if (text == null) return null;
|
||||
|
||||
Matcher matcher = INNER_GROUP_WITH_IDS.matcher(text);
|
||||
if (matcher.matches()) return matcher.group(1);
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user