OLD | NEW |
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 <gdk/gdk.h> | 5 #include <gdk/gdk.h> |
6 #include <gdk/gdkx.h> | 6 #include <gdk/gdkx.h> |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 101 |
102 // Notifies the listener that multiple files were chosen. | 102 // Notifies the listener that multiple files were chosen. |
103 void MultiFilesSelected(GtkWidget* dialog, | 103 void MultiFilesSelected(GtkWidget* dialog, |
104 const std::vector<base::FilePath>& files); | 104 const std::vector<base::FilePath>& files); |
105 | 105 |
106 // Notifies the listener that no file was chosen (the action was canceled). | 106 // Notifies the listener that no file was chosen (the action was canceled). |
107 // Dialog is passed so we can find that |params| pointer that was passed to | 107 // Dialog is passed so we can find that |params| pointer that was passed to |
108 // us when we were told to show the dialog. | 108 // us when we were told to show the dialog. |
109 void FileNotSelected(GtkWidget* dialog); | 109 void FileNotSelected(GtkWidget* dialog); |
110 | 110 |
111 GtkWidget* CreateSelectFolderDialog(const std::string& title, | 111 GtkWidget* CreateSelectFolderDialog( |
112 const base::FilePath& default_path, gfx::NativeWindow parent); | 112 Type type, |
| 113 const std::string& title, |
| 114 const base::FilePath& default_path, |
| 115 gfx::NativeWindow parent); |
113 | 116 |
114 GtkWidget* CreateFileOpenDialog(const std::string& title, | 117 GtkWidget* CreateFileOpenDialog(const std::string& title, |
115 const base::FilePath& default_path, gfx::NativeWindow parent); | 118 const base::FilePath& default_path, gfx::NativeWindow parent); |
116 | 119 |
117 GtkWidget* CreateMultiFileOpenDialog(const std::string& title, | 120 GtkWidget* CreateMultiFileOpenDialog(const std::string& title, |
118 const base::FilePath& default_path, gfx::NativeWindow parent); | 121 const base::FilePath& default_path, gfx::NativeWindow parent); |
119 | 122 |
120 GtkWidget* CreateSaveAsDialog(const std::string& title, | 123 GtkWidget* CreateSaveAsDialog(const std::string& title, |
121 const base::FilePath& default_path, gfx::NativeWindow parent); | 124 const base::FilePath& default_path, gfx::NativeWindow parent); |
122 | 125 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 233 |
231 std::string title_string = UTF16ToUTF8(title); | 234 std::string title_string = UTF16ToUTF8(title); |
232 | 235 |
233 file_type_index_ = file_type_index; | 236 file_type_index_ = file_type_index; |
234 if (file_types) | 237 if (file_types) |
235 file_types_ = *file_types; | 238 file_types_ = *file_types; |
236 | 239 |
237 GtkWidget* dialog = NULL; | 240 GtkWidget* dialog = NULL; |
238 switch (type) { | 241 switch (type) { |
239 case SELECT_FOLDER: | 242 case SELECT_FOLDER: |
240 dialog = CreateSelectFolderDialog(title_string, default_path, | 243 case SELECT_UPLOAD_FOLDER: |
| 244 dialog = CreateSelectFolderDialog(type, title_string, default_path, |
241 owning_window); | 245 owning_window); |
242 break; | 246 break; |
243 case SELECT_OPEN_FILE: | 247 case SELECT_OPEN_FILE: |
244 dialog = CreateFileOpenDialog(title_string, default_path, owning_window); | 248 dialog = CreateFileOpenDialog(title_string, default_path, owning_window); |
245 break; | 249 break; |
246 case SELECT_OPEN_MULTI_FILE: | 250 case SELECT_OPEN_MULTI_FILE: |
247 dialog = CreateMultiFileOpenDialog(title_string, default_path, | 251 dialog = CreateMultiFileOpenDialog(title_string, default_path, |
248 owning_window); | 252 owning_window); |
249 break; | 253 break; |
250 case SELECT_SAVEAS_FILE: | 254 case SELECT_SAVEAS_FILE: |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 default_path.value().c_str()); | 393 default_path.value().c_str()); |
390 } | 394 } |
391 } else if (!last_opened_path_->empty()) { | 395 } else if (!last_opened_path_->empty()) { |
392 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), | 396 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), |
393 last_opened_path_->value().c_str()); | 397 last_opened_path_->value().c_str()); |
394 } | 398 } |
395 return dialog; | 399 return dialog; |
396 } | 400 } |
397 | 401 |
398 GtkWidget* SelectFileDialogImplGTK::CreateSelectFolderDialog( | 402 GtkWidget* SelectFileDialogImplGTK::CreateSelectFolderDialog( |
| 403 Type type, |
399 const std::string& title, | 404 const std::string& title, |
400 const base::FilePath& default_path, | 405 const base::FilePath& default_path, |
401 gfx::NativeWindow parent) { | 406 gfx::NativeWindow parent) { |
402 std::string title_string = !title.empty() ? title : | 407 std::string title_string = title; |
| 408 if (title_string.empty()) { |
| 409 title_string = (type == SELECT_UPLOAD_FOLDER) ? |
| 410 l10n_util::GetStringUTF8(IDS_SELECT_UPLOAD_FOLDER_DIALOG_TITLE) : |
403 l10n_util::GetStringUTF8(IDS_SELECT_FOLDER_DIALOG_TITLE); | 411 l10n_util::GetStringUTF8(IDS_SELECT_FOLDER_DIALOG_TITLE); |
| 412 } |
| 413 std::string accept_button_label = (type == SELECT_UPLOAD_FOLDER) ? |
| 414 l10n_util::GetStringUTF8(IDS_SELECT_UPLOAD_FOLDER_DIALOG_UPLOAD_BUTTON) : |
| 415 GTK_STOCK_OPEN; |
404 | 416 |
405 GtkWidget* dialog = | 417 GtkWidget* dialog = |
406 gtk_file_chooser_dialog_new(title_string.c_str(), NULL, | 418 gtk_file_chooser_dialog_new(title_string.c_str(), NULL, |
407 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, | 419 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, |
408 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | 420 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
409 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, | 421 accept_button_label.c_str(), |
| 422 GTK_RESPONSE_ACCEPT, |
410 NULL); | 423 NULL); |
411 SetGtkTransientForAura(dialog, parent); | 424 SetGtkTransientForAura(dialog, parent); |
412 | 425 |
413 if (!default_path.empty()) { | 426 if (!default_path.empty()) { |
414 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), | 427 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), |
415 default_path.value().c_str()); | 428 default_path.value().c_str()); |
416 } else if (!last_opened_path_->empty()) { | 429 } else if (!last_opened_path_->empty()) { |
417 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), | 430 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), |
418 last_opened_path_->value().c_str()); | 431 last_opened_path_->value().c_str()); |
419 } | 432 } |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 g_free(filename); | 620 g_free(filename); |
608 if (pixbuf) { | 621 if (pixbuf) { |
609 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); | 622 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); |
610 g_object_unref(pixbuf); | 623 g_object_unref(pixbuf); |
611 } | 624 } |
612 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), | 625 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), |
613 pixbuf ? TRUE : FALSE); | 626 pixbuf ? TRUE : FALSE); |
614 } | 627 } |
615 | 628 |
616 } // namespace libgtk2ui | 629 } // namespace libgtk2ui |
OLD | NEW |