[nautilus-actions] Add a preview when selecting an icon
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Add a preview when selecting an icon
- Date: Thu, 2 Dec 2010 23:51:39 +0000 (UTC)
commit 4795ab2c20b38df00e4e45b6661a3281bd007e53
Author: Pierre Wieser <pwieser trychlos org>
Date: Thu Dec 2 20:37:57 2010 +0100
Add a preview when selecting an icon
ChangeLog | 7 +++++++
src/nact/nact-gtk-utils.c | 39 +++++++++++++++++++++++++++++++++++++++
src/nact/nact-gtk-utils.h | 6 ++++++
src/nact/nact-iaction-tab.c | 25 +++++++++++++++++++++++--
4 files changed, 75 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6c6ccda..fe1bc88 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2010-12-02 Pierre Wieser <pwieser trychlos org>
+ * src/nact/nact-gtk-utils.c:
+ * src/nact/nact-gtk-utils.h (nact_gtk_utils_select_file_with_preview):
+ New function.
+
+ * src/nact/nact-iaction-tab.c (on_icon_browse):
+ Add a preview when selecting an icon.
+
Factorize help description.
* po/POTFILES.in: add src/utils/console-utils.c file.
diff --git a/src/nact/nact-gtk-utils.c b/src/nact/nact-gtk-utils.c
index 996dd7f..1c0ab1b 100644
--- a/src/nact/nact-gtk-utils.c
+++ b/src/nact/nact-gtk-utils.c
@@ -268,12 +268,45 @@ nact_gtk_utils_select_file( BaseWindow *window,
GtkWidget *entry, const gchar *entry_name,
const gchar *default_dir_uri )
{
+ nact_gtk_utils_select_file_with_preview(
+ window, title, dialog_name, entry, entry_name, default_dir_uri, NULL );
+}
+
+/**
+ * nact_gtk_utils_select_file_with_preview:
+ * @window: the #BaseWindow which will be the parent of the dialog box.
+ * @title: the title of the dialog box.
+ * @dialog_name: the name of the dialog box in Preferences to read/write
+ * its size and position.
+ * @entry: the #GtkEntry which is associated with the selected file.
+ * @entry_name: the name of the entry in Preferences to be readen/written.
+ * @default_dir_uri: the URI of the directory which should be set if there is
+ * not yet any preference (see @entry_name)
+ * @update_preview_cb: the callback function in charge of updating the
+ * preview widget. May be NULL.
+ *
+ * Opens a #GtkFileChooserDialog and let the user choose an existing file
+ * -> choose and display an existing file name
+ * -> record the dirname URI.
+ *
+ * If the user validates its selection, the choosen file pathname will be
+ * written in the @entry #GtkEntry, while the corresponding dirname
+ * URI will be written as @entry_name in Preferences.
+ */
+void
+nact_gtk_utils_select_file_with_preview( BaseWindow *window,
+ const gchar *title, const gchar *dialog_name,
+ GtkWidget *entry, const gchar *entry_name,
+ const gchar *default_dir_uri,
+ GCallback update_preview_cb )
+{
NactApplication *application;
NAUpdater *updater;
GtkWindow *toplevel;
GtkWidget *dialog;
const gchar *text;
gchar *filename, *uri;
+ GtkWidget *preview;
application = NACT_APPLICATION( base_window_get_application( window ));
updater = nact_application_get_updater( application );
@@ -288,6 +321,12 @@ nact_gtk_utils_select_file( BaseWindow *window,
NULL
);
+ if( update_preview_cb ){
+ preview = gtk_image_new();
+ gtk_file_chooser_set_preview_widget( GTK_FILE_CHOOSER( dialog ), preview );
+ g_signal_connect( dialog, "update-preview", update_preview_cb, preview );
+ }
+
base_iprefs_position_named_window( window, GTK_WINDOW( dialog ), dialog_name );
text = gtk_entry_get_text( GTK_ENTRY( entry ));
diff --git a/src/nact/nact-gtk-utils.h b/src/nact/nact-gtk-utils.h
index 3c5c995..8414f29 100644
--- a/src/nact/nact-gtk-utils.h
+++ b/src/nact/nact-gtk-utils.h
@@ -60,6 +60,12 @@ void nact_gtk_utils_select_file( BaseWindow *window,
GtkWidget *entry, const gchar *entry_name,
const gchar *default_dir_uri );
+void nact_gtk_utils_select_file_with_preview( BaseWindow *window,
+ const gchar *title, const gchar *dialog_name,
+ GtkWidget *entry, const gchar *entry_name,
+ const gchar *default_dir_uri,
+ GCallback update_preview_cb );
+
void nact_gtk_utils_select_dir( BaseWindow *window,
const gchar *title, const gchar *dialog_name,
GtkWidget *entry, const gchar *entry_name,
diff --git a/src/nact/nact-iaction-tab.c b/src/nact/nact-iaction-tab.c
index b2d2a4c..0632f51 100644
--- a/src/nact/nact-iaction-tab.c
+++ b/src/nact/nact-iaction-tab.c
@@ -98,6 +98,7 @@ static GtkTreeModel *create_stock_icon_model( void );
static void icon_combo_list_fill( GtkComboBoxEntry* combo );
static void on_icon_browse( GtkButton *button, NactIActionTab *instance );
static void on_icon_changed( GtkEntry *entry, NactIActionTab *instance );
+static void icon_preview_cb( GtkFileChooser *dialog, GtkWidget *preview );
static gint sort_stock_ids( gconstpointer a, gconstpointer b );
static gchar *strip_underscore( const gchar *text );
static void release_icon_combobox( NactIActionTab *instance );
@@ -871,10 +872,10 @@ on_icon_browse( GtkButton *button, NactIActionTab *instance )
icon_widget = base_window_get_widget( BASE_WINDOW( instance ), "ActionIconComboBoxEntry" );
- nact_gtk_utils_select_file(
+ nact_gtk_utils_select_file_with_preview(
BASE_WINDOW( instance ),
_( "Choosing an icon" ), IPREFS_ICONS_DIALOG,
- gtk_bin_get_child( GTK_BIN( icon_widget )), IPREFS_ICONS_PATH, "" );
+ gtk_bin_get_child( GTK_BIN( icon_widget )), IPREFS_ICONS_PATH, "", G_CALLBACK( icon_preview_cb ));
}
static void
@@ -907,6 +908,26 @@ on_icon_changed( GtkEntry *icon_entry, NactIActionTab *instance )
nact_gtk_utils_render( icon_name, image, GTK_ICON_SIZE_MENU );
}
+static void
+icon_preview_cb( GtkFileChooser *dialog, GtkWidget *preview )
+{
+ char *filename;
+ GdkPixbuf *pixbuf;
+ gboolean have_preview;
+
+ filename = gtk_file_chooser_get_preview_filename( dialog );
+ pixbuf = gdk_pixbuf_new_from_file_at_size( filename, 128, 128, NULL );
+ have_preview = ( pixbuf != NULL );
+ g_free( filename );
+
+ if( have_preview ){
+ gtk_image_set_from_pixbuf( GTK_IMAGE( preview ), pixbuf );
+ g_object_unref( pixbuf );
+ }
+
+ gtk_file_chooser_set_preview_widget_active( dialog, have_preview );
+}
+
static gint
sort_stock_ids( gconstpointer a, gconstpointer b )
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]