summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-14 22:50:42 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-14 22:50:42 +0000
commit592036b2cb131f7f432cbe0363d887feb3a208d4 (patch)
treef95afb2c5cde0d185c35a5e3fd4e75c0b50fecd2 /chrome/browser/gtk
parent86fe753f644eb0da945796b9a10169b970d5f753 (diff)
downloadchromium_src-592036b2cb131f7f432cbe0363d887feb3a208d4.zip
chromium_src-592036b2cb131f7f432cbe0363d887feb3a208d4.tar.gz
chromium_src-592036b2cb131f7f432cbe0363d887feb3a208d4.tar.bz2
GTK: Change file chooser dialogs to prefer the suggested path (somewhatly erroneously known as "default_path") over the last selected path.
Also respect default_path for file save dialogs. This fixes a DCHECK we could hit from <upload> elements (as it turns out, there was no Release-mode crash). BUG=19267 Review URL: http://codereview.chromium.org/170014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23485 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r--chrome/browser/gtk/dialogs_gtk.cc46
1 files changed, 28 insertions, 18 deletions
diff --git a/chrome/browser/gtk/dialogs_gtk.cc b/chrome/browser/gtk/dialogs_gtk.cc
index c3f8bf7..7475e12 100644
--- a/chrome/browser/gtk/dialogs_gtk.cc
+++ b/chrome/browser/gtk/dialogs_gtk.cc
@@ -64,10 +64,10 @@ class SelectFileDialogImpl : public SelectFileDialog {
void FileNotSelected(GtkWidget* dialog);
GtkWidget* CreateFileOpenDialog(const std::string& title,
- gfx::NativeWindow parent);
+ const FilePath& default_path, gfx::NativeWindow parent);
GtkWidget* CreateMultiFileOpenDialog(const std::string& title,
- gfx::NativeWindow parent);
+ const FilePath& default_path, gfx::NativeWindow parent);
GtkWidget* CreateSaveAsDialog(const std::string& title,
const FilePath& default_path, gfx::NativeWindow parent);
@@ -183,12 +183,11 @@ void SelectFileDialogImpl::SelectFile(
GtkWidget* dialog = NULL;
switch (type) {
case SELECT_OPEN_FILE:
- DCHECK(default_path.empty());
- dialog = CreateFileOpenDialog(title_string, owning_window);
+ dialog = CreateFileOpenDialog(title_string, default_path, owning_window);
break;
case SELECT_OPEN_MULTI_FILE:
- DCHECK(default_path.empty());
- dialog = CreateMultiFileOpenDialog(title_string, owning_window);
+ dialog = CreateMultiFileOpenDialog(title_string, default_path,
+ owning_window);
break;
case SELECT_SAVEAS_FILE:
dialog = CreateSaveAsDialog(title_string, default_path, owning_window);
@@ -302,11 +301,10 @@ void SelectFileDialogImpl::FileNotSelected(GtkWidget* dialog) {
}
GtkWidget* SelectFileDialogImpl::CreateFileOpenDialog(const std::string& title,
- gfx::NativeWindow parent) {
+ const FilePath& default_path, gfx::NativeWindow parent) {
std::string title_string = !title.empty() ? title :
l10n_util::GetStringUTF8(IDS_OPEN_FILE_DIALOG_TITLE);
- // TODO(estade): do we want to set the open directory to some sort of default?
GtkWidget* dialog =
gtk_file_chooser_dialog_new(title_string.c_str(), parent,
GTK_FILE_CHOOSER_ACTION_OPEN,
@@ -315,7 +313,12 @@ GtkWidget* SelectFileDialogImpl::CreateFileOpenDialog(const std::string& title,
NULL);
AddFilters(GTK_FILE_CHOOSER(dialog));
- if (!last_opened_path_->empty()) {
+ if (!default_path.empty()) {
+ // If the file doesn't exist, this will just switch to the correct
+ // directory. That's good enough.
+ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),
+ default_path.value().c_str());
+ } else if (!last_opened_path_->empty()) {
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
last_opened_path_->value().c_str());
}
@@ -326,11 +329,12 @@ GtkWidget* SelectFileDialogImpl::CreateFileOpenDialog(const std::string& title,
}
GtkWidget* SelectFileDialogImpl::CreateMultiFileOpenDialog(
- const std::string& title, gfx::NativeWindow parent) {
+ const std::string& title,
+ const FilePath& default_path,
+ gfx::NativeWindow parent) {
std::string title_string = !title.empty() ? title :
l10n_util::GetStringUTF8(IDS_OPEN_FILES_DIALOG_TITLE);
- // TODO(estade): do we want to set the open directory to some sort of default?
GtkWidget* dialog =
gtk_file_chooser_dialog_new(title_string.c_str(), parent,
GTK_FILE_CHOOSER_ACTION_OPEN,
@@ -339,7 +343,12 @@ GtkWidget* SelectFileDialogImpl::CreateMultiFileOpenDialog(
NULL);
AddFilters(GTK_FILE_CHOOSER(dialog));
- if (!last_opened_path_->empty()) {
+ if (!default_path.empty()) {
+ // If the file doesn't exist, this will just switch to the correct
+ // directory. That's good enough.
+ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),
+ default_path.value().c_str());
+ } else if (!last_opened_path_->empty()) {
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
last_opened_path_->value().c_str());
}
@@ -362,17 +371,18 @@ GtkWidget* SelectFileDialogImpl::CreateSaveAsDialog(const std::string& title,
NULL);
AddFilters(GTK_FILE_CHOOSER(dialog));
- // Since we expect that the file will not already exist, we use
- // set_current_folder() followed by set_current_name().
- if (last_saved_path_->empty()) {
+ if (!default_path.empty()) {
+ // 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());
- } else {
+ 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());
}
- gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog),
- default_path.BaseName().value().c_str());
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE);
g_signal_connect(G_OBJECT(dialog), "response",
G_CALLBACK(OnSelectSingleFileDialogResponse), this);