attach sources to library: allow to add the chosen files as is if no sources are detected inside (KT-8592)

This commit is contained in:
nik
2016-03-01 16:28:43 +03:00
parent 4e6ba902c2
commit 2145921fb1
2 changed files with 32 additions and 14 deletions
@@ -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<OrderRoot> 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<VirtualFile> result = new ArrayList<VirtualFile>();
for (OrderRoot root : orderRoots) {
result.add(root.getFile());
@@ -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<String> names = new ArrayList<String>(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.<br>" +
"Choose the appropriate categories from the list.");
ChooseElementsDialog<String> 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<OrderRootType, Boolean> 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<OrderRootType, Boolean> 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.<br>" +
"Choose the appropriate categories from the list.");
ChooseElementsDialog<String> 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<OrderRootType, Boolean> pair = types.get(rootType);
for (VirtualFile candidate : rootCandidates) {
result.add(new OrderRoot(candidate, pair.getFirst(), pair.getSecond()));
}
}
}
}