mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
MainMenuCollector contains user data
This commit is contained in:
@@ -341,4 +341,16 @@ public abstract class AnAction implements PossiblyDumbAware {
|
||||
void markAsGlobal() {
|
||||
myIsGlobal = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns default action text.
|
||||
* This method must be overridden in case template presentation contains user data like Project name,
|
||||
* Run Configuration name, etc
|
||||
*
|
||||
* @return action presentable text without private user data
|
||||
*/
|
||||
@Nullable
|
||||
public String getTemplateText() {
|
||||
return getTemplatePresentation().getText();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,4 +80,10 @@ public class ToolAction extends AnAction implements DumbAware {
|
||||
tool.execute(e, new HackyDataContext(context), executionId, processListener);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTemplateText() {
|
||||
return "External Tool";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,4 +411,20 @@ public class DefaultActionGroup extends ActionGroup {
|
||||
super("cannot add an action twice: " + action);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an action group with specified template text. It is necessary to redefine template text if group contains
|
||||
* user specific data such as Project name, file name, etc
|
||||
* @param templateText template text which will be used in statistics
|
||||
* @return action group
|
||||
*/
|
||||
public static DefaultActionGroup createUserDataAwareGroup(String templateText) {
|
||||
return new DefaultActionGroup() {
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTemplateText() {
|
||||
return templateText;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.BitUtil;
|
||||
import com.intellij.util.PathUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.SystemIndependent;
|
||||
|
||||
import java.awt.event.InputEvent;
|
||||
@@ -80,4 +81,10 @@ public class ReopenProjectAction extends AnAction implements DumbAware {
|
||||
}
|
||||
return myProjectName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTemplateText() {
|
||||
return "Reopen Project";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,6 +486,12 @@ public class ActionMacroManager implements PersistentStateComponent<Element>, Di
|
||||
super.update(e);
|
||||
e.getPresentation().setEnabled(!getInstance().isPlaying());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTemplateText() {
|
||||
return "Invoke Macro";
|
||||
}
|
||||
}
|
||||
|
||||
private class MyKeyPostpocessor implements IdeEventQueue.EventDispatcher {
|
||||
|
||||
+2
-15
@@ -78,7 +78,7 @@ public class MainMenuCollector implements PersistentStateComponent<MainMenuColle
|
||||
protected String getPathFromMenuSelectionManager(@NotNull AnAction action) {
|
||||
List<String> groups = Arrays.stream(MenuSelectionManager.defaultManager().getSelectedPath())
|
||||
.filter(o -> o instanceof ActionMenu)
|
||||
.map(o -> ((ActionMenu)o).getText())
|
||||
.map(o -> ((ActionMenu)o).getAnAction().getTemplateText())
|
||||
.collect(Collectors.toList());
|
||||
if (groups.size() > 0) {
|
||||
String text = getActionText(action);
|
||||
@@ -88,25 +88,12 @@ public class MainMenuCollector implements PersistentStateComponent<MainMenuColle
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final HashMap<String, String> ourBlackList = new HashMap<>();
|
||||
|
||||
static {
|
||||
ourBlackList.put("com.intellij.ide.ReopenProjectAction", "Reopen Project");
|
||||
ourBlackList.put("com.intellij.openapi.wm.impl.ProjectWindowAction", "Switch Project");
|
||||
ourBlackList.put("com.intellij.tools.ToolAction", "External Tool");
|
||||
ourBlackList.put("com.intellij.ide.actionMacro.ActionMacroManager$InvokeMacroAction", "Invoke Macro");
|
||||
}
|
||||
|
||||
private static String getActionText(@NotNull AnAction action) {
|
||||
String text = ourBlackList.get(action.getClass().getName());
|
||||
if (text != null) {
|
||||
return text;
|
||||
}
|
||||
final String actionId = ActionManager.getInstance().getId(action);
|
||||
if (StringUtil.isEmpty(actionId)) {
|
||||
return "generated.on.runtime";
|
||||
}
|
||||
return action.getTemplatePresentation().getText(); //avoid user data in Action Presentation
|
||||
return action.getTemplateText(); //avoid user data in Action Presentation
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -136,4 +136,10 @@ public class ProjectWindowAction extends ToggleAction implements DumbAware {
|
||||
+ " previous: " + myPrevious.getTemplatePresentation().getText()
|
||||
+ " next: " + myNext.getTemplatePresentation().getText();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTemplateText() {
|
||||
return "Switch Project";
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public final class AntBuildGroup extends ActionGroup implements DumbAware {
|
||||
final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(project);
|
||||
for (final AntBuildFile buildFile : antConfiguration.getBuildFileList()) {
|
||||
final String name = buildFile.getPresentableName();
|
||||
DefaultActionGroup subgroup = new DefaultActionGroup();
|
||||
DefaultActionGroup subgroup = DefaultActionGroup.createUserDataAwareGroup(getTemplateText());
|
||||
subgroup.getTemplatePresentation().setText(name, false);
|
||||
subgroup.setPopup(true);
|
||||
fillGroup(buildFile, subgroup, antConfiguration);
|
||||
@@ -106,4 +106,9 @@ public final class AntBuildGroup extends ActionGroup implements DumbAware {
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateText() {
|
||||
return "Ant Build Group";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,4 +66,9 @@ public final class TargetAction extends DumbAwareAction {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateText() {
|
||||
return "Ant Target";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user