diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 19:07:13 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 19:07:13 +0000 |
commit | 711af1e567247935ce44a0ab253ea9cbfcb3a5fb (patch) | |
tree | f79d4d44c41a711a6948745b8be0f00c95a2efb7 /chrome | |
parent | 207d58c747ad0009fa3a918f67c33fc0dafe74f1 (diff) | |
download | chromium_src-711af1e567247935ce44a0ab253ea9cbfcb3a5fb.zip chromium_src-711af1e567247935ce44a0ab253ea9cbfcb3a5fb.tar.gz chromium_src-711af1e567247935ce44a0ab253ea9cbfcb3a5fb.tar.bz2 |
GTK: Implement folder chooser dialog.
Also, found another gtk bug: http://bugzilla.gnome.org/show_bug.cgi?id=594089 We can't write a suppression for this bug because the warning message is too generic, but it shouldn't be much of a problem in release builds.
BUG=20940
Review URL: http://codereview.chromium.org/196014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25485 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/generated_resources.grd | 3 | ||||
-rw-r--r-- | chrome/browser/gtk/dialogs_gtk.cc | 49 |
2 files changed, 46 insertions, 6 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 6742901..c510d0e 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4890,6 +4890,9 @@ Keep your key file in a safe place. You will need it to create new versions of y </if> <!-- File chooser dialog default titles (only used on Linux) --> + <message name="IDS_SELECT_FOLDER_DIALOG_TITLE" desc="The default title for the Select Folder file chooser dialog."> + Select Folder + </message> <message name="IDS_SAVE_AS_DIALOG_TITLE" desc="The default title for the Save As file chooser dialog."> Save File </message> diff --git a/chrome/browser/gtk/dialogs_gtk.cc b/chrome/browser/gtk/dialogs_gtk.cc index f4a76db..7681ad1 100644 --- a/chrome/browser/gtk/dialogs_gtk.cc +++ b/chrome/browser/gtk/dialogs_gtk.cc @@ -64,6 +64,9 @@ class SelectFileDialogImpl : public SelectFileDialog { // us when we were told to show the dialog. void FileNotSelected(GtkWidget* dialog); + GtkWidget* CreateSelectFolderDialog(const std::string& title, + const FilePath& default_path, gfx::NativeWindow parent); + GtkWidget* CreateFileOpenDialog(const std::string& title, const FilePath& default_path, gfx::NativeWindow parent); @@ -84,7 +87,8 @@ class SelectFileDialogImpl : public SelectFileDialog { // dialog. Used as a helper for the below callbacks. static bool IsCancelResponse(gint response_id); - // Callback for when the user responds to a Save As or Open File dialog. + // Callback for when the user responds to a Save As or Open File or + // Select Folder dialog. static void OnSelectSingleFileDialogResponse( GtkWidget* dialog, gint response_id, SelectFileDialogImpl* dialog_impl); @@ -183,6 +187,10 @@ void SelectFileDialogImpl::SelectFile( GtkWidget* dialog = NULL; switch (type) { + case SELECT_FOLDER: + dialog = CreateSelectFolderDialog(title_string, default_path, + owning_window); + break; case SELECT_OPEN_FILE: dialog = CreateFileOpenDialog(title_string, default_path, owning_window); break; @@ -194,7 +202,7 @@ void SelectFileDialogImpl::SelectFile( dialog = CreateSaveAsDialog(title_string, default_path, owning_window); break; default: - NOTIMPLEMENTED() << "Dialog type " << type << " not implemented."; + NOTREACHED(); return; } @@ -260,12 +268,14 @@ void SelectFileDialogImpl::AddFilters(GtkFileChooser* chooser) { void SelectFileDialogImpl::FileSelected(GtkWidget* dialog, const FilePath& path) { - if (type_ == SELECT_SAVEAS_FILE) { + if (type_ == SELECT_SAVEAS_FILE) *last_saved_path_ = path.DirName(); - } else { - DCHECK_EQ(type_, SELECT_OPEN_FILE); + else if (type_ == SELECT_OPEN_FILE) *last_opened_path_ = path.DirName(); - } + else if (type_ == SELECT_FOLDER) + *last_opened_path_ = path.DirName().DirName(); + else + NOTREACHED(); if (listener_) { GtkFileFilter* selected_filter = @@ -297,6 +307,33 @@ void SelectFileDialogImpl::FileNotSelected(GtkWidget* dialog) { gtk_widget_destroy(dialog); } +GtkWidget* SelectFileDialogImpl::CreateSelectFolderDialog( + const std::string& title, + const FilePath& default_path, + gfx::NativeWindow parent) { + std::string title_string = !title.empty() ? title : + l10n_util::GetStringUTF8(IDS_SELECT_FOLDER_DIALOG_TITLE); + + GtkWidget* dialog = + gtk_file_chooser_dialog_new(title_string.c_str(), parent, + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + + if (!default_path.empty()) { + 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()); + } + gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE); + g_signal_connect(G_OBJECT(dialog), "response", + G_CALLBACK(OnSelectSingleFileDialogResponse), this); + return dialog; +} + GtkWidget* SelectFileDialogImpl::CreateFileOpenDialog(const std::string& title, const FilePath& default_path, gfx::NativeWindow parent) { std::string title_string = !title.empty() ? title : |