mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
restore prev path in save dialog
This commit is contained in:
+11
-8
@@ -107,17 +107,20 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD
|
||||
@Override
|
||||
@NotNull
|
||||
public VirtualFile[] choose(@Nullable VirtualFile toSelect, Project project) {
|
||||
init();
|
||||
if (myProject == null && project != null) {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
prepareAndShow(toSelect);
|
||||
restoreSelection(toSelect);
|
||||
show();
|
||||
return myChosenFiles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void choose(@Nullable VirtualFile toSelect, @NotNull Consumer<List<VirtualFile>> callback) {
|
||||
prepareAndShow(toSelect);
|
||||
init();
|
||||
restoreSelection(toSelect);
|
||||
show();
|
||||
if (myChosenFiles.length > 0) {
|
||||
callback.consume(Arrays.asList(myChosenFiles));
|
||||
} else if (callback instanceof FileChooser.FileChooserConsumer){
|
||||
@@ -125,9 +128,7 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD
|
||||
}
|
||||
}
|
||||
|
||||
private void prepareAndShow(@Nullable VirtualFile toSelect) {
|
||||
init();
|
||||
|
||||
protected void restoreSelection(@Nullable VirtualFile toSelect) {
|
||||
final VirtualFile lastOpenedFile = FileChooserUtil.getLastOpenedFile(myProject);
|
||||
final VirtualFile file = FileChooserUtil.getFileToSelect(myChooserDescriptor, myProject, toSelect, lastOpenedFile);
|
||||
|
||||
@@ -146,8 +147,10 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
show();
|
||||
protected void storeSelection(@Nullable VirtualFile file) {
|
||||
FileChooserUtil.setLastOpenedFile(myProject, file);
|
||||
}
|
||||
|
||||
protected DefaultActionGroup createActionGroup() {
|
||||
@@ -295,7 +298,7 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD
|
||||
}
|
||||
|
||||
myChosenFiles = files;
|
||||
FileChooserUtil.setLastOpenedFile(myProject, files[files.length - 1]);
|
||||
storeSelection(files[files.length - 1]);
|
||||
|
||||
super.doOKAction();
|
||||
}
|
||||
|
||||
+3
-5
@@ -65,8 +65,9 @@ public class FileSaverDialogImpl extends FileChooserDialogImpl implements FileSa
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public VirtualFileWrapper save(@Nullable VirtualFile baseDir, @Nullable String filename) {
|
||||
public VirtualFileWrapper save(@Nullable VirtualFile baseDir, @Nullable final String filename) {
|
||||
init();
|
||||
restoreSelection(baseDir);
|
||||
myFileSystemTree.addListener(new FileSystemTree.Listener() {
|
||||
public void selectionChanged(final List<VirtualFile> selection) {
|
||||
updateFileName(selection);
|
||||
@@ -78,10 +79,6 @@ public class FileSaverDialogImpl extends FileChooserDialogImpl implements FileSa
|
||||
myFileName.setText(filename);
|
||||
}
|
||||
|
||||
if (baseDir != null && baseDir.isValid() && baseDir.isDirectory()) {
|
||||
myFileSystemTree.select(baseDir, null);
|
||||
}
|
||||
|
||||
show();
|
||||
|
||||
if (getExitCode() == OK_EXIT_CODE) {
|
||||
@@ -193,6 +190,7 @@ public class FileSaverDialogImpl extends FileChooserDialogImpl implements FileSa
|
||||
return;
|
||||
}
|
||||
}
|
||||
storeSelection(myFileSystemTree.getSelectedFile());
|
||||
super.doOKAction();
|
||||
}
|
||||
}
|
||||
|
||||
+9
-11
@@ -17,6 +17,7 @@ package com.intellij.openapi.fileChooser.impl;
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileSaverDescriptor;
|
||||
import com.intellij.openapi.fileChooser.PathChooserDialog;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
@@ -53,30 +54,27 @@ public final class FileChooserUtil {
|
||||
@Nullable final Project project,
|
||||
@Nullable final VirtualFile toSelect,
|
||||
@Nullable final VirtualFile lastPath) {
|
||||
boolean chooseDir = descriptor instanceof FileSaverDescriptor;
|
||||
VirtualFile result;
|
||||
if (toSelect == null && lastPath == null) {
|
||||
if (project != null) {
|
||||
final VirtualFile baseDir = project.getBaseDir();
|
||||
if (baseDir != null) {
|
||||
return baseDir;
|
||||
}
|
||||
}
|
||||
result = project == null? null : project.getBaseDir();
|
||||
}
|
||||
else if (toSelect != null && lastPath != null) {
|
||||
if (Boolean.TRUE.equals(descriptor.getUserData(PathChooserDialog.PREFER_LAST_OVER_EXPLICIT))) {
|
||||
return lastPath;
|
||||
result = lastPath;
|
||||
}
|
||||
else {
|
||||
return toSelect;
|
||||
result = toSelect;
|
||||
}
|
||||
}
|
||||
else if (toSelect == null) {
|
||||
return lastPath;
|
||||
result = lastPath;
|
||||
}
|
||||
else {
|
||||
return toSelect;
|
||||
result = toSelect;
|
||||
}
|
||||
|
||||
return null;
|
||||
return chooseDir && result != null && !result.isDirectory() ? result.getParent() : result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user