| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 // Notifies the listener that multiple files were chosen. | 69 // Notifies the listener that multiple files were chosen. |
| 70 void MultiFilesSelected(GtkWidget* dialog, | 70 void MultiFilesSelected(GtkWidget* dialog, |
| 71 const std::vector<base::FilePath>& files); | 71 const std::vector<base::FilePath>& files); |
| 72 | 72 |
| 73 // Notifies the listener that no file was chosen (the action was canceled). | 73 // Notifies the listener that no file was chosen (the action was canceled). |
| 74 // Dialog is passed so we can find that |params| pointer that was passed to | 74 // Dialog is passed so we can find that |params| pointer that was passed to |
| 75 // us when we were told to show the dialog. | 75 // us when we were told to show the dialog. |
| 76 void FileNotSelected(GtkWidget* dialog); | 76 void FileNotSelected(GtkWidget* dialog); |
| 77 | 77 |
| 78 GtkWidget* CreateSelectFolderDialog(const std::string& title, | 78 GtkWidget* CreateSelectFolderDialog( |
| 79 const base::FilePath& default_path, gfx::NativeWindow parent); | 79 Type type, |
| 80 const std::string& title, |
| 81 const base::FilePath& default_path, |
| 82 gfx::NativeWindow parent); |
| 80 | 83 |
| 81 GtkWidget* CreateFileOpenDialog(const std::string& title, | 84 GtkWidget* CreateFileOpenDialog(const std::string& title, |
| 82 const base::FilePath& default_path, gfx::NativeWindow parent); | 85 const base::FilePath& default_path, gfx::NativeWindow parent); |
| 83 | 86 |
| 84 GtkWidget* CreateMultiFileOpenDialog(const std::string& title, | 87 GtkWidget* CreateMultiFileOpenDialog(const std::string& title, |
| 85 const base::FilePath& default_path, gfx::NativeWindow parent); | 88 const base::FilePath& default_path, gfx::NativeWindow parent); |
| 86 | 89 |
| 87 GtkWidget* CreateSaveAsDialog(const std::string& title, | 90 GtkWidget* CreateSaveAsDialog(const std::string& title, |
| 88 const base::FilePath& default_path, gfx::NativeWindow parent); | 91 const base::FilePath& default_path, gfx::NativeWindow parent); |
| 89 | 92 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 187 |
| 185 file_type_index_ = file_type_index; | 188 file_type_index_ = file_type_index; |
| 186 if (file_types) | 189 if (file_types) |
| 187 file_types_ = *file_types; | 190 file_types_ = *file_types; |
| 188 else | 191 else |
| 189 file_types_.include_all_files = true; | 192 file_types_.include_all_files = true; |
| 190 | 193 |
| 191 GtkWidget* dialog = NULL; | 194 GtkWidget* dialog = NULL; |
| 192 switch (type) { | 195 switch (type) { |
| 193 case SELECT_FOLDER: | 196 case SELECT_FOLDER: |
| 194 dialog = CreateSelectFolderDialog(title_string, default_path, | 197 case SELECT_UPLOAD_FOLDER: |
| 198 dialog = CreateSelectFolderDialog(type, title_string, default_path, |
| 195 owning_window); | 199 owning_window); |
| 196 break; | 200 break; |
| 197 case SELECT_OPEN_FILE: | 201 case SELECT_OPEN_FILE: |
| 198 dialog = CreateFileOpenDialog(title_string, default_path, owning_window); | 202 dialog = CreateFileOpenDialog(title_string, default_path, owning_window); |
| 199 break; | 203 break; |
| 200 case SELECT_OPEN_MULTI_FILE: | 204 case SELECT_OPEN_MULTI_FILE: |
| 201 dialog = CreateMultiFileOpenDialog(title_string, default_path, | 205 dialog = CreateMultiFileOpenDialog(title_string, default_path, |
| 202 owning_window); | 206 owning_window); |
| 203 break; | 207 break; |
| 204 case SELECT_SAVEAS_FILE: | 208 case SELECT_SAVEAS_FILE: |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 default_path.value().c_str()); | 348 default_path.value().c_str()); |
| 345 } | 349 } |
| 346 } else if (!last_opened_path_->empty()) { | 350 } else if (!last_opened_path_->empty()) { |
| 347 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), | 351 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), |
| 348 last_opened_path_->value().c_str()); | 352 last_opened_path_->value().c_str()); |
| 349 } | 353 } |
| 350 return dialog; | 354 return dialog; |
| 351 } | 355 } |
| 352 | 356 |
| 353 GtkWidget* SelectFileDialogImplGTK::CreateSelectFolderDialog( | 357 GtkWidget* SelectFileDialogImplGTK::CreateSelectFolderDialog( |
| 358 Type type, |
| 354 const std::string& title, | 359 const std::string& title, |
| 355 const base::FilePath& default_path, | 360 const base::FilePath& default_path, |
| 356 gfx::NativeWindow parent) { | 361 gfx::NativeWindow parent) { |
| 357 std::string title_string = !title.empty() ? title : | 362 std::string title_string = title; |
| 363 if (title_string.empty()) { |
| 364 title_string = (type == SELECT_UPLOAD_FOLDER) ? |
| 365 l10n_util::GetStringUTF8(IDS_SELECT_UPLOAD_FOLDER_DIALOG_TITLE) : |
| 358 l10n_util::GetStringUTF8(IDS_SELECT_FOLDER_DIALOG_TITLE); | 366 l10n_util::GetStringUTF8(IDS_SELECT_FOLDER_DIALOG_TITLE); |
| 367 } |
| 368 std::string accept_button_label = (type == SELECT_UPLOAD_FOLDER) ? |
| 369 l10n_util::GetStringUTF8(IDS_SELECT_UPLOAD_FOLDER_DIALOG_UPLOAD_BUTTON) : |
| 370 GTK_STOCK_OPEN; |
| 359 | 371 |
| 360 GtkWidget* dialog = | 372 GtkWidget* dialog = |
| 361 gtk_file_chooser_dialog_new(title_string.c_str(), parent, | 373 gtk_file_chooser_dialog_new(title_string.c_str(), parent, |
| 362 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, | 374 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, |
| 363 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | 375 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
| 364 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, | 376 accept_button_label.c_str(), |
| 377 GTK_RESPONSE_ACCEPT, |
| 365 NULL); | 378 NULL); |
| 366 | 379 |
| 367 if (!default_path.empty()) { | 380 if (!default_path.empty()) { |
| 368 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), | 381 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), |
| 369 default_path.value().c_str()); | 382 default_path.value().c_str()); |
| 370 } else if (!last_opened_path_->empty()) { | 383 } else if (!last_opened_path_->empty()) { |
| 371 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), | 384 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), |
| 372 last_opened_path_->value().c_str()); | 385 last_opened_path_->value().c_str()); |
| 373 } | 386 } |
| 374 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE); | 387 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 } // namespace | 585 } // namespace |
| 573 | 586 |
| 574 namespace ui { | 587 namespace ui { |
| 575 | 588 |
| 576 SelectFileDialogImpl* SelectFileDialogImpl::NewSelectFileDialogImplGTK( | 589 SelectFileDialogImpl* SelectFileDialogImpl::NewSelectFileDialogImplGTK( |
| 577 Listener* listener, ui::SelectFilePolicy* policy) { | 590 Listener* listener, ui::SelectFilePolicy* policy) { |
| 578 return new SelectFileDialogImplGTK(listener, policy); | 591 return new SelectFileDialogImplGTK(listener, policy); |
| 579 } | 592 } |
| 580 | 593 |
| 581 } // namespace ui | 594 } // namespace ui |
| OLD | NEW |