mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
correctly identify context module for modules with multiple content roots (IDEA-291030)
GitOrigin-RevId: e74f1f936b229d6fa90985a68361106139a98e74
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3df18ccdc6
commit
7c3792118d
@@ -4,8 +4,8 @@ package com.intellij.compiler.actions;
|
||||
import com.intellij.compiler.CompilerConfiguration;
|
||||
import com.intellij.idea.ActionsBundle;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.compiler.JavaCompilerBundle;
|
||||
import com.intellij.openapi.compiler.CompilerManager;
|
||||
import com.intellij.openapi.compiler.JavaCompilerBundle;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -24,21 +24,21 @@ import java.util.List;
|
||||
|
||||
public class CompileAction extends CompileActionBase {
|
||||
|
||||
private final boolean isForFiles;
|
||||
private final String bundleKey;
|
||||
private final boolean myIsForFiles;
|
||||
private final String myBundleKey;
|
||||
|
||||
public CompileAction() {
|
||||
this(false, IdeActions.ACTION_COMPILE);
|
||||
}
|
||||
|
||||
protected CompileAction(boolean forFiles, String key) {
|
||||
isForFiles = forFiles;
|
||||
bundleKey = key;
|
||||
myIsForFiles = forFiles;
|
||||
myBundleKey = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doAction(DataContext dataContext, Project project) {
|
||||
final Module module = dataContext.getData(LangDataKeys.MODULE_CONTEXT);
|
||||
Module module = dataContext.getData(LangDataKeys.MODULE_CONTEXT);
|
||||
if (module != null) {
|
||||
ProjectTaskManager.getInstance(project).rebuild(module);
|
||||
}
|
||||
@@ -47,8 +47,13 @@ public class CompileAction extends CompileActionBase {
|
||||
if (files.length > 0) {
|
||||
ProjectTaskManager.getInstance(project).compile(files);
|
||||
}
|
||||
else {
|
||||
module = dataContext.getData(PlatformCoreDataKeys.MODULE); // fallback to any module available from the context
|
||||
if (module != null) {
|
||||
ProjectTaskManager.getInstance(project).rebuild(module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,7 +64,7 @@ public class CompileAction extends CompileActionBase {
|
||||
return;
|
||||
}
|
||||
|
||||
presentation.setText(ActionsBundle.actionText(bundleKey));
|
||||
presentation.setText(ActionsBundle.actionText(myBundleKey));
|
||||
presentation.setVisible(true);
|
||||
|
||||
Project project = e.getProject();
|
||||
@@ -68,11 +73,18 @@ public class CompileAction extends CompileActionBase {
|
||||
return;
|
||||
}
|
||||
|
||||
CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(project);
|
||||
final Module module = e.getData(LangDataKeys.MODULE_CONTEXT);
|
||||
boolean forFiles = false;
|
||||
|
||||
final VirtualFile[] files = getCompilableFiles(project, e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY));
|
||||
Module module = e.getData(LangDataKeys.MODULE_CONTEXT);
|
||||
final VirtualFile[] files;
|
||||
if (module != null) {
|
||||
files = VirtualFile.EMPTY_ARRAY;
|
||||
}
|
||||
else {
|
||||
files = getCompilableFiles(project, e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY));
|
||||
if (files.length == 0) {
|
||||
module = e.getData(PlatformCoreDataKeys.MODULE); // fallback to any module available from the context
|
||||
}
|
||||
}
|
||||
if (module == null && files.length == 0) {
|
||||
presentation.setEnabled(false);
|
||||
presentation.setVisible(!ActionPlaces.isPopupPlace(e.getPlace()));
|
||||
@@ -109,8 +121,7 @@ public class CompileAction extends CompileActionBase {
|
||||
forFiles = true;
|
||||
final VirtualFile file = files[0];
|
||||
FileType fileType = file.getFileType();
|
||||
if (CompilerManager.getInstance(project).isCompilableFileType(fileType) ||
|
||||
compilerConfiguration.isCompilableResourceFile(project, file)) {
|
||||
if (CompilerManager.getInstance(project).isCompilableFileType(fileType) || CompilerConfiguration.getInstance(project).isCompilableResourceFile(project, file)) {
|
||||
elementDescription = "'" + file.getName() + "'";
|
||||
}
|
||||
else {
|
||||
@@ -133,12 +144,12 @@ public class CompileAction extends CompileActionBase {
|
||||
}
|
||||
|
||||
presentation.setText(createPresentationText(elementDescription), true);
|
||||
presentation.setEnabledAndVisible(forFiles == isForFiles);
|
||||
presentation.setEnabledAndVisible(forFiles == myIsForFiles);
|
||||
}
|
||||
|
||||
private @NlsSafe String createPresentationText(String elementDescription) {
|
||||
StringBuilder buffer = new StringBuilder(40);
|
||||
buffer.append(ActionsBundle.actionText(bundleKey)).append(" ");
|
||||
buffer.append(ActionsBundle.actionText(myBundleKey)).append(" ");
|
||||
int length = elementDescription.length();
|
||||
if (length > 50) {
|
||||
if (StringUtil.startsWithChar(elementDescription, '\'')) {
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.compiler.actions;
|
||||
|
||||
import com.intellij.ide.impl.DataValidators;
|
||||
import com.intellij.ide.nls.NlsMessages;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.compiler.JavaCompilerBundle;
|
||||
@@ -33,17 +32,17 @@ public class MakeModuleAction extends CompileActionBase {
|
||||
|
||||
@Override
|
||||
protected void doAction(DataContext dataContext, Project project) {
|
||||
Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
|
||||
Module module;
|
||||
if (modules == null) {
|
||||
module = PlatformCoreDataKeys.MODULE.getData(dataContext);
|
||||
if (module == null) {
|
||||
return;
|
||||
}
|
||||
modules = new Module[]{module};
|
||||
}
|
||||
try {
|
||||
ProjectTaskManager.getInstance(project).build(modules);
|
||||
final Module[] modules = dataContext.getData(LangDataKeys.MODULE_CONTEXT_ARRAY);
|
||||
if (modules != null) {
|
||||
ProjectTaskManager.getInstance(project).build(modules);
|
||||
}
|
||||
else {
|
||||
final Module module = dataContext.getData(PlatformCoreDataKeys.MODULE);
|
||||
if (module != null) {
|
||||
ProjectTaskManager.getInstance(project).build(module);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error(e);
|
||||
@@ -57,35 +56,37 @@ public class MakeModuleAction extends CompileActionBase {
|
||||
if (!presentation.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
final DataContext dataContext = event.getDataContext();
|
||||
final Module module = PlatformCoreDataKeys.MODULE.getData(dataContext);
|
||||
Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
|
||||
final boolean isEnabled = module != null || modules != null;
|
||||
presentation.setEnabled(isEnabled);
|
||||
final String actionName = getTemplatePresentation().getTextWithMnemonic();
|
||||
|
||||
boolean isEnabled = false;
|
||||
String presentationText;
|
||||
final Module[] modules = event.getData(LangDataKeys.MODULE_CONTEXT_ARRAY);
|
||||
if (modules != null) {
|
||||
isEnabled = true;
|
||||
if (ArrayUtil.contains(null, modules)) {
|
||||
LOG.error("Unexpected null module slipped through validator; dataContext = " + dataContext +
|
||||
"; class = "+dataContext.getClass().getName());
|
||||
final DataContext dataContext = event.getDataContext();
|
||||
LOG.error("Unexpected null module slipped through validator; dataContext = " + dataContext + "; class = "+dataContext.getClass().getName());
|
||||
}
|
||||
if (modules.length == 1) {
|
||||
presentationText = JavaCompilerBundle.message("action.make.single.module.text", modules[0].getName());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
String moduleNames = Stream.of(modules).map(m -> "'"+m.getName()+"'").collect(NlsMessages.joiningNarrowAnd());
|
||||
presentationText = moduleNames.length() > 20 ?
|
||||
JavaCompilerBundle.message("action.make.selected.modules.text") :
|
||||
JavaCompilerBundle.message("action.make.few.modules.text", moduleNames);
|
||||
}
|
||||
}
|
||||
else if (module != null) {
|
||||
presentationText = JavaCompilerBundle.message("action.make.single.module.text", module.getName());
|
||||
}
|
||||
else {
|
||||
presentationText = actionName;
|
||||
final Module module = event.getData(PlatformCoreDataKeys.MODULE);
|
||||
if (module != null) {
|
||||
isEnabled = true;
|
||||
presentationText = JavaCompilerBundle.message("action.make.single.module.text", module.getName());
|
||||
}
|
||||
else {
|
||||
presentationText = getTemplatePresentation().getTextWithMnemonic();
|
||||
}
|
||||
}
|
||||
presentation.setText(presentationText);
|
||||
presentation.setEnabled(isEnabled);
|
||||
presentation.setVisible(isEnabled || !ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user