From 7108be979f9936e265b3889890ffce8a50183edc Mon Sep 17 00:00:00 2001 From: nik Date: Fri, 1 Mar 2019 19:26:18 +0300 Subject: [PATCH] actions: fix presentation of Java-specific New Project/Module action in non-java IDEs Other IDEs usually have their own 'New Project' action so we should use different text for Java-specific action differently when Java support is installed via plugin (IDEA-195719). Also in some IDEs these actions aren't shown under 'New' submenu so we need to add prefix 'New ' to their texts in such cases. --- .../ide/actions/ImportModuleAction.java | 1 + .../ide/actions/ImportProjectAction.java | 1 + .../ide/actions/NewProjectAction.java | 27 +++++++++++++++++++ .../actions/NewModuleAction.java | 6 ++--- .../vcs/checkout/NewProjectFromVCSGroup.java | 8 ++++++ .../intellij/ide/actions/NewActionGroup.java | 9 ++++++- .../src/messages/ProjectBundle.properties | 2 +- 7 files changed, 48 insertions(+), 6 deletions(-) diff --git a/java/idea-ui/src/com/intellij/ide/actions/ImportModuleAction.java b/java/idea-ui/src/com/intellij/ide/actions/ImportModuleAction.java index 57600d0b998d..cabc2daadb2c 100644 --- a/java/idea-ui/src/com/intellij/ide/actions/ImportModuleAction.java +++ b/java/idea-ui/src/com/intellij/ide/actions/ImportModuleAction.java @@ -64,6 +64,7 @@ public class ImportModuleAction extends AnAction { public void update(@NotNull AnActionEvent e) { Presentation presentation = e.getPresentation(); presentation.setEnabled(getEventProject(e) != null); + NewProjectAction.updatePresentationForNonJavaIdes(this, e); } @Override diff --git a/java/idea-ui/src/com/intellij/ide/actions/ImportProjectAction.java b/java/idea-ui/src/com/intellij/ide/actions/ImportProjectAction.java index 3a615e3280b4..1c58cf200c43 100644 --- a/java/idea-ui/src/com/intellij/ide/actions/ImportProjectAction.java +++ b/java/idea-ui/src/com/intellij/ide/actions/ImportProjectAction.java @@ -35,5 +35,6 @@ public class ImportProjectAction extends ImportModuleAction { if (NewWelcomeScreen.isNewWelcomeScreen(e)) { e.getPresentation().setIcon(AllIcons.ToolbarDecorator.Import); } + NewProjectAction.updatePresentationForNonJavaIdes(this, e); } } diff --git a/java/idea-ui/src/com/intellij/ide/actions/NewProjectAction.java b/java/idea-ui/src/com/intellij/ide/actions/NewProjectAction.java index 7cc832fcaafb..4ed133326303 100644 --- a/java/idea-ui/src/com/intellij/ide/actions/NewProjectAction.java +++ b/java/idea-ui/src/com/intellij/ide/actions/NewProjectAction.java @@ -4,16 +4,23 @@ package com.intellij.ide.actions; import com.intellij.icons.AllIcons; import com.intellij.ide.impl.NewProjectUtil; import com.intellij.ide.projectWizard.NewProjectWizard; +import com.intellij.lang.IdeLanguageCustomization; +import com.intellij.lang.java.JavaLanguage; +import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ui.configuration.ModulesProvider; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.impl.welcomeScreen.NewWelcomeScreen; import org.jetbrains.annotations.NotNull; public class NewProjectAction extends AnAction implements DumbAware { + private static final Logger LOG = Logger.getInstance(NewProjectAction.class); + @Override public boolean startInTransaction() { return true; @@ -31,5 +38,25 @@ public class NewProjectAction extends AnAction implements DumbAware { if (NewWelcomeScreen.isNewWelcomeScreen(e)) { e.getPresentation().setIcon(AllIcons.Welcome.CreateNewProject); } + updatePresentationForNonJavaIdes(this, e); + } + + public static void updatePresentationForNonJavaIdes(@NotNull AnAction action, @NotNull AnActionEvent e) { + String defaultText = action.getTemplatePresentation().getText(); + LOG.assertTrue(defaultText != null); + String text = StringUtil.trimStart(defaultText, "New "); + if (!IdeLanguageCustomization.getInstance().getPrimaryIdeLanguages().contains(JavaLanguage.INSTANCE)) { + text = "Java " + text; + } + if (!isInvokedFromNewSubMenu(action, e)) { + text = "New " + text; + } + e.getPresentation().setText(text); + } + + private static boolean isInvokedFromNewSubMenu(@NotNull AnAction action, + @NotNull AnActionEvent e) { + return NewActionGroup.isActionInNewPopupMenu(action) && + (ActionPlaces.MAIN_MENU.equals(e.getPlace()) || ActionPlaces.isPopupPlace(e.getPlace())); } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/actions/NewModuleAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/actions/NewModuleAction.java index 2b9814ddfea7..556e6f1ac8c4 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/actions/NewModuleAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/actions/NewModuleAction.java @@ -1,11 +1,11 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.roots.ui.configuration.actions; +import com.intellij.ide.actions.NewProjectAction; import com.intellij.ide.projectWizard.NewProjectWizard; import com.intellij.ide.util.newProjectWizard.AbstractProjectWizard; import com.intellij.ide.util.projectWizard.ModuleBuilder; import com.intellij.ide.util.projectWizard.ProjectBuilder; -import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; @@ -84,8 +84,6 @@ public class NewModuleAction extends AnAction implements DumbAware { public void update(@NotNull AnActionEvent e) { super.update(e); e.getPresentation().setEnabled(getEventProject(e) != null); - if (ActionPlaces.MAIN_MENU.equals(e.getPlace()) || ActionPlaces.isPopupPlace(e.getPlace())) { - e.getPresentation().setText("Module..."); - } + NewProjectAction.updatePresentationForNonJavaIdes(this, e); } } diff --git a/java/idea-ui/src/com/intellij/openapi/vcs/checkout/NewProjectFromVCSGroup.java b/java/idea-ui/src/com/intellij/openapi/vcs/checkout/NewProjectFromVCSGroup.java index d4b5ebee7b26..ba04ea0cdc2a 100644 --- a/java/idea-ui/src/com/intellij/openapi/vcs/checkout/NewProjectFromVCSGroup.java +++ b/java/idea-ui/src/com/intellij/openapi/vcs/checkout/NewProjectFromVCSGroup.java @@ -15,7 +15,9 @@ */ package com.intellij.openapi.vcs.checkout; +import com.intellij.ide.actions.NewProjectAction; import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.CheckoutProvider; import com.intellij.openapi.vcs.VcsKey; @@ -55,4 +57,10 @@ public class NewProjectFromVCSGroup extends CheckoutActionGroup { } }; } + + @Override + public void update(@NotNull AnActionEvent e) { + super.update(e); + NewProjectAction.updatePresentationForNonJavaIdes(this, e); + } } diff --git a/platform/lang-impl/src/com/intellij/ide/actions/NewActionGroup.java b/platform/lang-impl/src/com/intellij/ide/actions/NewActionGroup.java index a2fddc7bde72..082b00788afe 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/NewActionGroup.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/NewActionGroup.java @@ -29,13 +29,14 @@ import java.util.function.Predicate; * @author Dmitry Avdeev */ public class NewActionGroup extends ActionGroup { + private static final String PROJECT_OR_MODULE_GROUP_ID = "NewProjectOrModuleGroup"; @NotNull @Override public AnAction[] getChildren(@Nullable AnActionEvent e) { AnAction[] actions = ((ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_WEIGHING_NEW)).getChildren(e); if (e == null || ActionPlaces.isMainMenuOrActionSearch(e.getPlace())) { - AnAction newGroup = ActionManager.getInstance().getAction("NewProjectOrModuleGroup"); + AnAction newGroup = ActionManager.getInstance().getAction(PROJECT_OR_MODULE_GROUP_ID); if (newGroup != null) { AnAction[] newProjectActions = ((ActionGroup)newGroup).getChildren(e); if (newProjectActions.length > 0) { @@ -55,6 +56,12 @@ public class NewActionGroup extends ActionGroup { ActionGroup fileGroup = (ActionGroup)actionManager.getAction(IdeActions.GROUP_FILE); if (!ActionUtil.anyActionFromGroupMatches(fileGroup, false, child -> child instanceof NewActionGroup)) return false; + AnAction newProjectOrModuleGroup = ActionManager.getInstance().getAction(PROJECT_OR_MODULE_GROUP_ID); + if (newProjectOrModuleGroup instanceof ActionGroup + && ActionUtil.anyActionFromGroupMatches((ActionGroup)newProjectOrModuleGroup, false,Predicate.isEqual(action))) { + return true; + } + ActionGroup newGroup = (ActionGroup)actionManager.getAction(IdeActions.GROUP_NEW); return ActionUtil.anyActionFromGroupMatches(newGroup, false, Predicate.isEqual(action)); } diff --git a/platform/projectModel-impl/src/messages/ProjectBundle.properties b/platform/projectModel-impl/src/messages/ProjectBundle.properties index 7bff79a5cdd9..575f660004ef 100644 --- a/platform/projectModel-impl/src/messages/ProjectBundle.properties +++ b/platform/projectModel-impl/src/messages/ProjectBundle.properties @@ -215,7 +215,7 @@ module.classpath.button.move.down=Move Down module.remove.confirmation.prompt=Remove {1, choice, 1#Module|2#Modules} {0} from the project?\nNo files will be deleted. project.remove.confirmation.prompt=Would you like to detach the {1, choice, 1#project|2#projects} {0}? module.remove.command=Detach module from project -module.new.action=New Module +module.new.action=New Module... module.new.action.description=Add new module to the project module.toggle.excluded.action=Excluded module.toggle.excluded.action.description=Include/Exclude directory from module