mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
initially select parent of existing root when attaching new root to library (IDEADEV-40691)
This commit is contained in:
+33
-7
@@ -520,13 +520,7 @@ public class LibraryTableEditor implements Disposable {
|
||||
for (Map.Entry<DataKey, Object> entry : myFileChooserUserData.entrySet()) {
|
||||
myDescriptor.putUserData(entry.getKey(), entry.getValue());
|
||||
}
|
||||
VirtualFile toSelect = myLastChosen;
|
||||
if (toSelect == null && Comparing.strEqual(myLibraryTableProvider.getTableLevel(), LibraryTablesRegistrar.PROJECT_LEVEL)) {
|
||||
final Project project = myProject;
|
||||
if (project != null) {
|
||||
toSelect = project.getBaseDir();
|
||||
}
|
||||
}
|
||||
VirtualFile toSelect = getFileToSelect(library);
|
||||
final VirtualFile[] attachedFiles =
|
||||
attachFiles(library, scanForActualRoots(FileChooser.chooseFiles(myPanel, myDescriptor, toSelect)), getRootType(),
|
||||
addAsJarDirectories());
|
||||
@@ -537,6 +531,38 @@ public class LibraryTableEditor implements Disposable {
|
||||
fireLibrariesChanged();
|
||||
myTree.requestFocus();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private VirtualFile getFileToSelect(Library library) {
|
||||
VirtualFile toSelect = myLastChosen;
|
||||
if (toSelect == null) {
|
||||
for (OrderRootType orderRootType : OrderRootType.getAllPersistentTypes()) {
|
||||
final VirtualFile[] existingRoots = library.getFiles(orderRootType);
|
||||
if (existingRoots.length > 0) {
|
||||
VirtualFile existingRoot = existingRoots [0];
|
||||
if (existingRoot.getFileSystem() instanceof JarFileSystem) {
|
||||
existingRoot = JarFileSystem.getInstance().getVirtualFileForJar(existingRoot);
|
||||
}
|
||||
if (existingRoot != null) {
|
||||
if (existingRoot.isDirectory()) {
|
||||
toSelect = existingRoot;
|
||||
}
|
||||
else {
|
||||
toSelect = existingRoot.getParent();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toSelect == null && Comparing.strEqual(myLibraryTableProvider.getTableLevel(), LibraryTablesRegistrar.PROJECT_LEVEL)) {
|
||||
final Project project = myProject;
|
||||
if (project != null) {
|
||||
toSelect = project.getBaseDir();
|
||||
}
|
||||
}
|
||||
return toSelect;
|
||||
}
|
||||
}
|
||||
|
||||
private VirtualFile[] attachFiles(final Library library, final VirtualFile[] files, final OrderRootType rootType, final boolean isJarDirectories) {
|
||||
|
||||
Reference in New Issue
Block a user