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

Unified Diff: chrome/browser/gtk/dialogs_gtk.cc

Issue 151100: GTK: Preview images in file chooser.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/gtk/dialogs_gtk.cc
===================================================================
--- chrome/browser/gtk/dialogs_gtk.cc (revision 19623)
+++ chrome/browser/gtk/dialogs_gtk.cc (working copy)
@@ -17,6 +17,14 @@
#include "chrome/browser/shell_dialogs.h"
#include "grit/generated_resources.h"
+// The size of the preview we display for selected image files. We set height
+// larger than width because generally there is more free space vertically
+// than horiztonally (setting the preview image will alway expand the width of
+// the dialog, but usually not the height). The image's aspect ratio will always
+// be preserved.
+static const int kPreviewWidth = 256;
+static const int kPreviewHeight = 512;
+
// Implementation of SelectFileDialog that shows a Gtk common dialog for
// choosing a file or folder.
// This acts as a modal dialog. Ideally we want to only act modally for the
@@ -88,6 +96,10 @@
static void OnSelectMultiFileDialogResponse(
GtkWidget* dialog, gint response_id, SelectFileDialogImpl* dialog_impl);
+ // Callback for when we update the preview for the selection.
+ static void OnUpdatePreview(GtkFileChooser* chooser,
+ SelectFileDialogImpl* dialog);
+
// The listener to be notified of selection completion.
Listener* listener_;
@@ -112,6 +124,9 @@
static FilePath* last_saved_path_;
static FilePath* last_opened_path_;
+ // The GtkImage widget for showing previews of selected images.
+ GtkWidget* preview_;
+
DISALLOW_COPY_AND_ASSIGN(SelectFileDialogImpl);
};
@@ -188,6 +203,10 @@
return;
}
+ preview_ = gtk_image_new();
+ g_signal_connect(dialog, "update-preview", G_CALLBACK(OnUpdatePreview), this);
+ gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_);
+
params_map_[dialog] = params;
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
gtk_widget_show_all(dialog);
@@ -409,3 +428,20 @@
g_slist_free(filenames);
dialog_impl->MultiFilesSelected(dialog, filenames_fp);
}
+
+// static
+void SelectFileDialogImpl::OnUpdatePreview(GtkFileChooser* chooser,
+ SelectFileDialogImpl* dialog) {
+ gchar* filename = gtk_file_chooser_get_preview_filename(chooser);
+ if (!filename)
+ return;
+ // This will preserve the image's aspect ratio.
+ GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename, kPreviewWidth,
+ kPreviewHeight, NULL);
+ g_free(filename);
+ if (pixbuf) {
+ gtk_image_set_from_pixbuf(GTK_IMAGE(dialog->preview_), pixbuf);
+ g_object_unref(pixbuf);
+ }
+ gtk_file_chooser_set_preview_widget_active(chooser, pixbuf ? true : false);
Evan Martin 2009/06/30 20:16:58 maybe TRUE and FALSE here
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698