[gegl-edit] Added image preview widget to file chooser and file chooser now initializes on the current filename
- From: Isaac Wagner <isaacbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl-edit] Added image preview widget to file chooser and file chooser now initializes on the current filename
- Date: Thu, 9 Aug 2012 02:19:32 +0000 (UTC)
commit 5a6b99ec76e3cd9037241bbefc3cde9a4814ca4d
Author: Isaac Wagner <isaacbw src gnome org>
Date: Wed Aug 8 22:19:27 2012 -0400
Added image preview widget to file chooser and file chooser now initializes on the current filename if any
gegl-edit/gegl-gtk-property-view.c | 33 ++++++++++++++++++++++++++++++++-
1 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/gegl-edit/gegl-gtk-property-view.c b/gegl-edit/gegl-gtk-property-view.c
index 04edbfd..4676897 100644
--- a/gegl-edit/gegl-gtk-property-view.c
+++ b/gegl-edit/gegl-gtk-property-view.c
@@ -271,21 +271,52 @@ proxy_checkbox_toggled (GtkToggleButton *togglebutton, PropertyCallbackData *dat
}
}
+//from http://developer.gnome.org/gtk/2.24/GtkFileChooser.html
+static void
+update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
+{
+ GtkWidget *preview;
+ char *filename;
+ GdkPixbuf *pixbuf;
+ gboolean have_preview;
+
+ preview = GTK_WIDGET (data);
+ filename = gtk_file_chooser_get_preview_filename (file_chooser);
+
+ pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
+ have_preview = (pixbuf != NULL);
+ g_free (filename);
+
+ gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
+ if (pixbuf)
+ g_object_unref (pixbuf);
+
+ gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);
+}
+
static void
file_browse (GtkButton *button, PropertyCallbackData *data)
{
GtkWidget *window = gtk_widget_get_ancestor(GTK_WIDGET(button), GTK_TYPE_WINDOW);
+ GtkWidget *preview = gtk_image_new ();
GtkWidget *chooser = gtk_file_chooser_dialog_new("Select", GTK_WINDOW(window),
GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
+
+ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(chooser), gtk_entry_get_text(GTK_ENTRY(data->value_entry)));
+ gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER(chooser), preview);
+ g_signal_connect(chooser, "update-preview",
+ G_CALLBACK (update_preview_cb), preview);
+
gint result = gtk_dialog_run(GTK_DIALOG(chooser));
- if(result)
+ if(result == GTK_RESPONSE_ACCEPT)
{
gtk_entry_set_text(GTK_ENTRY(data->value_entry), gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser)));
g_signal_emit_by_name(data->value_entry, "activate");
}
+
gtk_widget_destroy(chooser);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]