[gnumeric] GnmExprEntry::with_icon: simplify.



commit 5233c3ea5b84d5d4e0d00db85c6e9c1ad62e0ab5
Author: Morten Welinder <terra gnome org>
Date:   Mon May 23 12:07:36 2011 -0400

    GnmExprEntry::with_icon: simplify.

 src/widgets/ChangeLog             |    3 +++
 src/widgets/gnumeric-expr-entry.c |   36 +++++++++++++++++++++++-------------
 2 files changed, 26 insertions(+), 13 deletions(-)
---
diff --git a/src/widgets/ChangeLog b/src/widgets/ChangeLog
index d0fe9a3..abe4b3c 100644
--- a/src/widgets/ChangeLog
+++ b/src/widgets/ChangeLog
@@ -1,5 +1,8 @@
 2011-05-23  Morten Welinder  <terra gnome org>
 
+	* gnumeric-expr-entry.c (gee_set_with_icon): Extract from
+	gee_set_property and do nothing if nothing changes.
+
 	* widget-font-selector.c (font_selector_get_pango)
 	(font_selector_set_from_pango): Unused.  Remove.
 
diff --git a/src/widgets/gnumeric-expr-entry.c b/src/widgets/gnumeric-expr-entry.c
index f948805..8a2c210 100644
--- a/src/widgets/gnumeric-expr-entry.c
+++ b/src/widgets/gnumeric-expr-entry.c
@@ -440,6 +440,28 @@ gee_set_format (GnmExprEntry *gee, GOFormat const *fmt)
 }
 
 static void
+gee_set_with_icon (GnmExprEntry *gee, gboolean with_icon)
+{
+	gboolean has_icon = (gee->icon != NULL);
+	with_icon = !!with_icon;
+
+	if (has_icon == with_icon)
+		return;
+
+	if (with_icon) {
+		gee->icon = gtk_toggle_button_new ();
+		gtk_container_add (GTK_CONTAINER (gee->icon),
+				   gtk_image_new_from_stock ("Gnumeric_ExprEntry",
+							     GTK_ICON_SIZE_MENU));
+		gtk_box_pack_end (GTK_BOX (gee), gee->icon, FALSE, FALSE, 0);
+		gtk_widget_show_all (gee->icon);
+		g_signal_connect (gee->icon, "clicked",
+				  G_CALLBACK (cb_icon_clicked), gee);
+	} else
+		gtk_widget_destroy (gee->icon);
+}
+
+static void
 gee_set_property (GObject      *object,
 		  guint         prop_id,
 		  GValue const *value,
@@ -452,19 +474,7 @@ gee_set_property (GObject      *object,
 		break;
 
 	case PROP_WITH_ICON:
-		if (g_value_get_boolean (value)) {
-			if (gee->icon == NULL) {
-				gee->icon = gtk_toggle_button_new ();
-				gtk_container_add (GTK_CONTAINER (gee->icon),
-						   gtk_image_new_from_stock ("Gnumeric_ExprEntry",
-							   		     GTK_ICON_SIZE_MENU));
-				gtk_box_pack_end (GTK_BOX (gee), gee->icon, FALSE, FALSE, 0);
-				gtk_widget_show_all (gee->icon);
-				g_signal_connect (gee->icon, "clicked",
-						  G_CALLBACK (cb_icon_clicked), gee);
-			}
-		} else if (gee->icon != NULL)
-			gtk_widget_destroy (gee->icon);
+		gee_set_with_icon (gee, g_value_get_boolean (value));
 		break;
 
 	case PROP_TEXT: {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]