FileChooserDialog now supports several files

This commit is contained in:
Ilya.Kazakevich
2014-09-02 21:37:59 +04:00
parent e9b3a836dc
commit ffcf1d381e
2 changed files with 32 additions and 5 deletions
@@ -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);
}
@@ -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) {