[gtksourceview/gtksourcecompletion] Added "changed" signal to GtkSourceCompletionProposal
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: svn-commits-list gnome org
- Subject: [gtksourceview/gtksourcecompletion] Added "changed" signal to GtkSourceCompletionProposal
- Date: Mon, 20 Apr 2009 05:28:46 -0400 (EDT)
commit 9485ae7e54f51726c5f90a2eaec090487472ca95
Author: Jesse van den Kieboom <jvanden grijpc10 epfl ch>
Date: Mon Apr 20 11:28:32 2009 +0200
Added "changed" signal to GtkSourceCompletionProposal
This makes it possible to easily update information on existing proposals when filtering (e.g. reflecting a different state)
---
gtksourceview/gtksourcecompletionitem.c | 11 +++++++++
gtksourceview/gtksourcecompletionmodel.c | 31 +++++++++++++++++++++++++++
gtksourceview/gtksourcecompletionproposal.c | 30 ++++++++++++++++++++++++-
gtksourceview/gtksourcecompletionproposal.h | 4 +++
4 files changed, 74 insertions(+), 2 deletions(-)
diff --git a/gtksourceview/gtksourcecompletionitem.c b/gtksourceview/gtksourcecompletionitem.c
index a315cd2..06f8b99 100644
--- a/gtksourceview/gtksourcecompletionitem.c
+++ b/gtksourceview/gtksourcecompletionitem.c
@@ -105,6 +105,12 @@ gtk_source_completion_item_get_property (GObject *object,
}
static void
+emit_changed (GtkSourceCompletionItem *item)
+{
+ gtk_source_completion_proposal_changed (GTK_SOURCE_COMPLETION_PROPOSAL (item));
+}
+
+static void
gtk_source_completion_item_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -121,10 +127,14 @@ gtk_source_completion_item_set_property (GObject *object,
case PROP_LABEL:
g_free (self->priv->label);
self->priv->label = g_value_dup_string (value);
+
+ emit_changed (self);
break;
case PROP_INFO:
g_free (self->priv->info);
self->priv->info = g_value_dup_string (value);
+
+ emit_changed (self);
break;
case PROP_ICON:
if (self->priv->icon != NULL)
@@ -133,6 +143,7 @@ gtk_source_completion_item_set_property (GObject *object,
}
self->priv->icon = GDK_PIXBUF (g_value_dup_object (value));
+ emit_changed (self);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
diff --git a/gtksourceview/gtksourcecompletionmodel.c b/gtksourceview/gtksourcecompletionmodel.c
index 5d203db..b5b3014 100644
--- a/gtksourceview/gtksourcecompletionmodel.c
+++ b/gtksourceview/gtksourcecompletionmodel.c
@@ -4,10 +4,13 @@
typedef struct
{
+ GtkSourceCompletionModel *model;
+
GtkSourceCompletionProvider *provider;
GtkSourceCompletionProposal *proposal;
GtkSourceCompletionModelFilterFlag filtered;
+ gulong changed_id;
} ProposalNode;
typedef struct
@@ -505,6 +508,7 @@ free_node (ProposalNode *node)
if (node->proposal != NULL)
{
+ g_signal_handler_disconnect (node->proposal, node->changed_id);
g_object_unref (node->proposal);
}
@@ -656,6 +660,26 @@ append_list (GtkSourceCompletionModel *model,
model->priv->last = item;
}
+static void
+on_proposal_changed (GtkSourceCompletionProposal *proposal,
+ GList *item)
+{
+ GtkTreeIter iter;
+ ProposalNode *node = (ProposalNode *)item->data;
+ GtkTreePath *path;
+
+ if (!node->filtered)
+ {
+ iter.user_data = node;
+ path = path_from_list (node->model, item);
+
+ gtk_tree_model_row_changed (GTK_TREE_MODEL (node->model),
+ path,
+ &iter);
+ gtk_tree_path_free (path);
+ }
+}
+
gboolean
gtk_source_completion_model_append (GtkSourceCompletionModel *model,
GtkSourceCompletionProvider *provider,
@@ -677,6 +701,7 @@ gtk_source_completion_model_append (GtkSourceCompletionModel *model,
if (g_hash_table_lookup (model->priv->num_per_provider, provider) == NULL)
{
header = g_slice_new (ProposalNode);
+ header->model = model;
header->provider = g_object_ref (provider);
header->proposal = NULL;
header->filtered = GTK_SOURCE_COMPLETION_MODEL_FILTERED;
@@ -692,6 +717,7 @@ gtk_source_completion_model_append (GtkSourceCompletionModel *model,
}
node = g_slice_new (ProposalNode);
+ node->model = model;
node->provider = g_object_ref (provider);
node->proposal = g_object_ref (proposal);
@@ -719,6 +745,11 @@ gtk_source_completion_model_append (GtkSourceCompletionModel *model,
}
}
+ node->changed_id = g_signal_connect (proposal,
+ "changed",
+ G_CALLBACK (on_proposal_changed),
+ item);
+
return TRUE;
}
diff --git a/gtksourceview/gtksourcecompletionproposal.c b/gtksourceview/gtksourcecompletionproposal.c
index 02ab307..2e54e9a 100644
--- a/gtksourceview/gtksourcecompletionproposal.c
+++ b/gtksourceview/gtksourcecompletionproposal.c
@@ -38,7 +38,7 @@
/* Signals */
enum
{
- ACTIVATE,
+ CHANGED,
NUM_SIGNALS
};
@@ -72,7 +72,18 @@ gtk_source_completion_proposal_init (GtkSourceCompletionProposalIface *iface)
iface->get_info = gtk_source_completion_proposal_get_info_default;
if (!initialized)
- {
+ {
+ signals[CHANGED] =
+ g_signal_new ("changed",
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (GtkSourceCompletionProposalIface, changed),
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
initialized = TRUE;
}
}
@@ -154,3 +165,18 @@ gtk_source_completion_proposal_get_info (GtkSourceCompletionProposal *proposal)
g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal), NULL);
return GTK_SOURCE_COMPLETION_PROPOSAL_GET_INTERFACE (proposal)->get_info (proposal);
}
+
+/**
+ * gtk_source_completion_proposal_changed:
+ * @proposal: The #GtkSourceCompletionProposal
+ *
+ * Emits the "changed" signal on @proposal. This should be called by
+ * implementations whenever the name, icon or info of the proposal has
+ * changed.
+ */
+void
+gtk_source_completion_proposal_changed (GtkSourceCompletionProposal *proposal)
+{
+ g_return_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal));
+ g_signal_emit (proposal, signals[CHANGED], 0);
+}
diff --git a/gtksourceview/gtksourcecompletionproposal.h b/gtksourceview/gtksourcecompletionproposal.h
index 1775751..aa50686 100644
--- a/gtksourceview/gtksourcecompletionproposal.h
+++ b/gtksourceview/gtksourcecompletionproposal.h
@@ -46,6 +46,8 @@ struct _GtkSourceCompletionProposalIface
GdkPixbuf *(*get_icon) (GtkSourceCompletionProposal *proposal);
const gchar *(*get_info) (GtkSourceCompletionProposal *proposal);
+ /* Signals */
+ void (*changed) (GtkSourceCompletionProposal *proposal);
};
GType gtk_source_completion_proposal_get_type (void) G_GNUC_CONST;
@@ -54,6 +56,8 @@ const gchar *gtk_source_completion_proposal_get_label (GtkSourceCompletionPropo
GdkPixbuf *gtk_source_completion_proposal_get_icon (GtkSourceCompletionProposal *proposal);
const gchar *gtk_source_completion_proposal_get_info (GtkSourceCompletionProposal *proposal);
+void gtk_source_completion_proposal_changed (GtkSourceCompletionProposal *proposal);
+
G_END_DECLS
#endif /* __GTK_SOURCE_COMPLETION_PROPOSAL_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]