| 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 Type type, const std::string& title, |
| 112 const base::FilePath& default_path, gfx::NativeWindow parent); | 113 const base::FilePath& default_path, gfx::NativeWindow parent); |
| 113 | 114 |
| 114 GtkWidget* CreateFileOpenDialog(const std::string& title, | 115 GtkWidget* CreateFileOpenDialog(const std::string& title, |
| 115 const base::FilePath& default_path, gfx::NativeWindow parent); | 116 const base::FilePath& default_path, gfx::NativeWindow parent); |
| 116 | 117 |
| 117 GtkWidget* CreateMultiFileOpenDialog(const std::string& title, | 118 GtkWidget* CreateMultiFileOpenDialog(const std::string& title, |
| 118 const base::FilePath& default_path, gfx::NativeWindow parent); | 119 const base::FilePath& default_path, gfx::NativeWindow parent); |
| 119 | 120 |
| 120 GtkWidget* CreateSaveAsDialog(const std::string& title, | 121 GtkWidget* CreateSaveAsDialog(const std::string& title, |
| 121 const base::FilePath& default_path, gfx::NativeWindow parent); | 122 const base::FilePath& default_path, gfx::NativeWindow parent); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 231 |
| 231 std::string title_string = UTF16ToUTF8(title); | 232 std::string title_string = UTF16ToUTF8(title); |
| 232 | 233 |
| 233 file_type_index_ = file_type_index; | 234 file_type_index_ = file_type_index; |
| 234 if (file_types) | 235 if (file_types) |
| 235 file_types_ = *file_types; | 236 file_types_ = *file_types; |
| 236 | 237 |
| 237 GtkWidget* dialog = NULL; | 238 GtkWidget* dialog = NULL; |
| 238 switch (type) { | 239 switch (type) { |
| 239 case SELECT_FOLDER: | 240 case SELECT_FOLDER: |
| 240 dialog = CreateSelectFolderDialog(title_string, default_path, | 241 case SELECT_UPLOAD_FOLDER: |
| 242 dialog = CreateSelectFolderDialog(type, title_string, default_path, |
| 241 owning_window); | 243 owning_window); |
| 242 break; | 244 break; |
| 243 case SELECT_OPEN_FILE: | 245 case SELECT_OPEN_FILE: |
| 244 dialog = CreateFileOpenDialog(title_string, default_path, owning_window); | 246 dialog = CreateFileOpenDialog(title_string, default_path, owning_window); |
| 245 break; | 247 break; |
| 246 case SELECT_OPEN_MULTI_FILE: | 248 case SELECT_OPEN_MULTI_FILE: |
| 247 dialog = CreateMultiFileOpenDialog(title_string, default_path, | 249 dialog = CreateMultiFileOpenDialog(title_string, default_path, |
| 248 owning_window); | 250 owning_window); |
| 249 break; | 251 break; |
| 250 case SELECT_SAVEAS_FILE: | 252 case SELECT_SAVEAS_FILE: |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 default_path.value().c_str()); | 391 default_path.value().c_str()); |
| 390 } | 392 } |
| 391 } else if (!last_opened_path_->empty()) { | 393 } else if (!last_opened_path_->empty()) { |
| 392 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), | 394 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), |
| 393 last_opened_path_->value().c_str()); | 395 last_opened_path_->value().c_str()); |
| 394 } | 396 } |
| 395 return dialog; | 397 return dialog; |
| 396 } | 398 } |
| 397 | 399 |
| 398 GtkWidget* SelectFileDialogImplGTK::CreateSelectFolderDialog( | 400 GtkWidget* SelectFileDialogImplGTK::CreateSelectFolderDialog( |
| 401 Type type, |
| 399 const std::string& title, | 402 const std::string& title, |
| 400 const base::FilePath& default_path, | 403 const base::FilePath& default_path, |
| 401 gfx::NativeWindow parent) { | 404 gfx::NativeWindow parent) { |
| 402 std::string title_string = !title.empty() ? title : | 405 std::string title_string = title; |
| 406 if (title_string.empty()) { |
| 407 title_string = (type == SELECT_UPLOAD_FOLDER) ? |
| 408 l10n_util::GetStringUTF8(IDS_SELECT_UPLOAD_FOLDER_DIALOG_TITLE) : |
| 403 l10n_util::GetStringUTF8(IDS_SELECT_FOLDER_DIALOG_TITLE); | 409 l10n_util::GetStringUTF8(IDS_SELECT_FOLDER_DIALOG_TITLE); |
| 410 } |
| 411 std::string accept_button_label = (type == SELECT_UPLOAD_FOLDER) ? |
| 412 l10n_util::GetStringUTF8(IDS_SELECT_UPLOAD_FOLDER_DIALOG_UPLOAD_BUTTON) : |
| 413 GTK_STOCK_OPEN; |
| 404 | 414 |
| 405 GtkWidget* dialog = | 415 GtkWidget* dialog = |
| 406 gtk_file_chooser_dialog_new(title_string.c_str(), NULL, | 416 gtk_file_chooser_dialog_new(title_string.c_str(), NULL, |
| 407 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, | 417 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, |
| 408 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | 418 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
| 409 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, | 419 accept_button_label.c_str(), |
| 420 GTK_RESPONSE_ACCEPT, |
| 410 NULL); | 421 NULL); |
| 411 SetGtkTransientForAura(dialog, parent); | 422 SetGtkTransientForAura(dialog, parent); |
| 412 | 423 |
| 413 if (!default_path.empty()) { | 424 if (!default_path.empty()) { |
| 414 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), | 425 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), |
| 415 default_path.value().c_str()); | 426 default_path.value().c_str()); |
| 416 } else if (!last_opened_path_->empty()) { | 427 } else if (!last_opened_path_->empty()) { |
| 417 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), | 428 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), |
| 418 last_opened_path_->value().c_str()); | 429 last_opened_path_->value().c_str()); |
| 419 } | 430 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 g_free(filename); | 618 g_free(filename); |
| 608 if (pixbuf) { | 619 if (pixbuf) { |
| 609 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); | 620 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); |
| 610 g_object_unref(pixbuf); | 621 g_object_unref(pixbuf); |
| 611 } | 622 } |
| 612 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), | 623 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), |
| 613 pixbuf ? TRUE : FALSE); | 624 pixbuf ? TRUE : FALSE); |
| 614 } | 625 } |
| 615 | 626 |
| 616 } // namespace libgtk2ui | 627 } // namespace libgtk2ui |
| OLD | NEW |