FileChooserDialog now supports several files
authorIlya.Kazakevich <Ilya.Kazakevich@jetbrains.com>
Tue, 2 Sep 2014 17:37:59 +0000 (21:37 +0400)
committerIlya.Kazakevich <Ilya.Kazakevich@jetbrains.com>
Tue, 2 Sep 2014 17:37:59 +0000 (21:37 +0400)
platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooserDialog.java
platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileChooserDialogImpl.java

index c12ab422a942b6a9f37d6cf1f8a97b4c2593240d..324979dff228a8c2760d7c92bf19d6a3f945fc8e 100644 (file)
@@ -23,7 +23,22 @@ import org.jetbrains.annotations.Nullable;
 
 public interface FileChooserDialog {
   DataKey<Boolean> PREFER_LAST_OVER_TO_SELECT = PathChooserDialog.PREFER_LAST_OVER_EXPLICIT;
-  
+
+  /**
+   * @deprecated Please use {@link #choose(com.intellij.openapi.project.Project, com.intellij.openapi.vfs.VirtualFile...)} because
+   * it supports several selections
+   */
+  @Deprecated
   @NotNull
   VirtualFile[] choose(@Nullable VirtualFile toSelect, @Nullable Project project);
+
+  /**
+   * Choose one or more files
+   *
+   * @param project  use this project (you may pass null if you already set project in ctor)
+   * @param toSelect files to be selected automatically.
+   * @return files chosen by user
+   */
+  @NotNull
+  VirtualFile[] choose(@Nullable Project project, @NotNull VirtualFile... toSelect);
 }
\ No newline at end of file
index d585ec5a7b7df963e8d0c4afd9837967cca8145c..d2ea19bc403def31eac23ab2258196ccd8d8069d 100644 (file)
@@ -114,16 +114,29 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD
 
   @Override
   @NotNull
-  public VirtualFile[] choose(@Nullable VirtualFile toSelect, Project project) {
+  public VirtualFile[] choose(@Nullable final Project project, @NotNull final VirtualFile... toSelect) {
     init();
-    if (myProject == null && project != null) {
+    if ((myProject == null) && (project != null)) {
       myProject = project;
     }
-    restoreSelection(toSelect);
+    if (toSelect.length == 1) {
+      restoreSelection(toSelect[0]);
+    }
+    else {
+      selectInTree(toSelect, true);
+    }
+
     show();
     return myChosenFiles;
   }
 
+
+  @NotNull
+  @Override
+  public VirtualFile[] choose(@Nullable final VirtualFile toSelect, @Nullable final Project project) {
+    return choose(project, toSelect);
+  }
+
   @Override
   public void choose(@Nullable VirtualFile toSelect, @NotNull Consumer<List<VirtualFile>> callback) {
     init();
@@ -163,7 +176,6 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD
     if (file != null && file.getFileSystem() instanceof LocalFileSystem) {
       saveRecent(file.getPath());
     }
-
   }
 
   protected void saveRecent(String path) {