[yelp] [yelp-location-entry] Adding bookmark tags in completion drop-down
- From: Shaun McCance <shaunm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [yelp] [yelp-location-entry] Adding bookmark tags in completion drop-down
- Date: Fri, 7 May 2010 23:28:06 +0000 (UTC)
commit e8f780133384968182fbd77dd9db668984b772be
Author: Shaun McCance <shaunm gnome org>
Date: Fri May 7 18:27:50 2010 -0500
[yelp-location-entry] Adding bookmark tags in completion drop-down
libyelp/yelp-location-entry.c | 48 +++++++++++++++++++++++++++++++++++------
libyelp/yelp-location-entry.h | 3 +-
src/yelp-window.c | 36 +++++++++++++++++++++++++++---
3 files changed, 75 insertions(+), 12 deletions(-)
---
diff --git a/libyelp/yelp-location-entry.c b/libyelp/yelp-location-entry.c
index 8a63adc..187f6bf 100644
--- a/libyelp/yelp-location-entry.c
+++ b/libyelp/yelp-location-entry.c
@@ -121,6 +121,11 @@ static void cell_set_bookmark_icon (GtkCellLayout *layout,
YelpLocationEntry *entry);
/* GtkEntryCompletion callbacks */
+static void cell_set_completion_bookmark_icon (GtkCellLayout *layout,
+ GtkCellRenderer *cell,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ YelpLocationEntry *entry);
static void cell_set_completion_text_cell (GtkCellLayout *layout,
GtkCellRenderer *cell,
GtkTreeModel *model,
@@ -150,10 +155,10 @@ struct _YelpLocationEntryPrivate
guint pulse;
GtkCellRenderer *icon_cell;
- GtkCellRenderer *bookmark_cell;
GtkEntryCompletion *completion;
gint completion_desc_column;
+ gint completion_flags_column;
/* free this, and only this */
GtkTreeRowReference *row;
@@ -333,6 +338,7 @@ yelp_location_entry_class_init (YelpLocationEntryClass *klass)
static void
yelp_location_entry_init (YelpLocationEntry *entry)
{
+ GtkCellRenderer *bookmark_cell;
YelpLocationEntryPrivate *priv = GET_PRIV (entry);
GList *cells;
@@ -370,11 +376,11 @@ yelp_location_entry_init (YelpLocationEntry *entry)
gtk_cell_layout_reorder (GTK_CELL_LAYOUT (entry), priv->icon_cell, 0);
- priv->bookmark_cell = gtk_cell_renderer_pixbuf_new ();
- gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (entry), priv->bookmark_cell, FALSE);
+ bookmark_cell = gtk_cell_renderer_pixbuf_new ();
+ gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (entry), bookmark_cell, FALSE);
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (entry),
- priv->bookmark_cell,
- cell_set_bookmark_icon,
+ bookmark_cell,
+ (GtkCellLayoutDataFunc) cell_set_bookmark_icon,
entry, NULL);
g_signal_connect (entry, "changed",
@@ -533,14 +539,16 @@ yelp_location_entry_set_completion_model (YelpLocationEntry *entry,
GtkTreeModel *model,
gint text_column,
gint desc_column,
- gint icon_column)
+ gint icon_column,
+ gint flags_column)
{
YelpLocationEntryPrivate *priv = GET_PRIV (entry);
GList *cells;
- GtkCellRenderer *icon_cell;
+ GtkCellRenderer *icon_cell, *bookmark_cell;
priv->completion = gtk_entry_completion_new ();
priv->completion_desc_column = desc_column;
+ priv->completion_flags_column = flags_column;
gtk_entry_completion_set_minimum_key_length (priv->completion, 3);
gtk_entry_completion_set_model (priv->completion, model);
gtk_entry_completion_set_text_column (priv->completion, text_column);
@@ -571,6 +579,13 @@ yelp_location_entry_set_completion_model (YelpLocationEntry *entry,
icon_column,
NULL);
+ bookmark_cell = gtk_cell_renderer_pixbuf_new ();
+ gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (priv->completion), bookmark_cell, FALSE);
+ gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->completion),
+ bookmark_cell,
+ (GtkCellLayoutDataFunc) cell_set_completion_bookmark_icon,
+ entry, NULL);
+
gtk_entry_set_completion (GTK_ENTRY (priv->text_entry),
priv->completion);
}
@@ -878,6 +893,25 @@ cell_set_bookmark_icon (GtkCellLayout *layout,
}
static void
+cell_set_completion_bookmark_icon (GtkCellLayout *layout,
+ GtkCellRenderer *cell,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ YelpLocationEntry *entry)
+{
+ gint flags;
+ YelpLocationEntryPrivate *priv = GET_PRIV (entry);
+
+ gtk_tree_model_get (model, iter,
+ priv->completion_flags_column, &flags,
+ -1);
+ if (flags & YELP_LOCATION_ENTRY_IS_BOOKMARKED)
+ g_object_set (cell, "icon-name", "bookmark", NULL);
+ else
+ g_object_set (cell, "icon-name", NULL, NULL);
+}
+
+static void
cell_set_completion_text_cell (GtkCellLayout *layout,
GtkCellRenderer *cell,
GtkTreeModel *model,
diff --git a/libyelp/yelp-location-entry.h b/libyelp/yelp-location-entry.h
index 2ad5b07..37167ad 100644
--- a/libyelp/yelp-location-entry.h
+++ b/libyelp/yelp-location-entry.h
@@ -91,7 +91,8 @@ void yelp_location_entry_set_completion_model (YelpLocationEntry *ent
GtkTreeModel *model,
gint text_column,
gint desc_column,
- gint icon_column);
+ gint icon_column,
+ gint flags_column);
void yelp_location_entry_start_search (YelpLocationEntry *entry);
diff --git a/src/yelp-window.c b/src/yelp-window.c
index faeccd8..b0eb5b6 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -170,7 +170,8 @@ enum {
COMPLETION_COL_TITLE,
COMPLETION_COL_DESC,
COMPLETION_COL_ICON,
- COMPLETION_COL_PAGE
+ COMPLETION_COL_PAGE,
+ COMPLETION_COL_FLAGS
};
static const gchar *YELP_UI =
@@ -817,6 +818,7 @@ window_set_bookmark_icons (YelpWindow *window)
GtkTreeIter iter;
gchar *page_id;
GHashTable *bookmarks;
+ GtkTreeModel *completion;
YelpWindowPrivate *priv = GET_PRIV (window);
g_object_get (priv->view, "yelp-uri", &uri, NULL);
@@ -857,6 +859,30 @@ window_set_bookmark_icons (YelpWindow *window)
cont = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->history), &iter);
}
+ completion = (GtkTreeModel *) g_hash_table_lookup (completions, doc_uri);
+ if (completion) {
+ gchar *page_id;
+ gint flags;
+ completion = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (completion));
+ cont = gtk_tree_model_get_iter_first (completion, &iter);
+ while (cont) {
+ gtk_tree_model_get (completion, &iter,
+ COMPLETION_COL_PAGE, &page_id,
+ COMPLETION_COL_FLAGS, &flags,
+ -1);
+ if (page_id && g_hash_table_lookup (bookmarks, page_id)) {
+ flags |= YELP_LOCATION_ENTRY_IS_BOOKMARKED;
+ }
+ else {
+ flags &= ~YELP_LOCATION_ENTRY_IS_BOOKMARKED;
+ }
+ gtk_list_store_set (GTK_LIST_STORE (completion), &iter,
+ COMPLETION_COL_FLAGS, flags,
+ -1);
+ cont = gtk_tree_model_iter_next (completion, &iter);
+ }
+ }
+
g_hash_table_destroy (bookmarks);
g_free (doc_uri);
g_object_unref (uri);
@@ -1288,11 +1314,12 @@ view_loaded (YelpView *view,
completion = (GtkTreeModel *) g_hash_table_lookup (completions, doc_uri);
if (completion == NULL) {
- GtkListStore *base = gtk_list_store_new (4,
+ GtkListStore *base = gtk_list_store_new (5,
G_TYPE_STRING, /* title */
G_TYPE_STRING, /* desc */
G_TYPE_STRING, /* icon */
- G_TYPE_STRING /* uri */
+ G_TYPE_STRING, /* uri */
+ G_TYPE_INT /* flags */
);
completion = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (base));
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (completion),
@@ -1328,7 +1355,8 @@ view_loaded (YelpView *view,
GTK_TREE_MODEL (completion),
COMPLETION_COL_TITLE,
COMPLETION_COL_DESC,
- COMPLETION_COL_ICON);
+ COMPLETION_COL_ICON,
+ COMPLETION_COL_FLAGS);
window_set_bookmark_icons (window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]