[gtksourceview/gtksourcecompletion] Add equals and get_hash methods to proposal.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: svn-commits-list gnome org
- Subject: [gtksourceview/gtksourcecompletion] Add equals and get_hash methods to proposal.
- Date: Tue, 23 Jun 2009 05:32:16 -0400 (EDT)
commit 39fc584a79a091220548578c7660151474ff0708
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Wed Jun 10 20:04:46 2009 +0200
Add equals and get_hash methods to proposal.
gtksourceview/gtksourcecompletion.c | 6 +-
gtksourceview/gtksourcecompletionmodel.c | 41 +--------------
gtksourceview/gtksourcecompletionproposal.c | 72 +++++++++++++++++++++++++++
gtksourceview/gtksourcecompletionproposal.h | 8 +++
4 files changed, 85 insertions(+), 42 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 825c7de..b639c7e 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -1301,6 +1301,9 @@ gtk_source_completion_set_property (GObject *object,
static void
gtk_source_completion_hide_default (GtkSourceCompletion *completion)
{
+ gtk_widget_hide (completion->priv->info_window);
+ gtk_widget_hide (completion->priv->window);
+
completion->priv->filter_provider = NULL;
gtk_label_set_markup (GTK_LABEL (completion->priv->default_info), "");
@@ -1311,9 +1314,6 @@ gtk_source_completion_hide_default (GtkSourceCompletion *completion)
completion->priv->active_providers = NULL;
completion->priv->info_visible = GTK_WIDGET_VISIBLE (completion->priv->info_window);
-
- gtk_widget_hide (completion->priv->info_window);
- gtk_widget_hide (completion->priv->window);
}
static void
diff --git a/gtksourceview/gtksourcecompletionmodel.c b/gtksourceview/gtksourcecompletionmodel.c
index b70dcc4..de4e9cd 100644
--- a/gtksourceview/gtksourcecompletionmodel.c
+++ b/gtksourceview/gtksourcecompletionmodel.c
@@ -479,59 +479,22 @@ free_num (gpointer data)
g_slice_free (HeaderInfo, data);
}
-/* We are going to compare only the label, if the label is the same the elements
- * are the same, but in case anything else changed like the pixbuf or the changed
- * we are going to substitute the previous element by the new one */
- /* FIXME: add a equal func to be implemented by the user */
static gboolean
compare_nodes (gconstpointer a,
gconstpointer b)
{
ProposalNode *p1 = (ProposalNode *)a;
ProposalNode *p2 = (ProposalNode *)b;
- const gchar *label1, *label2;
- label1 = gtk_source_completion_proposal_get_markup (p1->proposal);
- label2 = gtk_source_completion_proposal_get_markup (p2->proposal);
-
- if (label1 != NULL && label2 == NULL)
- {
- return FALSE;
- }
- else if (label2 != NULL && label1 == NULL)
- {
- return FALSE;
- }
- else if (label1 == NULL && label2 == NULL)
- {
- label1 = gtk_source_completion_proposal_get_label (p1->proposal);
- label2 = gtk_source_completion_proposal_get_label (p2->proposal);
- }
-
- if (g_strcmp0 (label1, label2) == 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
+ return gtk_source_completion_proposal_equals (p1->proposal, p2->proposal);
}
static guint
hash_node (gconstpointer v)
{
ProposalNode *node = (ProposalNode *)v;
- const gchar *label;
-
- label = gtk_source_completion_proposal_get_markup (node->proposal);
-
- if (label == NULL)
- {
- label = gtk_source_completion_proposal_get_label (node->proposal);
- }
- return g_str_hash (label);
+ return gtk_source_completion_proposal_get_hash (node->proposal);
}
static void
diff --git a/gtksourceview/gtksourcecompletionproposal.c b/gtksourceview/gtksourcecompletionproposal.c
index fd1352e..2bfc8ee 100644
--- a/gtksourceview/gtksourcecompletionproposal.c
+++ b/gtksourceview/gtksourcecompletionproposal.c
@@ -74,6 +74,59 @@ gtk_source_completion_proposal_get_info_default (GtkSourceCompletionProposal *pr
return NULL;
}
+static guint
+gtk_source_completion_proposal_get_hash_default (GtkSourceCompletionProposal *proposal)
+{
+ const gchar *label;
+
+ label = gtk_source_completion_proposal_get_label (proposal);
+
+ if (label == NULL)
+ label = gtk_source_completion_proposal_get_markup (proposal);
+
+ if (label != NULL)
+ return g_str_hash (label);
+ else
+ g_return_val_if_reached (0);
+}
+
+static gboolean
+gtk_source_completion_proposal_equals_default (GtkSourceCompletionProposal *proposal1,
+ GtkSourceCompletionProposal *proposal2)
+{
+ const gchar *label1, *label2;
+
+ label1 = gtk_source_completion_proposal_get_markup (proposal1);
+ label2 = gtk_source_completion_proposal_get_markup (proposal2);
+
+ if (label1 != NULL && label2 == NULL)
+ {
+ return FALSE;
+ }
+ else if (label2 != NULL && label1 == NULL)
+ {
+ return FALSE;
+ }
+ else if (label1 == NULL && label2 == NULL)
+ {
+ label1 = gtk_source_completion_proposal_get_label (proposal1);
+ label2 = gtk_source_completion_proposal_get_label (proposal2);
+ }
+
+ if (label1 != NULL && label2 != NULL)
+ {
+ /* FIXME: g_utf8_collate ??? */
+ if (g_strcmp0 (label1, label2) == 0)
+ return TRUE;
+ else
+ return FALSE;
+ }
+ else
+ {
+ g_return_val_if_reached (FALSE);
+ }
+}
+
static void
gtk_source_completion_proposal_init (GtkSourceCompletionProposalIface *iface)
{
@@ -86,6 +139,9 @@ gtk_source_completion_proposal_init (GtkSourceCompletionProposalIface *iface)
iface->get_icon = gtk_source_completion_proposal_get_icon_default;
iface->get_info = gtk_source_completion_proposal_get_info_default;
+ iface->get_hash = gtk_source_completion_proposal_get_hash_default;
+ iface->equals = gtk_source_completion_proposal_equals_default;
+
if (!initialized)
{
/**
@@ -226,6 +282,22 @@ gtk_source_completion_proposal_get_info (GtkSourceCompletionProposal *proposal)
return GTK_SOURCE_COMPLETION_PROPOSAL_GET_INTERFACE (proposal)->get_info (proposal);
}
+guint
+gtk_source_completion_proposal_get_hash (GtkSourceCompletionProposal *proposal)
+{
+ g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal), 0);
+ return GTK_SOURCE_COMPLETION_PROPOSAL_GET_INTERFACE (proposal)->get_hash (proposal);
+}
+
+gboolean
+gtk_source_completion_proposal_equals (GtkSourceCompletionProposal *proposal1,
+ GtkSourceCompletionProposal *proposal2)
+{
+ g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal1), FALSE);
+ g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal2), FALSE);
+ return GTK_SOURCE_COMPLETION_PROPOSAL_GET_INTERFACE (proposal1)->equals (proposal1, proposal2);
+}
+
/**
* gtk_source_completion_proposal_changed:
* @proposal: A #GtkSourceCompletionProposal
diff --git a/gtksourceview/gtksourcecompletionproposal.h b/gtksourceview/gtksourcecompletionproposal.h
index abb147a..6ddcaa8 100644
--- a/gtksourceview/gtksourcecompletionproposal.h
+++ b/gtksourceview/gtksourcecompletionproposal.h
@@ -49,6 +49,10 @@ struct _GtkSourceCompletionProposalIface
GdkPixbuf *(*get_icon) (GtkSourceCompletionProposal *proposal);
const gchar *(*get_info) (GtkSourceCompletionProposal *proposal);
+ guint (*get_hash) (GtkSourceCompletionProposal *proposal);
+ gboolean (*equals) (GtkSourceCompletionProposal *proposal1,
+ GtkSourceCompletionProposal *proposal2);
+
/* Signals */
void (*changed) (GtkSourceCompletionProposal *proposal);
};
@@ -62,6 +66,10 @@ const gchar *gtk_source_completion_proposal_get_text (GtkSourceCompletionPropos
GdkPixbuf *gtk_source_completion_proposal_get_icon (GtkSourceCompletionProposal *proposal);
const gchar *gtk_source_completion_proposal_get_info (GtkSourceCompletionProposal *proposal);
+guint gtk_source_completion_proposal_get_hash (GtkSourceCompletionProposal *proposal);
+gboolean gtk_source_completion_proposal_equals (GtkSourceCompletionProposal *proposal1,
+ GtkSourceCompletionProposal *proposal2);
+
void gtk_source_completion_proposal_changed (GtkSourceCompletionProposal *proposal);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]