[epiphany] EphyTopicsPalette: Inherit from GtkListStore, not from GtkTreeView.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] EphyTopicsPalette: Inherit from GtkListStore, not from GtkTreeView.
- Date: Sat, 21 Nov 2015 00:26:10 +0000 (UTC)
commit 31781e055e8ad808c03c2fcfd60fd98525d28c55
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sun Nov 8 07:52:19 2015 +0100
EphyTopicsPalette: Inherit from GtkListStore, not from GtkTreeView.
https://bugzilla.gnome.org/show_bug.cgi?id=757669
src/bookmarks/ephy-bookmark-properties.c | 10 ++--
src/bookmarks/ephy-topics-palette.c | 105 +++++++++++++----------------
src/bookmarks/ephy-topics-palette.h | 5 +-
3 files changed, 54 insertions(+), 66 deletions(-)
---
diff --git a/src/bookmarks/ephy-bookmark-properties.c b/src/bookmarks/ephy-bookmark-properties.c
index c7735a7..85a99ff 100644
--- a/src/bookmarks/ephy-bookmark-properties.c
+++ b/src/bookmarks/ephy-bookmark-properties.c
@@ -68,8 +68,8 @@ struct _EphyBookmarkProperties
GtkScrolledWindow *topics_scrolled_window;
GtkLabel *warning_label;
- /* slave */
- EphyTopicsPalette *palette;
+ /* model */
+ EphyTopicsPalette *topics_model;
};
enum
@@ -267,7 +267,7 @@ on_topic_edited (GtkCellRendererText *renderer,
}
else
{
- ephy_topics_palette_update_list (EPHY_TOPICS_PALETTE (properties->topics_tree_view)); //
TODO hack
+ ephy_topics_palette_update_list (properties->topics_model);
}
}
@@ -381,8 +381,8 @@ ephy_bookmark_properties_constructor (GType type,
gtk_tree_view_set_row_separator_func (properties->topics_tree_view, is_separator, NULL, NULL);
- properties->palette = ephy_topics_palette_new (properties->bookmarks, properties->bookmark);
- gtk_tree_view_set_model (properties->topics_tree_view, GTK_TREE_MODEL (ephy_topics_palette_get_store
(properties->palette)));
+ properties->topics_model = ephy_topics_palette_new (properties->bookmarks, properties->bookmark);
+ gtk_tree_view_set_model (properties->topics_tree_view, GTK_TREE_MODEL (properties->topics_model));
/* TODO bind; and the entry?! */
gtk_widget_set_sensitive (GTK_WIDGET (properties->topics_scrolled_window), !lockdown);
diff --git a/src/bookmarks/ephy-topics-palette.c b/src/bookmarks/ephy-topics-palette.c
index e485a8f..f6165d9 100644
--- a/src/bookmarks/ephy-topics-palette.c
+++ b/src/bookmarks/ephy-topics-palette.c
@@ -32,12 +32,13 @@
struct _EphyTopicsPalette
{
- GtkTreeView parent_instance;
+ GtkListStore parent_instance;
+ /* construct properties */
EphyBookmarks *bookmarks;
EphyNode *bookmark;
- GtkListStore *store;
- GtkTreeViewColumn *column;
+
+ /* non-construct property */
int mode;
};
@@ -56,10 +57,10 @@ enum
MODES
};
-G_DEFINE_TYPE (EphyTopicsPalette, ephy_topics_palette, GTK_TYPE_TREE_VIEW)
+G_DEFINE_TYPE (EphyTopicsPalette, ephy_topics_palette, GTK_TYPE_LIST_STORE)
static void
-append_topics (EphyTopicsPalette *palette,
+append_topics (EphyTopicsPalette *self,
GtkTreeIter *iter,
gboolean *valid,
gboolean *first,
@@ -76,12 +77,12 @@ append_topics (EphyTopicsPalette *palette,
if (!*first)
{
- if (!*valid) gtk_list_store_append (palette->store, iter);
- gtk_list_store_set (palette->store, iter,
+ if (!*valid) gtk_list_store_append (GTK_LIST_STORE (self), iter);
+ gtk_list_store_set (GTK_LIST_STORE (self), iter,
EPHY_TOPICS_PALETTE_COLUMN_TITLE, NULL,
EPHY_TOPICS_PALETTE_COLUMN_NODE, NULL,
-1);
- *valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (palette->store), iter);
+ *valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (self), iter);
}
for (i = 0; i < topics->len ; i++)
@@ -89,19 +90,19 @@ append_topics (EphyTopicsPalette *palette,
node = g_ptr_array_index (topics, i);
title = ephy_node_get_property_string (node, EPHY_NODE_KEYWORD_PROP_NAME);
- if (!*valid) gtk_list_store_append (palette->store, iter);
- gtk_list_store_set (palette->store, iter,
+ if (!*valid) gtk_list_store_append (GTK_LIST_STORE (self), iter);
+ gtk_list_store_set (GTK_LIST_STORE (self), iter,
EPHY_TOPICS_PALETTE_COLUMN_TITLE, title,
EPHY_TOPICS_PALETTE_COLUMN_NODE, node,
- EPHY_TOPICS_PALETTE_COLUMN_SELECTED, ephy_node_has_child (node,
palette->bookmark),
+ EPHY_TOPICS_PALETTE_COLUMN_SELECTED, ephy_node_has_child (node,
self->bookmark),
-1);
- *valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (palette->store), iter);
+ *valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (self), iter);
*first = FALSE;
}
}
void
-ephy_topics_palette_update_list (EphyTopicsPalette *palette)
+ephy_topics_palette_update_list (EphyTopicsPalette *self)
{
GPtrArray *children, *bookmarks, *topics;
EphyNode *node;
@@ -109,14 +110,13 @@ ephy_topics_palette_update_list (EphyTopicsPalette *palette)
gint i, priority;
gboolean valid, first;
- gtk_widget_queue_draw (GTK_WIDGET (palette));
- valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (palette->store), &iter);
+ valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self), &iter);
first = TRUE;
- if (palette->mode == MODE_LIST)
+ if (self->mode == MODE_LIST)
{
/* Allocate and fill the suggestions array. */
- node = ephy_bookmarks_get_keywords (palette->bookmarks);
+ node = ephy_bookmarks_get_keywords (self->bookmarks);
children = ephy_node_get_children (node);
topics = g_ptr_array_sized_new (children->len);
for (i = 0; i < children->len; i++)
@@ -131,15 +131,15 @@ ephy_topics_palette_update_list (EphyTopicsPalette *palette)
}
g_ptr_array_sort (topics, ephy_bookmarks_compare_topic_pointers);
- append_topics (palette, &iter, &valid, &first, topics);
+ append_topics (self, &iter, &valid, &first, topics);
g_ptr_array_free (topics, TRUE);
}
- else if (palette->mode == MODE_GROUPED)
+ else if (self->mode == MODE_GROUPED)
{
GPtrArray *suggested, *selected;
/* Allocate and fill the bookmarks array. */
- node = ephy_bookmarks_get_bookmarks (palette->bookmarks);
+ node = ephy_bookmarks_get_bookmarks (self->bookmarks);
children = ephy_node_get_children (node);
bookmarks = g_ptr_array_sized_new (children->len);
for (i = 0; i < children->len; i++)
@@ -148,7 +148,7 @@ ephy_topics_palette_update_list (EphyTopicsPalette *palette)
}
/* Allocate and fill the topics array. */
- node = ephy_bookmarks_get_keywords (palette->bookmarks);
+ node = ephy_bookmarks_get_keywords (self->bookmarks);
children = ephy_node_get_children (node);
topics = g_ptr_array_sized_new (children->len);
suggested = g_ptr_array_sized_new (children->len);
@@ -162,7 +162,7 @@ ephy_topics_palette_update_list (EphyTopicsPalette *palette)
continue;
/* We'll consider only bookmarks covered by the same topics as our bookmark. */
- if (ephy_node_has_child (node, palette->bookmark))
+ if (ephy_node_has_child (node, self->bookmark))
{
ephy_nodes_remove_not_covered (node, bookmarks);
g_ptr_array_add (selected, node);
@@ -188,7 +188,7 @@ ephy_topics_palette_update_list (EphyTopicsPalette *palette)
for (i = 0; i < topics->len ; i++)
{
node = g_ptr_array_index (topics, i);
- if (!ephy_node_has_child (node, palette->bookmark) &&
+ if (!ephy_node_has_child (node, self->bookmark) &&
ephy_nodes_covered (node, bookmarks))
{
g_ptr_array_add (suggested, node);
@@ -201,9 +201,9 @@ ephy_topics_palette_update_list (EphyTopicsPalette *palette)
g_ptr_array_sort (selected, ephy_bookmarks_compare_topic_pointers);
g_ptr_array_sort (suggested, ephy_bookmarks_compare_topic_pointers);
g_ptr_array_sort (topics, ephy_bookmarks_compare_topic_pointers);
- append_topics (palette, &iter, &valid, &first, selected);
- append_topics (palette, &iter, &valid, &first, suggested);
- append_topics (palette, &iter, &valid, &first, topics);
+ append_topics (self, &iter, &valid, &first, selected);
+ append_topics (self, &iter, &valid, &first, suggested);
+ append_topics (self, &iter, &valid, &first, topics);
g_ptr_array_free (selected, TRUE);
g_ptr_array_free (suggested, TRUE);
g_ptr_array_free (bookmarks, TRUE);
@@ -212,41 +212,41 @@ ephy_topics_palette_update_list (EphyTopicsPalette *palette)
while (valid)
{
- valid = gtk_list_store_remove (palette->store, &iter);
+ valid = gtk_list_store_remove (GTK_LIST_STORE (self), &iter);
}
}
static void
tree_changed_cb (EphyBookmarks *bookmarks,
- EphyTopicsPalette *palette)
+ EphyTopicsPalette *self)
{
- ephy_topics_palette_update_list (palette);
+ ephy_topics_palette_update_list (self);
}
static void
node_added_cb (EphyNode *parent,
EphyNode *child,
- EphyTopicsPalette *palette)
+ EphyTopicsPalette *self)
{
- ephy_topics_palette_update_list (palette);
+ ephy_topics_palette_update_list (self);
}
static void
node_changed_cb (EphyNode *parent,
EphyNode *child,
guint property_id,
- EphyTopicsPalette *palette)
+ EphyTopicsPalette *self)
{
- ephy_topics_palette_update_list (palette);
+ ephy_topics_palette_update_list (self);
}
static void
node_removed_cb (EphyNode *parent,
EphyNode *child,
guint index,
- EphyTopicsPalette *palette)
+ EphyTopicsPalette *self)
{
- ephy_topics_palette_update_list (palette);
+ ephy_topics_palette_update_list (self);
}
static void
@@ -255,30 +255,30 @@ ephy_topics_palette_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- EphyTopicsPalette *palette = EPHY_TOPICS_PALETTE (object);
+ EphyTopicsPalette *self = EPHY_TOPICS_PALETTE (object);
EphyNode *node;
switch (prop_id)
{
case PROP_BOOKMARKS:
- palette->bookmarks = g_value_get_object (value);
- node = ephy_bookmarks_get_keywords (palette->bookmarks);
+ self->bookmarks = g_value_get_object (value);
+ node = ephy_bookmarks_get_keywords (self->bookmarks);
ephy_node_signal_connect_object (node, EPHY_NODE_CHILD_ADDED,
(EphyNodeCallback) node_added_cb, object);
ephy_node_signal_connect_object (node, EPHY_NODE_CHILD_CHANGED,
(EphyNodeCallback) node_changed_cb, object);
ephy_node_signal_connect_object (node, EPHY_NODE_CHILD_REMOVED,
(EphyNodeCallback) node_removed_cb, object);
- g_signal_connect_object (palette->bookmarks, "tree-changed",
- G_CALLBACK (tree_changed_cb), palette,
+ g_signal_connect_object (self->bookmarks, "tree-changed",
+ G_CALLBACK (tree_changed_cb), self,
G_CONNECT_AFTER);
break;
case PROP_BOOKMARK:
- palette->bookmark = g_value_get_pointer (value);
+ self->bookmark = g_value_get_pointer (value);
break;
case PROP_MODE:
- palette->mode = g_value_get_int (value);
- ephy_topics_palette_update_list (palette);
+ self->mode = g_value_get_int (value);
+ ephy_topics_palette_update_list (self);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -286,12 +286,6 @@ ephy_topics_palette_set_property (GObject *object,
}
}
-GtkListStore *
-ephy_topics_palette_get_store (EphyTopicsPalette *palette)
-{
- return palette->store;
-}
-
static GObject *
ephy_topics_palette_constructor (GType type,
guint n_construct_properties,
@@ -299,24 +293,19 @@ ephy_topics_palette_constructor (GType type,
{
GObject *object;
- EphyTopicsPalette *palette;
+ GType types[3] = { G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN };
object = G_OBJECT_CLASS (ephy_topics_palette_parent_class)->constructor (type,
n_construct_properties,
construct_params);
- palette = EPHY_TOPICS_PALETTE (object);
-
- palette->store = gtk_list_store_new (EPHY_TOPICS_PALETTE_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER,
G_TYPE_BOOLEAN);
- gtk_tree_view_set_model (GTK_TREE_VIEW (object), GTK_TREE_MODEL (palette->store));
- g_object_unref (palette->store);
-
- ephy_topics_palette_update_list (palette);
+ gtk_list_store_set_column_types (GTK_LIST_STORE (object), 3, types);
+ ephy_topics_palette_update_list (EPHY_TOPICS_PALETTE (object));
return object;
}
static void
-ephy_topics_palette_init (EphyTopicsPalette *palette)
+ephy_topics_palette_init (EphyTopicsPalette *self)
{
}
diff --git a/src/bookmarks/ephy-topics-palette.h b/src/bookmarks/ephy-topics-palette.h
index 8dd5c10..6ffa30c 100644
--- a/src/bookmarks/ephy-topics-palette.h
+++ b/src/bookmarks/ephy-topics-palette.h
@@ -30,7 +30,7 @@
G_BEGIN_DECLS
#define EPHY_TYPE_TOPICS_PALETTE (ephy_topics_palette_get_type ())
-G_DECLARE_FINAL_TYPE (EphyTopicsPalette, ephy_topics_palette, EPHY, TOPICS_PALETTE, GtkTreeView);
+G_DECLARE_FINAL_TYPE (EphyTopicsPalette, ephy_topics_palette, EPHY, TOPICS_PALETTE, GtkListStore);
enum
{
@@ -43,8 +43,7 @@ enum
EphyTopicsPalette *ephy_topics_palette_new (EphyBookmarks *bookmarks,
EphyNode *bookmark);
-void ephy_topics_palette_update_list (EphyTopicsPalette *palette);
-GtkListStore *ephy_topics_palette_get_store (EphyTopicsPalette *palette);
+void ephy_topics_palette_update_list (EphyTopicsPalette *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]