diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/PathUIUtils.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/PathUIUtils.java index f44643b92891..3bcb1c45792c 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/PathUIUtils.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/PathUIUtils.java @@ -41,7 +41,7 @@ public class PathUIUtils { /** * This method takes a candidates for the project root, then scans the candidates and - * if multiple candidates or non root source directories are found whithin some + * if multiple candidates or non root source directories are found within some * directories, it shows a dialog that allows selecting or deselecting them. * @param parent a parent parent or project * @param rootCandidates a candidates for roots @@ -50,7 +50,7 @@ public class PathUIUtils { public static VirtualFile[] scanAndSelectDetectedJavaSourceRoots(Component parentComponent, final VirtualFile[] rootCandidates) { final List orderRoots = RootDetectionUtil.detectRoots(Arrays.asList(rootCandidates), parentComponent, null, new LibraryRootsDetectorImpl(Arrays.asList(Extensions.getExtensions(RootDetector.JAVA_SOURCE_ROOT_DETECTOR))), - new OrderRootType[0]); + new OrderRootType[] {OrderRootType.SOURCES}); final List result = new ArrayList(); for (OrderRoot root : orderRoots) { result.add(root.getFile()); diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/impl/RootDetectionUtil.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/impl/RootDetectionUtil.java index c6493e7baafe..7de49054cff4 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/impl/RootDetectionUtil.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/ui/impl/RootDetectionUtil.java @@ -28,6 +28,7 @@ import com.intellij.openapi.roots.libraries.ui.DetectedLibraryRoot; import com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor; import com.intellij.openapi.roots.libraries.ui.LibraryRootsDetector; import com.intellij.openapi.roots.libraries.ui.OrderRoot; +import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -119,20 +120,37 @@ public class RootDetectionUtil { } LOG.assertTrue(!types.isEmpty(), "No allowed root types found for " + detector); List names = new ArrayList(types.keySet()); - String title = "Choose Categories of Selected Files"; - String description = XmlStringUtil.wrapInHtml(ApplicationNamesInfo.getInstance().getProductName() + " cannot determine what kind of files the chosen items contain.
" + - "Choose the appropriate categories from the list."); - ChooseElementsDialog dialog; - if (parentComponent != null) { - dialog = new ChooseRootTypeElementsDialog(parentComponent, names, title, description); + if (names.size() == 1) { + String title = "Attach Roots"; + String typeName = names.get(0); + String message = ApplicationNamesInfo.getInstance().getProductName() + " cannot determine what kind of files the chosen items contain. " + + "Do you want to attach them as '" + typeName + "'?"; + int answer = parentComponent != null + ? Messages.showYesNoDialog(parentComponent, message, title, null) + : Messages.showYesNoDialog(project, message, title, null); + if (answer == Messages.YES) { + Pair pair = types.get(typeName); + for (VirtualFile candidate : rootCandidates) { + result.add(new OrderRoot(candidate, pair.getFirst(), pair.getSecond())); + } + } } else { - dialog = new ChooseRootTypeElementsDialog(project, names, title, description); - } - for (String rootType : dialog.showAndGetResult()) { - final Pair pair = types.get(rootType); - for (VirtualFile candidate : rootCandidates) { - result.add(new OrderRoot(candidate, pair.getFirst(), pair.getSecond())); + String title = "Choose Categories of Selected Files"; + String description = XmlStringUtil.wrapInHtml(ApplicationNamesInfo.getInstance().getProductName() + " cannot determine what kind of files the chosen items contain.
" + + "Choose the appropriate categories from the list."); + ChooseElementsDialog dialog; + if (parentComponent != null) { + dialog = new ChooseRootTypeElementsDialog(parentComponent, names, title, description); + } + else { + dialog = new ChooseRootTypeElementsDialog(project, names, title, description); + } + for (String rootType : dialog.showAndGetResult()) { + final Pair pair = types.get(rootType); + for (VirtualFile candidate : rootCandidates) { + result.add(new OrderRoot(candidate, pair.getFirst(), pair.getSecond())); + } } } }