From e3d869a1f9c0d20539c080f212e159907d15b856 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 6 Oct 2009 14:38:14 +0400 Subject: [PATCH] initially select parent of existing root when attaching new root to library (IDEADEV-40691) --- .../libraryEditor/LibraryTableEditor.java | 40 ++++++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTableEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTableEditor.java index 50c8570a75..02db7efd4f 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTableEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/LibraryTableEditor.java @@ -520,13 +520,7 @@ public class LibraryTableEditor implements Disposable { for (Map.Entry 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) { -- 2.11.4.GIT