From 456d9144bd889aa71e277fc9e7b06f3d654931cf Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 23 Jul 2004 10:03:56 +0000 Subject: Add support for toggles. When editing is canceled remove the node. 2004-07-23 Marco Pesenti Gritti * lib/ephy-marshal.list: * lib/widgets/ephy-node-view.c: (path_toggled), (ephy_node_view_key_press_cb), (get_selection_refs), (ephy_node_view_button_press_cb), (cell_renderer_edited), (renderer_editing_canceled_cb), (ephy_node_view_add_column), (ephy_node_view_init), (ephy_node_view_edit), (ephy_node_view_constructor), (ephy_node_view_add_toggle), (ephy_node_view_class_init): * lib/widgets/ephy-node-view.h: Add support for toggles. When editing is canceled remove the node. * src/bookmarks/ephy-new-bookmark.c: (ephy_new_bookmark_add): * src/bookmarks/ephy-topics-selector.c: (ephy_topics_selector_get_type), (ephy_topics_selector_set_bookmarks), (ephy_topics_selector_set_property), (ephy_topics_selector_apply), (provide_toggle), (ephy_topics_selector_constructor), (topic_destroy_cb), (node_toggled_cb), (ephy_topics_selector_init), (ephy_topics_selector_new), (ephy_topics_selector_new_topic), (ephy_topics_selector_class_init): * src/bookmarks/ephy-topics-selector.h: Use EphyNodeView instead of a list store. Share a lot of code and we get updating for free. Fix bug #144770 --- ChangeLog | 29 ++ doc/reference/tmpl/ephy-embed-single.sgml | 11 - doc/reference/tmpl/ephy-embed.sgml | 2 + doc/reference/tmpl/epiphany-unused.sgml | 9 + lib/ephy-marshal.list | 1 + lib/widgets/ephy-node-view.c | 132 +++++++-- lib/widgets/ephy-node-view.h | 5 + src/bookmarks/ephy-new-bookmark.c | 3 +- src/bookmarks/ephy-topics-selector.c | 445 ++++++++++-------------------- src/bookmarks/ephy-topics-selector.h | 13 +- 10 files changed, 302 insertions(+), 348 deletions(-) diff --git a/ChangeLog b/ChangeLog index 22f314213..991ce124f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2004-07-23 Marco Pesenti Gritti + + * lib/ephy-marshal.list: + * lib/widgets/ephy-node-view.c: (path_toggled), + (ephy_node_view_key_press_cb), (get_selection_refs), + (ephy_node_view_button_press_cb), (cell_renderer_edited), + (renderer_editing_canceled_cb), (ephy_node_view_add_column), + (ephy_node_view_init), (ephy_node_view_edit), + (ephy_node_view_constructor), (ephy_node_view_add_toggle), + (ephy_node_view_class_init): + * lib/widgets/ephy-node-view.h: + + Add support for toggles. When editing is canceled remove + the node. + + * src/bookmarks/ephy-new-bookmark.c: (ephy_new_bookmark_add): + * src/bookmarks/ephy-topics-selector.c: + (ephy_topics_selector_get_type), + (ephy_topics_selector_set_bookmarks), + (ephy_topics_selector_set_property), (ephy_topics_selector_apply), + (provide_toggle), (ephy_topics_selector_constructor), + (topic_destroy_cb), (node_toggled_cb), (ephy_topics_selector_init), + (ephy_topics_selector_new), (ephy_topics_selector_new_topic), + (ephy_topics_selector_class_init): + * src/bookmarks/ephy-topics-selector.h: + + Use EphyNodeView instead of a list store. Share a lot of code + and we get updating for free. Fix bug #144770 + 2004-07-23 Marco Pesenti Gritti * lib/widgets/ephy-node-view.c: (filter_changed_cb), diff --git a/doc/reference/tmpl/ephy-embed-single.sgml b/doc/reference/tmpl/ephy-embed-single.sgml index ed0f624b1..83b187a97 100644 --- a/doc/reference/tmpl/ephy-embed-single.sgml +++ b/doc/reference/tmpl/ephy-embed-single.sgml @@ -66,17 +66,6 @@ is used to perform browser-related actions which do not refer to an individual @shell: - - - - - -@single: -@url: - -@shell: - - diff --git a/doc/reference/tmpl/ephy-embed.sgml b/doc/reference/tmpl/ephy-embed.sgml index 83b60c806..67fb618d5 100644 --- a/doc/reference/tmpl/ephy-embed.sgml +++ b/doc/reference/tmpl/ephy-embed.sgml @@ -130,6 +130,8 @@ be done by casting). @: @: @: +@: +@: @: diff --git a/doc/reference/tmpl/epiphany-unused.sgml b/doc/reference/tmpl/epiphany-unused.sgml index 142307092..aa9f02d89 100644 --- a/doc/reference/tmpl/epiphany-unused.sgml +++ b/doc/reference/tmpl/epiphany-unused.sgml @@ -136,6 +136,15 @@ mozilla-embed-event @embed: + + + + + +@single: +@url: +@shell: + diff --git a/lib/ephy-marshal.list b/lib/ephy-marshal.list index 425418825..a31b373fc 100644 --- a/lib/ephy-marshal.list +++ b/lib/ephy-marshal.list @@ -3,6 +3,7 @@ BOOLEAN:OBJECT BOOLEAN:STRING, STRING VOID:INT,INT VOID:POINTER,INT +VOID:POINTER,BOOLEAN VOID:POINTER,POINTER VOID:STRING,INT VOID:STRING,INT,INT diff --git a/lib/widgets/ephy-node-view.c b/lib/widgets/ephy-node-view.c index 2416f4101..fecb90799 100644 --- a/lib/widgets/ephy-node-view.c +++ b/lib/widgets/ephy-node-view.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,7 @@ struct EphyNodeViewPrivate GtkCellRenderer *editable_renderer; GtkTreeViewColumn *editable_column; int editable_node_column; + int toggle_column; EphyNodeFilter *filter; @@ -65,7 +67,7 @@ struct EphyNodeViewPrivate guint priority_prop_id; int priority_column; - gboolean editing; + EphyNode *edited_node; int editable_property; int searchable_data_column; @@ -84,6 +86,7 @@ struct EphyNodeViewPrivate enum { + NODE_TOGGLED, NODE_ACTIVATED, NODE_SELECTED, NODE_DROPPED, @@ -588,6 +591,31 @@ ephy_node_view_row_activated_cb (GtkTreeView *treeview, g_signal_emit (G_OBJECT (view), ephy_node_view_signals[NODE_ACTIVATED], 0, node); } +static void +path_toggled (GtkTreeModel *dummy_model, GtkTreePath *path, + GtkTreeIter *dummy, gpointer data) +{ + EphyNodeView *view = EPHY_NODE_VIEW (data); + gboolean checked; + EphyNode *node; + GtkTreeIter iter, iter2; + GValue value = {0, }; + + gtk_tree_model_get_iter (view->priv->sortmodel, &iter, path); + gtk_tree_model_sort_convert_iter_to_child_iter + (GTK_TREE_MODEL_SORT (view->priv->sortmodel), &iter2, &iter); + gtk_tree_model_filter_convert_iter_to_child_iter + (GTK_TREE_MODEL_FILTER (view->priv->filtermodel), &iter, &iter2); + + node = ephy_tree_model_node_node_from_iter (view->priv->nodemodel, &iter); + gtk_tree_model_get_value (GTK_TREE_MODEL (view->priv->nodemodel), &iter, + view->priv->toggle_column, &value); + checked = !g_value_get_boolean (&value); + + g_signal_emit (G_OBJECT (view), ephy_node_view_signals[NODE_TOGGLED], 0, + node, checked); +} + static gboolean ephy_node_view_key_press_cb (GtkTreeView *treeview, GdkEventKey *event, @@ -597,8 +625,21 @@ ephy_node_view_key_press_cb (GtkTreeView *treeview, unicode = gdk_keyval_to_unicode (event->keyval); - if ((event->state & GDK_SHIFT_MASK) && - (event->keyval == GDK_F10)) + if (event->keyval == GDK_space || + event->keyval == GDK_Return || + event->keyval == GDK_KP_Enter) + { + if (view->priv->toggle_column >= 0) + { + GtkTreeSelection *selection; + + selection = gtk_tree_view_get_selection (treeview); + gtk_tree_selection_selected_foreach + (selection, path_toggled, view); + } + } + else if ((event->state & GDK_SHIFT_MASK) && + (event->keyval == GDK_F10)) { g_signal_emit (G_OBJECT (view), ephy_node_view_signals[SHOW_POPUP], 0); @@ -631,16 +672,13 @@ static GList * get_selection_refs (GtkTreeView *tree_view) { GtkTreeSelection *selection; - GList *ref_list; - - ref_list = NULL; - + GList *ref_list = NULL; + selection = gtk_tree_view_get_selection (tree_view); gtk_tree_selection_selected_foreach (selection, selection_foreach, &ref_list); - ref_list = g_list_reverse (ref_list); - + ref_list = g_list_reverse (ref_list); return ref_list; } @@ -827,10 +865,17 @@ ephy_node_view_button_press_cb (GtkWidget *treeview, } else if (event->button == 1) { - view->priv->drag_started = FALSE; - view->priv->drag_button = event->button; - view->priv->drag_x = event->x; - view->priv->drag_y = event->y; + if (view->priv->toggle_column >= 0) + { + path_toggled (NULL, path, NULL, view); + } + else + { + view->priv->drag_started = FALSE; + view->priv->drag_button = event->button; + view->priv->drag_x = event->x; + view->priv->drag_y = event->y; + } } gtk_tree_path_free (path); @@ -940,7 +985,7 @@ cell_renderer_edited (GtkCellRendererText *cell, GtkTreeIter iter, iter2; EphyNode *node; - view->priv->editing = FALSE; + view->priv->edited_node = NULL; g_object_set (G_OBJECT (view->priv->editable_renderer), "editable", FALSE, @@ -964,6 +1009,13 @@ cell_renderer_edited (GtkCellRendererText *cell, gtk_tree_path_free (path); } +static void +renderer_editing_canceled_cb (GtkCellRendererText *cell, + EphyNodeView *view) +{ + ephy_node_unref (view->priv->edited_node); +} + static inline int compare_string_values (const GValue *a_value, const GValue *b_value) { @@ -1198,7 +1250,11 @@ ephy_node_view_add_column (EphyNodeView *view, view->priv->editable_column = gcolumn; view->priv->editable_node_column = column; view->priv->editable_property = prop_id; - g_signal_connect (renderer, "edited", G_CALLBACK (cell_renderer_edited), view); + + g_signal_connect (renderer, "edited", + G_CALLBACK (cell_renderer_edited), view); + g_signal_connect (renderer, "editing-canceled", + G_CALLBACK (renderer_editing_canceled_cb), view); } if ((flags & EPHY_NODE_VIEW_SEARCHABLE) && @@ -1275,9 +1331,10 @@ ephy_node_view_init (EphyNodeView *view) { view->priv = EPHY_NODE_VIEW_GET_PRIVATE (view); + view->priv->toggle_column = -1; view->priv->filter = NULL; view->priv->editable_renderer = NULL; - view->priv->editing = TRUE; + view->priv->edited_node = NULL; view->priv->searchable_data_column = -1; view->priv->source_target_list = NULL; view->priv->priority_column = -1; @@ -1443,6 +1500,7 @@ ephy_node_view_enable_drag_source (EphyNodeView *view, void ephy_node_view_edit (EphyNodeView *view) { + GtkTreePath *path; GtkTreeSelection *selection; GList *rows; GtkTreeModel *model; @@ -1454,16 +1512,17 @@ ephy_node_view_edit (EphyNodeView *view) rows = gtk_tree_selection_get_selected_rows (selection, &model); if (rows == NULL) return; + path = rows->data; + g_object_set (G_OBJECT (view->priv->editable_renderer), "editable", TRUE, NULL); - gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), - (GtkTreePath *)rows->data, + gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path, view->priv->editable_column, TRUE); - view->priv->editing = TRUE; + view->priv->edited_node = get_node_from_path (view, path); g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL); g_list_free (rows); @@ -1533,9 +1592,9 @@ ephy_node_view_constructor (GType type, guint n_construct_properties, g_signal_connect_object (object, "button_press_event", G_CALLBACK (ephy_node_view_button_press_cb), view, 0); - g_signal_connect_after (object, "key_press_event", - G_CALLBACK (ephy_node_view_key_press_cb), - view); + g_signal_connect (object, "key_press_event", + G_CALLBACK (ephy_node_view_key_press_cb), + view); g_signal_connect_object (object, "row_activated", G_CALLBACK (ephy_node_view_row_activated_cb), view, 0); @@ -1549,6 +1608,24 @@ ephy_node_view_constructor (GType type, guint n_construct_properties, return object; } +void +ephy_node_view_add_toggle (EphyNodeView *view, EphyTreeModelNodeValueFunc value_func, + gpointer data) +{ + GtkCellRenderer *renderer; + GtkTreeViewColumn *col; + int column; + + column = ephy_tree_model_node_add_func_column + (view->priv->nodemodel, G_TYPE_BOOLEAN, value_func, data); + view->priv->toggle_column = column; + + renderer = gtk_cell_renderer_toggle_new (); + col = gtk_tree_view_column_new_with_attributes + ("", renderer, "active", column, NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (view), col); +} + static void ephy_node_view_class_init (EphyNodeViewClass *klass) { @@ -1576,6 +1653,17 @@ ephy_node_view_class_init (EphyNodeViewClass *klass) EPHY_TYPE_NODE_FILTER, G_PARAM_READWRITE)); + ephy_node_view_signals[NODE_TOGGLED] = + g_signal_new ("node_toggled", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EphyNodeViewClass, node_toggled), + NULL, NULL, + ephy_marshal_VOID__POINTER_BOOLEAN, + G_TYPE_NONE, + 2, + G_TYPE_POINTER, + G_TYPE_BOOLEAN); ephy_node_view_signals[NODE_ACTIVATED] = g_signal_new ("node_activated", G_OBJECT_CLASS_TYPE (object_class), diff --git a/lib/widgets/ephy-node-view.h b/lib/widgets/ephy-node-view.h index 1896eb233..91886dc67 100644 --- a/lib/widgets/ephy-node-view.h +++ b/lib/widgets/ephy-node-view.h @@ -65,6 +65,7 @@ typedef struct { GtkTreeViewClass parent; + void (*node_toggled) (EphyNodeView *view, EphyNode *node, gboolean checked); void (*node_activated) (EphyNodeView *view, EphyNode *node); void (*node_selected) (EphyNodeView *view, EphyNode *node); void (*node_dropped) (EphyNodeView *view, EphyNode *node, GList *uris); @@ -78,6 +79,10 @@ GtkWidget *ephy_node_view_new (EphyNode *root, void ephy_node_view_enable_dnd (EphyNodeView *view); +void ephy_node_view_add_toggle (EphyNodeView *view, + EphyTreeModelNodeValueFunc value_func, + gpointer data); + GtkTreeViewColumn *ephy_node_view_add_column (EphyNodeView *view, const char *title, GType value_type, diff --git a/src/bookmarks/ephy-new-bookmark.c b/src/bookmarks/ephy-new-bookmark.c index 742ae005b..5897a23d1 100644 --- a/src/bookmarks/ephy-new-bookmark.c +++ b/src/bookmarks/ephy-new-bookmark.c @@ -164,8 +164,7 @@ ephy_new_bookmark_add (EphyNewBookmark *new_bookmark) new_bookmark->priv->location); new_bookmark->priv->id = ephy_node_get_id (node); - ephy_topics_selector_set_bookmark (selector, node); - ephy_topics_selector_apply (selector); + ephy_topics_selector_apply (selector, node); if (new_bookmark->priv->icon) { diff --git a/src/bookmarks/ephy-topics-selector.c b/src/bookmarks/ephy-topics-selector.c index 007a3a05d..ac8113a44 100644 --- a/src/bookmarks/ephy-topics-selector.c +++ b/src/bookmarks/ephy-topics-selector.c @@ -24,40 +24,20 @@ #include "ephy-topics-selector.h" #include "ephy-debug.h" -#include "ephy-node-view.h" -#include "ephy-gui.h" #include -#include -#include -#include -#include -#include -#include -#include static void ephy_topics_selector_class_init (EphyTopicsSelectorClass *klass); static void ephy_topics_selector_init (EphyTopicsSelector *editor); -static void ephy_topics_selector_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void ephy_topics_selector_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); #define EPHY_TOPICS_SELECTOR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_TOPICS_SELECTOR, EphyTopicsSelectorPrivate)) struct EphyTopicsSelectorPrivate { EphyBookmarks *bookmarks; - GtkTreeModel *model; EphyNode *bookmark; - - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - GtkTreePath *edited_path; + EphyNodeFilter *filter; + GList *topics; }; enum @@ -67,13 +47,6 @@ enum PROP_BOOKMARK }; -enum -{ - COL_HAS_TOPIC, - COL_TOPIC, - COL_NODE -}; - static GObjectClass *parent_class = NULL; GType @@ -96,7 +69,7 @@ ephy_topics_selector_get_type (void) (GInstanceInitFunc) ephy_topics_selector_init }; - ephy_topics_selector_type = g_type_register_static (GTK_TYPE_TREE_VIEW, + ephy_topics_selector_type = g_type_register_static (EPHY_TYPE_NODE_VIEW, "EphyTopicsSelector", &our_info, 0); } @@ -105,34 +78,6 @@ ephy_topics_selector_get_type (void) } static void -ephy_topics_selector_class_init (EphyTopicsSelectorClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - object_class->set_property = ephy_topics_selector_set_property; - object_class->get_property = ephy_topics_selector_get_property; - - g_object_class_install_property (object_class, - PROP_BOOKMARKS, - g_param_spec_object ("bookmarks", - "Bookmarks set", - "Bookmarks set", - EPHY_TYPE_BOOKMARKS, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, - PROP_BOOKMARK, - g_param_spec_pointer ("bookmark", - "Bookmark", - "Bookmark", - G_PARAM_READWRITE)); - - g_type_class_add_private (object_class, sizeof(EphyTopicsSelectorPrivate)); -} - -void ephy_topics_selector_set_bookmark (EphyTopicsSelector *selector, EphyNode *bookmark) { @@ -143,6 +88,13 @@ ephy_topics_selector_set_bookmark (EphyTopicsSelector *selector, g_object_notify (G_OBJECT (selector), "bookmark"); } +static void +ephy_topics_selector_set_bookmarks (EphyTopicsSelector *selector, + EphyBookmarks *bookmarks) +{ + selector->priv->bookmarks = bookmarks; +} + static void ephy_topics_selector_set_property (GObject *object, guint prop_id, @@ -154,7 +106,8 @@ ephy_topics_selector_set_property (GObject *object, switch (prop_id) { case PROP_BOOKMARKS: - selector->priv->bookmarks = g_value_get_object (value); + ephy_topics_selector_set_bookmarks + (selector, g_value_get_object (value)); break; case PROP_BOOKMARK: ephy_topics_selector_set_bookmark @@ -185,265 +138,129 @@ ephy_topics_selector_get_property (GObject *object, } } -static void -fill_model (EphyTopicsSelector *editor) +void +ephy_topics_selector_apply (EphyTopicsSelector *selector, EphyNode *bookmark) { - GPtrArray *children; - int i; - EphyNode *keywords; - GtkListStore *model = GTK_LIST_STORE (editor->priv->model); + GList *l; - keywords = ephy_bookmarks_get_keywords (editor->priv->bookmarks); - - children = ephy_node_get_children (keywords); - for (i = 0; i < children->len; i++) + for (l = selector->priv->topics; l != NULL; l = l->next) { - EphyNode *kid; - const char *name; - gboolean has_keyword = FALSE; - int priority; - GtkTreeIter iter; - - kid = g_ptr_array_index (children, i); - - name = ephy_node_get_property_string - (kid, EPHY_NODE_KEYWORD_PROP_NAME); - - if (editor->priv->bookmark != NULL) - { - has_keyword = ephy_bookmarks_has_keyword - (editor->priv->bookmarks, kid, - editor->priv->bookmark); - } + EphyNode *node = l->data; - priority = ephy_node_get_property_int - (kid, EPHY_NODE_KEYWORD_PROP_PRIORITY); - if (priority == -1) priority = EPHY_NODE_VIEW_NORMAL_PRIORITY; - - if (priority == EPHY_NODE_VIEW_NORMAL_PRIORITY) - { - gtk_list_store_append (model, &iter); - gtk_list_store_set (model, &iter, - COL_HAS_TOPIC, has_keyword, - COL_TOPIC, name, - COL_NODE, kid, - -1); - } + ephy_bookmarks_set_keyword (selector->priv->bookmarks, + node, bookmark); } } static void -topic_toggled (GtkTreePath *path, - EphyTopicsSelector *selector) -{ - GtkTreeModel *model = selector->priv->model; - GtkTreeIter iter; - gboolean has_topic; - - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, COL_HAS_TOPIC, &has_topic, -1); - has_topic = !has_topic; - - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_HAS_TOPIC, has_topic, -1); - ephy_topics_selector_apply (selector); -} - -void -ephy_topics_selector_apply (EphyTopicsSelector *editor) +provide_toggle (EphyNode *node, GValue *value, gpointer data) { - GtkTreeIter iter; - GtkTreeModel *model = editor->priv->model; - - LOG ("Update topics") + EphyTopicsSelector *selector = EPHY_TOPICS_SELECTOR (data); + gboolean result = FALSE; - if (editor->priv->bookmark == NULL) return; + g_value_init (value, G_TYPE_BOOLEAN); - if (!gtk_tree_model_get_iter_first (model, &iter)) + if (selector->priv->bookmark) { - return; + result = ephy_node_has_child (node, selector->priv->bookmark); } - - do + else { - GValue value = { 0, }; - gboolean has_topic; - EphyNode *node; + result = (g_list_find (selector->priv->topics, node) != NULL); + } - gtk_tree_model_get_value (model, &iter, COL_HAS_TOPIC, &value); - has_topic = g_value_get_boolean (&value); - g_value_unset (&value); + g_value_set_boolean (value, result); +} - gtk_tree_model_get_value (model, &iter, COL_NODE, &value); - node = g_value_get_pointer (&value); - g_value_unset (&value); +static GObject * +ephy_topics_selector_constructor (GType type, guint n_construct_properties, + GObjectConstructParam *construct_params) - if (has_topic) - { - ephy_bookmarks_set_keyword (editor->priv->bookmarks, - node, - editor->priv->bookmark); - } - else - { - ephy_bookmarks_unset_keyword (editor->priv->bookmarks, - node, - editor->priv->bookmark); - } - } - while (gtk_tree_model_iter_next (model, &iter)); +{ + GObject *object; + EphyTopicsSelector *selector; + EphyTopicsSelectorPrivate *priv; + + object = parent_class->constructor (type, n_construct_properties, + construct_params); + selector = EPHY_TOPICS_SELECTOR (object); + priv = EPHY_TOPICS_SELECTOR_GET_PRIVATE (object); + + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (selector), FALSE); + + ephy_node_view_add_toggle (EPHY_NODE_VIEW (selector), + provide_toggle, selector); + ephy_node_view_add_column (EPHY_NODE_VIEW (selector), "Topics", + G_TYPE_STRING, + EPHY_NODE_KEYWORD_PROP_NAME, + EPHY_NODE_VIEW_SHOW_PRIORITY | + EPHY_NODE_VIEW_EDITABLE | + EPHY_NODE_VIEW_SEARCHABLE, NULL); + + return object; } -static gboolean -topic_clicked (GtkTreeView *tree_view, - GdkEventButton *event, - EphyTopicsSelector *selector) +static void +topic_destroy_cb (EphyNode *node, EphyTopicsSelector *selector) { - GtkTreePath *path = NULL; - - if (event->window != gtk_tree_view_get_bin_window (tree_view)) - return FALSE; - - if (gtk_tree_view_get_path_at_pos (tree_view, - (gint) event->x, - (gint) event->y, - &path, NULL, - NULL, NULL)) - { - topic_toggled (path, selector); - - gtk_tree_path_free (path); - } - - return FALSE; + selector->priv->topics = g_list_remove + (selector->priv->topics, node); } -static gboolean -topic_key_pressed (GtkTreeView *tree_view, - GdkEventKey *event, - EphyTopicsSelector *selector) +static void +node_toggled_cb (EphyTopicsSelector *selector, EphyNode *node, + gboolean checked, gpointer data) { - GtkTreeSelection *sel = NULL; - GtkTreeIter iter; - GtkTreePath *path; - guint32 unicode; - - switch (event->keyval) + if (selector->priv->bookmark) { - case GDK_space: - case GDK_Return: - case GDK_KP_Enter: - sel = gtk_tree_view_get_selection (tree_view); - - if (gtk_tree_selection_get_selected (sel, NULL, &iter)) + if (checked) { - path = gtk_tree_model_get_path (selector->priv->model, &iter); - - topic_toggled (path, selector); - - gtk_tree_path_free (path); + ephy_bookmarks_set_keyword (selector->priv->bookmarks, + node, + selector->priv->bookmark); + } + else + { + ephy_bookmarks_unset_keyword (selector->priv->bookmarks, + node, + selector->priv->bookmark); } - return TRUE; - - default: - break; } - - unicode = gdk_keyval_to_unicode (event->keyval); - if (unicode) + else { - return ephy_gui_select_row_by_key (tree_view, COL_TOPIC, unicode); + if (checked) + { + selector->priv->topics = g_list_append + (selector->priv->topics, node); + ephy_node_signal_connect_object (node, EPHY_NODE_DESTROY, + (EphyNodeCallback) topic_destroy_cb, + G_OBJECT (selector)); + } + else + { + selector->priv->topics = g_list_remove + (selector->priv->topics, node); + } } - - return FALSE; -} - -static void -renderer_edited_cb (GtkCellRendererText *cell, - const char *path_str, - const char *new_text, - EphyTopicsSelector *selector) -{ - GtkTreePath *path; - GtkTreeIter iter; - EphyNode *topic; - - path = gtk_tree_path_new_from_string (path_str); - gtk_tree_model_get_iter (selector->priv->model, &iter, path); - - topic = ephy_bookmarks_add_keyword (selector->priv->bookmarks, new_text); - gtk_list_store_set (GTK_LIST_STORE (selector->priv->model), &iter, - COL_HAS_TOPIC, TRUE, - COL_TOPIC, new_text, - COL_NODE, topic, - -1); - gtk_tree_path_free (path); - - g_object_set (G_OBJECT (cell), "editable", FALSE, NULL); - gtk_tree_path_free (selector->priv->edited_path); -} - -static void -renderer_editing_canceled_cb (GtkCellRendererText *cell, - EphyTopicsSelector *selector) -{ - GtkTreeIter iter; - - gtk_tree_model_get_iter (selector->priv->model, &iter, - selector->priv->edited_path); - gtk_list_store_remove (GTK_LIST_STORE (selector->priv->model), &iter); - - g_object_set (G_OBJECT (cell), "editable", FALSE, NULL); - gtk_tree_path_free (selector->priv->edited_path); } static void -ephy_topics_build_ui (EphyTopicsSelector *editor) +ephy_topics_selector_init (EphyTopicsSelector *selector) { - GtkListStore *model; - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - - model = gtk_list_store_new (3, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_POINTER); - editor->priv->model = GTK_TREE_MODEL (model); - - gtk_tree_view_set_model (GTK_TREE_VIEW (editor), GTK_TREE_MODEL (model)); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (editor), FALSE); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model), - COL_TOPIC, - GTK_SORT_ASCENDING); - g_object_unref (model); - - /* Has topic column */ - renderer = gtk_cell_renderer_toggle_new (); - column = gtk_tree_view_column_new_with_attributes - ("", renderer, "active", COL_HAS_TOPIC, NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (editor), column); - - renderer = gtk_cell_renderer_text_new (); - editor->priv->renderer = renderer; - column = gtk_tree_view_column_new_with_attributes - ("Description", renderer, "text", COL_TOPIC, NULL); - editor->priv->column = column; - gtk_tree_view_append_column (GTK_TREE_VIEW (editor), column); - g_signal_connect (renderer, "edited", - G_CALLBACK (renderer_edited_cb), editor); - g_signal_connect (renderer, "editing-canceled", - G_CALLBACK (renderer_editing_canceled_cb), editor); - - g_signal_connect (G_OBJECT (editor), "key_press_event", - G_CALLBACK (topic_key_pressed), editor); - g_signal_connect (G_OBJECT (editor), "button_press_event", - G_CALLBACK (topic_clicked), editor); - fill_model (editor); -} - -static void -ephy_topics_selector_init (EphyTopicsSelector *editor) -{ - editor->priv = EPHY_TOPICS_SELECTOR_GET_PRIVATE (editor); - - editor->priv->bookmark = NULL; + selector->priv = EPHY_TOPICS_SELECTOR_GET_PRIVATE (selector); + selector->priv->bookmark = NULL; + selector->priv->topics = NULL; + + selector->priv->filter = ephy_node_filter_new (); + ephy_node_filter_add_expression (selector->priv->filter, + ephy_node_filter_expression_new (EPHY_NODE_FILTER_EXPRESSION_INT_PROP_EQUALS, + EPHY_NODE_KEYWORD_PROP_PRIORITY, + EPHY_NODE_VIEW_NORMAL_PRIORITY), + 0); + g_object_set (selector, "filter", selector->priv->filter, NULL); + + g_signal_connect (selector, "node_toggled", + G_CALLBACK (node_toggled_cb), NULL); } GtkWidget * @@ -451,39 +268,57 @@ ephy_topics_selector_new (EphyBookmarks *bookmarks, EphyNode *bookmark) { EphyTopicsSelector *editor; + EphyNode *root; g_assert (bookmarks != NULL); + root = ephy_bookmarks_get_keywords (bookmarks); editor = EPHY_TOPICS_SELECTOR (g_object_new (EPHY_TYPE_TOPICS_SELECTOR, "bookmarks", bookmarks, "bookmark", bookmark, + "root", root, NULL)); - ephy_topics_build_ui (editor); - return GTK_WIDGET (editor); } void ephy_topics_selector_new_topic (EphyTopicsSelector *selector) { - GtkTreePath *path; - GtkTreeIter iter; - - g_object_set (G_OBJECT (selector->priv->renderer), - "editable", TRUE, NULL); - - gtk_list_store_append (GTK_LIST_STORE (selector->priv->model), &iter); - gtk_list_store_set (GTK_LIST_STORE (selector->priv->model), &iter, - COL_HAS_TOPIC, FALSE, - COL_TOPIC, _("Type a topic"), - COL_NODE, NULL, - -1); - - path = gtk_tree_model_get_path (selector->priv->model, &iter); - gtk_widget_grab_focus (GTK_WIDGET (selector)); - gtk_tree_view_set_cursor (GTK_TREE_VIEW (selector), path, - selector->priv->column, TRUE); - selector->priv->edited_path = path; + EphyNode *node; + + node = ephy_bookmarks_add_keyword + (selector->priv->bookmarks, _("Type a topic")); + ephy_node_view_select_node (EPHY_NODE_VIEW (selector), node); + ephy_node_view_edit (EPHY_NODE_VIEW (selector)); +} + +static void +ephy_topics_selector_class_init (EphyTopicsSelectorClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + object_class->set_property = ephy_topics_selector_set_property; + object_class->get_property = ephy_topics_selector_get_property; + object_class->constructor = ephy_topics_selector_constructor; + + g_object_class_install_property (object_class, + PROP_BOOKMARKS, + g_param_spec_object ("bookmarks", + "Bookmarks set", + "Bookmarks set", + EPHY_TYPE_BOOKMARKS, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, + PROP_BOOKMARK, + g_param_spec_pointer ("bookmark", + "Bookmark", + "Bookmark", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_type_class_add_private (object_class, sizeof(EphyTopicsSelectorPrivate)); } diff --git a/src/bookmarks/ephy-topics-selector.h b/src/bookmarks/ephy-topics-selector.h index ce4a4ac35..733d48f41 100644 --- a/src/bookmarks/ephy-topics-selector.h +++ b/src/bookmarks/ephy-topics-selector.h @@ -22,8 +22,7 @@ #define EPHY_TOPICS_SELECTOR_H #include "ephy-bookmarks.h" - -#include +#include "ephy-node-view.h" G_BEGIN_DECLS @@ -38,7 +37,7 @@ typedef struct EphyTopicsSelectorPrivate EphyTopicsSelectorPrivate; typedef struct { - GtkTreeView parent; + EphyNodeView parent; /*< private >*/ EphyTopicsSelectorPrivate *priv; @@ -46,7 +45,7 @@ typedef struct typedef struct { - GtkTreeViewClass parent; + EphyNodeViewClass parent; } EphyTopicsSelectorClass; GType ephy_topics_selector_get_type (void); @@ -54,12 +53,10 @@ GType ephy_topics_selector_get_type (void); GtkWidget *ephy_topics_selector_new (EphyBookmarks *bookmarks, EphyNode *bookmark); -void ephy_topics_selector_set_bookmark (EphyTopicsSelector *selector, - EphyNode *bookmark); - void ephy_topics_selector_new_topic (EphyTopicsSelector *selector); -void ephy_topics_selector_apply (EphyTopicsSelector *selector); +void ephy_topics_selector_apply (EphyTopicsSelector *selector, + EphyNode *bookmark); G_END_DECLS -- cgit v1.2.3