Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: ui/base/dialogs/gtk/select_file_dialog_impl_gtk.cc

Issue 11778082: estade@ review feedback on r175674 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <gtk/gtk.h> 5 #include <gtk/gtk.h>
6 #include <map> 6 #include <map>
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop.h" 13 #include "base/message_loop.h"
13 #include "base/string_util.h" 14 #include "base/string_util.h"
14 #include "base/sys_string_conversions.h" 15 #include "base/sys_string_conversions.h"
15 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
16 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
17 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
18 #include "grit/ui_strings.h" 19 #include "grit/ui_strings.h"
19 #include "ui/base/dialogs/gtk/select_file_dialog_impl.h" 20 #include "ui/base/dialogs/gtk/select_file_dialog_impl.h"
20 #include "ui/base/dialogs/select_file_dialog.h" 21 #include "ui/base/dialogs/select_file_dialog.h"
21 #include "ui/base/gtk/gtk_signal.h" 22 #include "ui/base/gtk/gtk_signal.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 24
24 namespace { 25 namespace {
25 26
26 // Makes sure that .jpg also shows .JPG. |data| is a std::string* in disguise. 27 // Makes sure that .jpg also shows .JPG.
27 gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info, 28 gboolean FileFilterCaseInsensitive(const GtkFileFilterInfo* file_info,
28 gpointer data) { 29 std::string* file_extension) {
29 std::string* file_extension = reinterpret_cast<std::string*>(data);
30 return EndsWith(file_info->filename, *file_extension, false); 30 return EndsWith(file_info->filename, *file_extension, false);
31 } 31 }
32 32
33 // Deletes |data| when gtk_file_filter_add_custom() is done with it. 33 // Deletes |data| when gtk_file_filter_add_custom() is done with it.
34 void OnFileFilterDataDestroyed(gpointer data) { 34 void OnFileFilterDataDestroyed(std::string* file_extension) {
35 delete reinterpret_cast<std::string*>(data); 35 delete file_extension;
36 } 36 }
37 37
38 // Implementation of SelectFileDialog that shows a Gtk common dialog for 38 // Implementation of SelectFileDialog that shows a Gtk common dialog for
39 // choosing a file or folder. This acts as a modal dialog. 39 // choosing a file or folder. This acts as a modal dialog.
40 class SelectFileDialogImplGTK : public ui::SelectFileDialogImpl { 40 class SelectFileDialogImplGTK : public ui::SelectFileDialogImpl {
41 public: 41 public:
42 explicit SelectFileDialogImplGTK(Listener* listener, 42 explicit SelectFileDialogImplGTK(Listener* listener,
43 ui::SelectFilePolicy* policy); 43 ui::SelectFilePolicy* policy);
44 44
45 protected: 45 protected:
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { 232 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) {
233 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { 233 for (size_t i = 0; i < file_types_.extensions.size(); ++i) {
234 GtkFileFilter* filter = NULL; 234 GtkFileFilter* filter = NULL;
235 std::set<std::string> fallback_labels; 235 std::set<std::string> fallback_labels;
236 236
237 for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) { 237 for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) {
238 const std::string& current_extension = file_types_.extensions[i][j]; 238 const std::string& current_extension = file_types_.extensions[i][j];
239 if (!current_extension.empty()) { 239 if (!current_extension.empty()) {
240 if (!filter) 240 if (!filter)
241 filter = gtk_file_filter_new(); 241 filter = gtk_file_filter_new();
242 // |file_extension| is freed in |OnFileFilterDataDestroyed()|. 242 scoped_ptr<std::string> file_extension(
243 std::string* file_extension = new std::string("." + current_extension); 243 new std::string("." + current_extension));
244 gtk_file_filter_add_custom(filter,
245 GTK_FILE_FILTER_FILENAME,
246 &FileFilterCaseInsensitive,
247 reinterpret_cast<gpointer>(file_extension),
248 &OnFileFilterDataDestroyed);
249 fallback_labels.insert(std::string("*").append(*file_extension)); 244 fallback_labels.insert(std::string("*").append(*file_extension));
245 gtk_file_filter_add_custom(
246 filter,
247 GTK_FILE_FILTER_FILENAME,
248 reinterpret_cast<GtkFileFilterFunc>(FileFilterCaseInsensitive),
249 file_extension.release(),
250 reinterpret_cast<GDestroyNotify>(OnFileFilterDataDestroyed));
250 } 251 }
251 } 252 }
252 // We didn't find any non-empty extensions to filter on. 253 // We didn't find any non-empty extensions to filter on.
253 if (!filter) 254 if (!filter)
254 continue; 255 continue;
255 256
256 // The description vector may be blank, in which case we are supposed to 257 // The description vector may be blank, in which case we are supposed to
257 // use some sort of default description based on the filter. 258 // use some sort of default description based on the filter.
258 if (i < file_types_.extension_description_overrides.size()) { 259 if (i < file_types_.extension_description_overrides.size()) {
259 gtk_file_filter_set_name(filter, UTF16ToUTF8( 260 gtk_file_filter_set_name(filter, UTF16ToUTF8(
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 } // namespace 571 } // namespace
571 572
572 namespace ui { 573 namespace ui {
573 574
574 SelectFileDialogImpl* SelectFileDialogImpl::NewSelectFileDialogImplGTK( 575 SelectFileDialogImpl* SelectFileDialogImpl::NewSelectFileDialogImplGTK(
575 Listener* listener, ui::SelectFilePolicy* policy) { 576 Listener* listener, ui::SelectFilePolicy* policy) {
576 return new SelectFileDialogImplGTK(listener, policy); 577 return new SelectFileDialogImplGTK(listener, policy);
577 } 578 }
578 579
579 } // namespace ui 580 } // namespace ui
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698