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.
This commit is contained in:
nik
2019-03-04 13:04:14 +03:00
parent 2dcd51d91e
commit 7108be979f
7 changed files with 48 additions and 6 deletions
@@ -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
@@ -35,5 +35,6 @@ public class ImportProjectAction extends ImportModuleAction {
if (NewWelcomeScreen.isNewWelcomeScreen(e)) {
e.getPresentation().setIcon(AllIcons.ToolbarDecorator.Import);
}
NewProjectAction.updatePresentationForNonJavaIdes(this, e);
}
}
@@ -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()));
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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));
}
@@ -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