Revision: 1871 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1871&view=re... Author: colombanw Date: 2011-01-23 14:25:10 +0000 (Sun, 23 Jan 2011)
Log Message: ----------- WebHelper: Avoid useless notifications when synchronizing settings from widgets
When synchronizing settings from their display widget, only change the corresponding property if the value actually changed. This avoids useless notifications if the value was not modified.
This is particularly useful because we synchronize on preference dialog validation, but since the dialog is shared by all plugins we might synchronize even when the user has only changed the settings of another plugin.
Modified Paths: -------------- trunk/geany-plugins/webhelper/src/gwh-settings.c
Modified: trunk/geany-plugins/webhelper/src/gwh-settings.c =================================================================== --- trunk/geany-plugins/webhelper/src/gwh-settings.c 2011-01-23 14:24:39 UTC (rev 1870) +++ trunk/geany-plugins/webhelper/src/gwh-settings.c 2011-01-23 14:25:10 UTC (rev 1871) @@ -506,13 +506,16 @@ }
static void -gwh_settings_widget_boolean_sync (GwhSettings *self, - GParamSpec *pspec, - GtkWidget *widget) +gwh_settings_widget_boolean_sync (GwhSettings *self, + GParamSpec *pspec, + const GValue *old_value, + GtkWidget *widget) { - g_object_set (self, pspec->name, - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)), - NULL); + gboolean val = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); + + if (g_value_get_boolean (old_value) != val) { + g_object_set (self, pspec->name, val, NULL); + } }
static void @@ -575,9 +578,10 @@ }
static void -gwh_settings_widget_enum_sync (GwhSettings *self, - GParamSpec *pspec, - GtkWidget *widget) +gwh_settings_widget_enum_sync (GwhSettings *self, + GParamSpec *pspec, + const GValue *old_value, + GtkWidget *widget) { GtkTreeIter iter;
@@ -587,7 +591,9 @@
model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); gtk_tree_model_get (model, &iter, 0, &val, -1); - g_object_set (self, pspec->name, val, NULL); + if (g_value_get_enum (old_value) != val) { + g_object_set (self, pspec->name, val, NULL); + } } }
@@ -623,13 +629,16 @@ }
static void -gwh_settings_widget_int_sync (GwhSettings *self, - GParamSpec *pspec, - GtkWidget *widget) +gwh_settings_widget_int_sync (GwhSettings *self, + GParamSpec *pspec, + const GValue *old_value, + GtkWidget *widget) { - g_object_set (self, pspec->name, - gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget)), - NULL); + gint val = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget)); + + if (g_value_get_int (old_value) != val) { + g_object_set (self, pspec->name, val, NULL); + } }
static void @@ -665,12 +674,17 @@ }
static void -gwh_settings_widget_string_sync (GwhSettings *self, - GParamSpec *pspec, - GtkWidget *widget) +gwh_settings_widget_string_sync (GwhSettings *self, + GParamSpec *pspec, + const GValue *old_value, + GtkWidget *widget) { - g_object_set (self, pspec->name, gtk_entry_get_text (GTK_ENTRY (widget)), - NULL); + const gchar *val = gtk_entry_get_text (GTK_ENTRY (widget)); + const gchar *old_val = g_value_get_string (old_value); + + if (g_strcmp0 (old_val, val) != 0) { + g_object_set (self, pspec->name, val, NULL); + } }
@@ -783,6 +797,7 @@ GtkWidget *widget) { GParamSpec *pspec; + GValue value = {0};
g_return_val_if_fail (G_IS_OBJECT (widget), FALSE);
@@ -790,10 +805,12 @@ g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); pspec = g_object_get_data (G_OBJECT (widget), KEY_PSPEC); g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE); + g_value_init (&value, pspec->value_type); + g_object_get_property (G_OBJECT (self), pspec->name, &value); switch (G_TYPE_FUNDAMENTAL (pspec->value_type)) { #define HANDLE_TYPE(T, t) \ case G_TYPE_##T: \ - gwh_settings_widget_##t##_sync (self, pspec, widget); \ + gwh_settings_widget_##t##_sync (self, pspec, &value, widget); \ break;
HANDLE_TYPE (BOOLEAN, boolean) @@ -807,6 +824,7 @@ g_critical ("Unsupported property type "%s"", g_type_name (pspec->value_type)); } + g_value_unset (&value);
return TRUE; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.