Commit 4e9149ac authored by tsepez@chromium.org's avatar tsepez@chromium.org

Make saving files from flash less annoying.

Resolves missing or relative suggested paths relative to the last opened directory, and when the path is a directory itself, browse files under it rather than itself under its parent.  Determining the latter takes a file system interrogation because the syntax isn't sufficient.

BUG=140799

Review URL: https://chromiumcodereview.appspot.com/10697010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151738 0039d316-1c4b-4281-b951-d872f2087c98
parent 9b8e05e6
......@@ -401,9 +401,10 @@ void FileSelectHelper::RunFileChooserOnUIThread(
dialog_type_ = ui::SelectFileDialog::SELECT_OPEN_FILE;
NOTREACHED();
}
FilePath default_file_name = params.default_file_name;
if (default_file_name.empty())
default_file_name = profile_->last_selected_directory();
FilePath default_file_name = params.default_file_name.IsAbsolute() ?
params.default_file_name :
profile_->last_selected_directory().Append(params.default_file_name);
gfx::NativeWindow owning_window =
platform_util::GetTopLevel(render_view_host_->GetView()->GetNativeView());
......
......@@ -403,10 +403,16 @@ GtkWidget* SelectFileDialogImplGTK::CreateSaveAsDialog(const std::string& title,
// Since the file may not already exist, we use
// set_current_folder() followed by set_current_name(), as per the
// recommendation of the GTK docs.
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
default_path.DirName().value().c_str());
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog),
default_path.BaseName().value().c_str());
if (CallDirectoryExistsOnUIThread(default_path)) {
gtk_file_chooser_set_current_folder(
GTK_FILE_CHOOSER(dialog), default_path.value().c_str());
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "");
} else {
gtk_file_chooser_set_current_folder(
GTK_FILE_CHOOSER(dialog), default_path.DirName().value().c_str());
gtk_file_chooser_set_current_name(
GTK_FILE_CHOOSER(dialog), default_path.BaseName().value().c_str());
}
} else if (!last_saved_path_->empty()) {
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
last_saved_path_->value().c_str());
......
......@@ -75,6 +75,13 @@ bool CallGetSaveFileName(OPENFILENAME* ofn) {
}
}
// Distinguish directories from regular files.
bool IsDirectory(const FilePath& path) {
base::PlatformFileInfo file_info;
return file_util::GetFileInfo(path, &file_info) ?
file_info.is_directory : file_util::EndsWithSeparator(path);
}
// Get the file type description from the registry. This will be "Text Document"
// for .txt files, "JPEG Image" for .jpg files, etc. If the registry doesn't
// have an entry for the file type, we return false, true if the description was
......@@ -286,8 +293,14 @@ bool SaveFileAsWithFilter(HWND owner,
// Set up the initial directory for the dialog.
std::wstring directory;
if (!suggested_name.empty())
directory = suggested_path.DirName().value();
if (!suggested_name.empty()) {
if (IsDirectory(suggested_path)) {
directory = suggested_path.value();
file_part.clear();
} else {
directory = suggested_path.DirName().value();
}
}
save_as.lpstrInitialDir = directory.c_str();
save_as.lpstrTitle = NULL;
......@@ -715,13 +728,7 @@ bool SelectFileDialogImpl::RunOpenFileDialog(
FilePath dir;
// Use lpstrInitialDir to specify the initial directory
if (!path->empty()) {
bool is_dir;
base::PlatformFileInfo file_info;
if (file_util::GetFileInfo(*path, &file_info))
is_dir = file_info.is_directory;
else
is_dir = file_util::EndsWithSeparator(*path);
if (is_dir) {
if (IsDirectory(*path)) {
ofn.lpstrInitialDir = path->value().c_str();
} else {
dir = path->DirName();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment