Index: ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc |
diff --git a/ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc b/ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc |
index b66afc280eded3d8436c0aa60e333475fd135ac9..77839eade8867ff354cc9385bf5c240f426d4a5f 100644 |
--- a/ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc |
+++ b/ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc |
@@ -23,6 +23,18 @@ |
namespace { |
+// Makes sure that .jpg also shows .JPG. |data| is a std::string* in disguise. |
+gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info, |
+ gpointer data) { |
Evan Stade
2013/01/10 01:50:06
just make data a std::string*
Dan Beam
2013/01/10 05:37:08
Done.
|
+ std::string* file_extension = reinterpret_cast<std::string*>(data); |
+ return EndsWith(file_info->filename, *file_extension, false); |
+} |
+ |
+// Deletes |data| when gtk_file_filter_add_custom() is done with it. |
+void OnFileFilterDataDestroyed(gpointer data) { |
+ delete reinterpret_cast<std::string*>(data); |
+} |
+ |
// Implementation of SelectFileDialog that shows a Gtk common dialog for |
// choosing a file or folder. This acts as a modal dialog. |
class SelectFileDialogImplGTK : public ui::SelectFileDialogImpl { |
@@ -227,9 +239,14 @@ void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { |
if (!current_extension.empty()) { |
if (!filter) |
filter = gtk_file_filter_new(); |
- std::string pattern = "*." + current_extension; |
- gtk_file_filter_add_pattern(filter, pattern.c_str()); |
- fallback_labels.insert(pattern); |
+ // |file_extension| is freed in |OnFileFilterDataDestroyed()|. |
+ std::string* file_extension = new std::string("." + current_extension); |
Evan Stade
2013/01/10 01:50:06
scoped_ptr for clarity (and .release() it to the f
Dan Beam
2013/01/10 05:37:08
Done.
|
+ gtk_file_filter_add_custom(filter, |
+ GTK_FILE_FILTER_FILENAME, |
+ &FileFilterCaseInsensitive, |
+ reinterpret_cast<gpointer>(file_extension), |
Evan Stade
2013/01/10 01:50:06
sure this cast is necessary?
Dan Beam
2013/01/10 05:37:08
Nope, it's not.
|
+ &OnFileFilterDataDestroyed); |
+ fallback_labels.insert(std::string("*").append(*file_extension)); |
Evan Stade
2013/01/10 01:50:06
you should not use file_extension after you've han
Dan Beam
2013/01/10 05:37:08
Done.
|
} |
} |
// We didn't find any non-empty extensions to filter on. |