[glade/gbinding] Add "invalidate" signal to GladeProperty
- From: Denis Washington <denisw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade/gbinding] Add "invalidate" signal to GladeProperty
- Date: Tue, 20 Dec 2011 16:55:20 +0000 (UTC)
commit aa4bf12f62d914ad53378bf78d112e0fffd574ad
Author: Denis Washington <denisw src gnome org>
Date: Tue Dec 20 17:46:01 2011 +0100
Add "invalidate" signal to GladeProperty
This is supposed to be signalled whenever a property gets invalid,
e.g. when switching a GtkLabel to use a pixbuf instead of a stock
icon. Binding target properties use this to remove any property
bindings that become invalid this way.
The signal is emitted when glade_property_invalidate() is called.
Currently, the GladeEntryEditor does this, so binding a property
to an entry's "Text" and then changing the entry to use a "Buffer"
correctly removes the binding. More callers will follow.
gladeui/glade-marshallers.list | 1 +
gladeui/glade-property.c | 68 +++++++++++++++++++++++++++++++++---
gladeui/glade-property.h | 5 ++-
plugins/gtk+/glade-entry-editor.c | 8 ++++
4 files changed, 75 insertions(+), 7 deletions(-)
---
diff --git a/gladeui/glade-marshallers.list b/gladeui/glade-marshallers.list
index 4b727dd..4b2129b 100644
--- a/gladeui/glade-marshallers.list
+++ b/gladeui/glade-marshallers.list
@@ -3,6 +3,7 @@ VOID:POINTER
VOID:STRING,ULONG,UINT,STRING
VOID:OBJECT
VOID:STRING
+VOID:VOID
VOID:INT,INT
VOID:OBJECT,OBJECT
VOID:OBJECT,BOOLEAN
diff --git a/gladeui/glade-property.c b/gladeui/glade-property.c
index 7ec2726..df23b37 100644
--- a/gladeui/glade-property.c
+++ b/gladeui/glade-property.c
@@ -111,6 +111,10 @@ struct _GladePropertyPrivate {
GList *binding_targets; /* The properties that this property is the binding
source of */
+ gulong binding_invalidated_id; /* Signal handler that removes invalidated
+ * property bindings
+ */
+
/* For resolving a binding source read from a project file */
gchar *binding_source_object_name;
gchar *binding_source_property_name;
@@ -128,6 +132,7 @@ enum
{
VALUE_CHANGED,
TOOLTIP_CHANGED,
+ INVALIDATED,
LAST_SIGNAL
};
@@ -738,6 +743,16 @@ glade_property_klass_init (GladePropertyKlass * prop_class)
G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING);
+ glade_property_signals[INVALIDATED] =
+ g_signal_new ("invalidated",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GladePropertyKlass,
+ invalidated),
+ NULL, NULL,
+ _glade_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
g_type_class_add_private (prop_class, sizeof (GladePropertyPrivate));
}
@@ -1731,6 +1746,16 @@ glade_property_get_state (GladeProperty *property)
return property->priv->state;
}
+void
+glade_property_invalidate (GladeProperty *property)
+{
+ g_return_if_fail (GLADE_IS_PROPERTY (property));
+
+ g_signal_emit (G_OBJECT (property),
+ glade_property_signals[INVALIDATED],
+ 0);
+}
+
GladeProperty *
glade_property_get_binding_source (GladeProperty *property)
{
@@ -1739,6 +1764,30 @@ glade_property_get_binding_source (GladeProperty *property)
return property->priv->binding_source;
}
+static void
+glade_property_add_binding_target (GladeProperty *property,
+ GladeProperty *target)
+{
+ if (!g_list_find (property->priv->binding_targets, property))
+ property->priv->binding_targets =
+ g_list_prepend (property->priv->binding_targets, target);
+}
+
+static void
+glade_property_remove_binding_target (GladeProperty *property,
+ GladeProperty *target)
+{
+ property->priv->binding_targets =
+ g_list_remove (property->priv->binding_targets, target);
+}
+
+static void
+glade_property_binding_invalidated (GladeProperty *binding_source,
+ GladeProperty *property)
+{
+ glade_command_bind_property (property, NULL);
+}
+
void
glade_property_set_binding_source (GladeProperty *property,
GladeProperty *binding_source)
@@ -1763,15 +1812,22 @@ glade_property_set_binding_source (GladeProperty *property,
g_return_if_fail (glade_widget_in_project (source_widget));
g_return_if_fail (g_type_is_a (G_PARAM_SPEC_TYPE (source_pspec),
G_PARAM_SPEC_TYPE (prop_pspec)));
-
- if (!g_list_find (binding_source->priv->binding_targets, property))
- binding_source->priv->binding_targets =
- g_list_prepend (binding_source->priv->binding_targets, property);
}
if ((old_source = property->priv->binding_source) != NULL)
- old_source->priv->binding_targets =
- g_list_remove (old_source->priv->binding_targets, property);
+ {
+ glade_property_remove_binding_target (old_source, property);
+ g_signal_handler_disconnect (old_source,
+ property->priv->binding_invalidated_id);
+ }
+ if (binding_source)
+ {
+ glade_property_add_binding_target (binding_source, property);
+ property->priv->binding_invalidated_id =
+ g_signal_connect (binding_source, "invalidated",
+ G_CALLBACK (glade_property_binding_invalidated),
+ property);
+ }
property->priv->binding_source = binding_source;
g_object_notify_by_pspec (G_OBJECT (property), properties[PROP_BINDING_SOURCE]);
diff --git a/gladeui/glade-property.h b/gladeui/glade-property.h
index e7f649b..d270614 100644
--- a/gladeui/glade-property.h
+++ b/gladeui/glade-property.h
@@ -50,12 +50,13 @@ struct _GladePropertyKlass
void (* value_changed) (GladeProperty *, GValue *, GValue *);
void (* tooltip_changed) (GladeProperty *, const gchar *,
const gchar *, const gchar *);
+ void (* invalidated) (GladeProperty *);
+
void (* glade_reserved1) (void);
void (* glade_reserved2) (void);
void (* glade_reserved3) (void);
void (* glade_reserved4) (void);
void (* glade_reserved5) (void);
- void (* glade_reserved6) (void);
};
@@ -167,6 +168,8 @@ GValue *glade_property_inline_value (GladeProperty
GladePropertyState glade_property_get_state (GladeProperty *property);
+void glade_property_invalidate (GladeProperty *property);
+
GladeProperty *glade_property_get_binding_source (GladeProperty *property);
void glade_property_set_binding_source (GladeProperty *property,
diff --git a/plugins/gtk+/glade-entry-editor.c b/plugins/gtk+/glade-entry-editor.c
index 86320da..940742b 100644
--- a/plugins/gtk+/glade-entry-editor.c
+++ b/plugins/gtk+/glade-entry-editor.c
@@ -194,6 +194,7 @@ text_toggled (GtkWidget * widget, GladeEntryEditor * entry_editor)
glade_widget_get_name (gwidget));
property = glade_widget_get_property (gwidget, "buffer");
+ glade_property_invalidate (property);
glade_command_set_property (property, NULL);
property =
@@ -236,6 +237,7 @@ buffer_toggled (GtkWidget * widget, GladeEntryEditor * entry_editor)
/* Reset the text while still in static text mode */
property = glade_widget_get_property (gwidget, "text");
+ glade_property_invalidate (property);
glade_command_set_property (property, NULL);
property =
@@ -264,8 +266,10 @@ set_stock_mode (GladeEntryEditor * entry_editor, gboolean primary)
GValue value = { 0, };
property = glade_widget_get_property (gwidget, ICON_NAME_NAME (primary));
+ glade_property_invalidate (property);
glade_command_set_property (property, NULL);
property = glade_widget_get_property (gwidget, PIXBUF_NAME (primary));
+ glade_property_invalidate (property);
glade_command_set_property (property, NULL);
property = glade_widget_get_property (gwidget, STOCK_NAME (primary));
@@ -284,8 +288,10 @@ set_icon_name_mode (GladeEntryEditor * entry_editor, gboolean primary)
GladeWidget *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (entry_editor));
property = glade_widget_get_property (gwidget, STOCK_NAME (primary));
+ glade_property_invalidate (property);
glade_command_set_property (property, NULL);
property = glade_widget_get_property (gwidget, PIXBUF_NAME (primary));
+ glade_property_invalidate (property);
glade_command_set_property (property, NULL);
property = glade_widget_get_property (gwidget, ICON_MODE_NAME (primary));
glade_command_set_property (property, GLADE_IMAGE_MODE_ICON);
@@ -298,9 +304,11 @@ set_pixbuf_mode (GladeEntryEditor * entry_editor, gboolean primary)
GladeWidget *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (entry_editor));
property = glade_widget_get_property (gwidget, STOCK_NAME (primary));
+ glade_property_invalidate (property);
glade_command_set_property (property, NULL);
property = glade_widget_get_property (gwidget, ICON_NAME_NAME (primary));
+ glade_property_invalidate (property);
glade_command_set_property (property, NULL);
property = glade_widget_get_property (gwidget, ICON_MODE_NAME (primary));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]