| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 void SelectFileDialogImpl::FileNotSelected(GtkWidget* dialog) { | 296 void SelectFileDialogImpl::FileNotSelected(GtkWidget* dialog) { |
| 297 void* params = PopParamsForDialog(dialog); | 297 void* params = PopParamsForDialog(dialog); |
| 298 if (listener_) | 298 if (listener_) |
| 299 listener_->FileSelectionCanceled(params); | 299 listener_->FileSelectionCanceled(params); |
| 300 RemoveParentForDialog(dialog); | 300 RemoveParentForDialog(dialog); |
| 301 gtk_widget_destroy(dialog); | 301 gtk_widget_destroy(dialog); |
| 302 } | 302 } |
| 303 | 303 |
| 304 GtkWidget* SelectFileDialogImpl::CreateFileOpenDialog(const std::string& title, | 304 GtkWidget* SelectFileDialogImpl::CreateFileOpenDialog(const std::string& title, |
| 305 gfx::NativeWindow parent) { | 305 gfx::NativeWindow parent) { |
| 306 std::string title_string = !title.empty() ? title : |
| 307 l10n_util::GetStringUTF8(IDS_OPEN_FILE_DIALOG_TITLE); |
| 308 |
| 306 // TODO(estade): do we want to set the open directory to some sort of default? | 309 // TODO(estade): do we want to set the open directory to some sort of default? |
| 307 GtkWidget* dialog = | 310 GtkWidget* dialog = |
| 308 gtk_file_chooser_dialog_new(title.c_str(), parent, | 311 gtk_file_chooser_dialog_new(title_string.c_str(), parent, |
| 309 GTK_FILE_CHOOSER_ACTION_OPEN, | 312 GTK_FILE_CHOOSER_ACTION_OPEN, |
| 310 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | 313 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
| 311 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, | 314 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
| 312 NULL); | 315 NULL); |
| 313 | 316 |
| 314 AddFilters(GTK_FILE_CHOOSER(dialog)); | 317 AddFilters(GTK_FILE_CHOOSER(dialog)); |
| 315 if (!last_opened_path_->empty()) { | 318 if (!last_opened_path_->empty()) { |
| 316 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), | 319 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), |
| 317 last_opened_path_->value().c_str()); | 320 last_opened_path_->value().c_str()); |
| 318 } | 321 } |
| 319 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE); | 322 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE); |
| 320 g_signal_connect(G_OBJECT(dialog), "response", | 323 g_signal_connect(G_OBJECT(dialog), "response", |
| 321 G_CALLBACK(OnSelectSingleFileDialogResponse), this); | 324 G_CALLBACK(OnSelectSingleFileDialogResponse), this); |
| 322 return dialog; | 325 return dialog; |
| 323 } | 326 } |
| 324 | 327 |
| 325 GtkWidget* SelectFileDialogImpl::CreateMultiFileOpenDialog( | 328 GtkWidget* SelectFileDialogImpl::CreateMultiFileOpenDialog( |
| 326 const std::string& title, gfx::NativeWindow parent) { | 329 const std::string& title, gfx::NativeWindow parent) { |
| 330 std::string title_string = !title.empty() ? title : |
| 331 l10n_util::GetStringUTF8(IDS_OPEN_FILES_DIALOG_TITLE); |
| 332 |
| 327 // TODO(estade): do we want to set the open directory to some sort of default? | 333 // TODO(estade): do we want to set the open directory to some sort of default? |
| 328 GtkWidget* dialog = | 334 GtkWidget* dialog = |
| 329 gtk_file_chooser_dialog_new(title.c_str(), parent, | 335 gtk_file_chooser_dialog_new(title_string.c_str(), parent, |
| 330 GTK_FILE_CHOOSER_ACTION_OPEN, | 336 GTK_FILE_CHOOSER_ACTION_OPEN, |
| 331 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | 337 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
| 332 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, | 338 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
| 333 NULL); | 339 NULL); |
| 334 | 340 |
| 335 AddFilters(GTK_FILE_CHOOSER(dialog)); | 341 AddFilters(GTK_FILE_CHOOSER(dialog)); |
| 336 if (!last_opened_path_->empty()) { | 342 if (!last_opened_path_->empty()) { |
| 337 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), | 343 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), |
| 338 last_opened_path_->value().c_str()); | 344 last_opened_path_->value().c_str()); |
| 339 } | 345 } |
| 340 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); | 346 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); |
| 341 g_signal_connect(G_OBJECT(dialog), "response", | 347 g_signal_connect(G_OBJECT(dialog), "response", |
| 342 G_CALLBACK(OnSelectMultiFileDialogResponse), this); | 348 G_CALLBACK(OnSelectMultiFileDialogResponse), this); |
| 343 return dialog; | 349 return dialog; |
| 344 } | 350 } |
| 345 | 351 |
| 346 GtkWidget* SelectFileDialogImpl::CreateSaveAsDialog(const std::string& title, | 352 GtkWidget* SelectFileDialogImpl::CreateSaveAsDialog(const std::string& title, |
| 347 const FilePath& default_path, gfx::NativeWindow parent) { | 353 const FilePath& default_path, gfx::NativeWindow parent) { |
| 354 std::string title_string = !title.empty() ? title : |
| 355 l10n_util::GetStringUTF8(IDS_SAVE_AS_DIALOG_TITLE); |
| 356 |
| 348 GtkWidget* dialog = | 357 GtkWidget* dialog = |
| 349 gtk_file_chooser_dialog_new(title.c_str(), parent, | 358 gtk_file_chooser_dialog_new(title_string.c_str(), parent, |
| 350 GTK_FILE_CHOOSER_ACTION_SAVE, | 359 GTK_FILE_CHOOSER_ACTION_SAVE, |
| 351 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | 360 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
| 352 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, | 361 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, |
| 353 NULL); | 362 NULL); |
| 354 | 363 |
| 355 AddFilters(GTK_FILE_CHOOSER(dialog)); | 364 AddFilters(GTK_FILE_CHOOSER(dialog)); |
| 356 // Since we expect that the file will not already exist, we use | 365 // Since we expect that the file will not already exist, we use |
| 357 // set_current_folder() followed by set_current_name(). | 366 // set_current_folder() followed by set_current_name(). |
| 358 if (last_saved_path_->empty()) { | 367 if (last_saved_path_->empty()) { |
| 359 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), | 368 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 // This will preserve the image's aspect ratio. | 448 // This will preserve the image's aspect ratio. |
| 440 GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename, kPreviewWidth, | 449 GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename, kPreviewWidth, |
| 441 kPreviewHeight, NULL); | 450 kPreviewHeight, NULL); |
| 442 g_free(filename); | 451 g_free(filename); |
| 443 if (pixbuf) { | 452 if (pixbuf) { |
| 444 gtk_image_set_from_pixbuf(GTK_IMAGE(dialog->preview_), pixbuf); | 453 gtk_image_set_from_pixbuf(GTK_IMAGE(dialog->preview_), pixbuf); |
| 445 g_object_unref(pixbuf); | 454 g_object_unref(pixbuf); |
| 446 } | 455 } |
| 447 gtk_file_chooser_set_preview_widget_active(chooser, pixbuf ? TRUE : FALSE); | 456 gtk_file_chooser_set_preview_widget_active(chooser, pixbuf ? TRUE : FALSE); |
| 448 } | 457 } |
| OLD | NEW |