diff options
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-editor.c | 2 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks.c | 6 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks.h | 4 | ||||
-rw-r--r-- | src/bookmarks/ephy-node-view.c | 83 | ||||
-rw-r--r-- | src/bookmarks/ephy-tree-model-node.c | 17 | ||||
-rw-r--r-- | src/bookmarks/ephy-tree-model-node.h | 2 |
7 files changed, 129 insertions, 3 deletions
@@ -1,3 +1,21 @@ +2003-02-26 Xan Lopez <xan@masilla.org> + + * src/bookmarks/ephy-bookmarks-editor.c: + (ephy_bookmarks_editor_construct): + * src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_init): + * src/bookmarks/ephy-bookmarks.h: + * src/bookmarks/ephy-node-view.c: (ephy_node_view_sort_func), + (set_sort_column_id), (ephy_node_view_add_column): + * src/bookmarks/ephy-tree-model-node.c: + (ephy_tree_model_node_get_column_type), + (ephy_tree_model_node_get_value), + (ephy_tree_model_node_column_get_type): + * src/bookmarks/ephy-tree-model-node.h: + + Default (alphabetical) sort of keywords and bookmarks in the BE, with + "All" remaining always on top. Disabled user-sort option of the + columns, it's a bit silly now. + 2003-02-26 Marco Pesenti Gritti <marco@it.gnome.org> * lib/widgets/ephy-toolbars-group.c: diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c index 1c12b4954..a3ce4fdf5 100644 --- a/src/bookmarks/ephy-bookmarks-editor.c +++ b/src/bookmarks/ephy-bookmarks-editor.c @@ -670,7 +670,7 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor) key_view = ephy_node_view_new (node, NULL); ephy_node_view_set_browse_mode (key_view); ephy_node_view_add_column (key_view, _("Keywords"), - EPHY_TREE_MODEL_NODE_COL_KEYWORD, FALSE); + EPHY_TREE_MODEL_NODE_COL_KEYWORD, TRUE); gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (key_view), FALSE, TRUE, 0); gtk_widget_set_size_request (GTK_WIDGET (key_view), 130, -1); gtk_widget_show (GTK_WIDGET (key_view)); diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c index 3b45599f6..8425ad92a 100644 --- a/src/bookmarks/ephy-bookmarks.c +++ b/src/bookmarks/ephy-bookmarks.c @@ -481,6 +481,12 @@ ephy_bookmarks_init (EphyBookmarks *eb) /* Keywords */ eb->priv->keywords = ephy_node_new_with_id (KEYWORDS_NODE_ID); ephy_node_ref (eb->priv->keywords); + g_value_init (&value, G_TYPE_BOOLEAN); + g_value_set_boolean (&value, TRUE); + ephy_node_set_property (eb->priv->bookmarks, + EPHY_NODE_KEYWORD_PROP_ALL_PRIORITY, + &value); + g_value_unset (&value); ephy_node_add_child (eb->priv->keywords, eb->priv->bookmarks); diff --git a/src/bookmarks/ephy-bookmarks.h b/src/bookmarks/ephy-bookmarks.h index 169e5a841..0d8f75efa 100644 --- a/src/bookmarks/ephy-bookmarks.h +++ b/src/bookmarks/ephy-bookmarks.h @@ -43,7 +43,9 @@ enum EPHY_NODE_BMK_PROP_KEYWORDS = 4, EPHY_NODE_KEYWORD_PROP_NAME = 5, EPHY_NODE_BMK_PROP_SMART_LOCATION = 6, - EPHY_NODE_BMK_PROP_ICON = 7 + EPHY_NODE_BMK_PROP_ICON = 7, + EPHY_NODE_KEYWORD_PROP_ALL_PRIORITY = 8 + }; struct EphyBookmarks diff --git a/src/bookmarks/ephy-node-view.c b/src/bookmarks/ephy-node-view.c index 102cefb9c..c67d66b04 100644 --- a/src/bookmarks/ephy-node-view.c +++ b/src/bookmarks/ephy-node-view.c @@ -30,6 +30,7 @@ #include "ephy-tree-model-sort.h" #include "eggtreemultidnd.h" #include "ephy-dnd.h" +#include "string.h" static void ephy_node_view_class_init (EphyNodeViewClass *klass); static void ephy_node_view_init (EphyNodeView *view); @@ -54,6 +55,8 @@ struct EphyNodeViewPrivate EphyNodeFilter *filter; GtkWidget *treeview; + + EphyTreeModelNodeColumn default_sort_column_id; }; enum @@ -395,6 +398,82 @@ ephy_node_view_new (EphyNode *root, return view; } +static int +ephy_node_view_sort_func (GtkTreeModel *model, + GtkTreeIter *a, + GtkTreeIter *b, + gpointer user_data) +{ + g_return_val_if_fail (model != NULL, 0); + g_return_val_if_fail (user_data != NULL, 0); + + GList *order = (GList *) user_data; + GList *l; + int retval = 0; + + for (l = order; l != NULL && retval == 0; l = g_list_next (l)) + { + EphyTreeModelNodeColumn column = GPOINTER_TO_INT (l->data); + GType type = gtk_tree_model_get_column_type (model, column); + GValue a_value = {0, }; + GValue b_value = {0, }; + const char *stra, *strb; + + gtk_tree_model_get_value (model, a, column, &a_value); + gtk_tree_model_get_value (model, b, column, &b_value); + + switch (G_TYPE_FUNDAMENTAL (type)) + { + case G_TYPE_STRING: + stra = g_value_get_string (&a_value); + strb = g_value_get_string (&b_value); + if (stra == NULL) stra = ""; + if (strb == NULL) strb = ""; + + if (column == EPHY_TREE_MODEL_NODE_COL_BOOKMARK || + column == EPHY_TREE_MODEL_NODE_COL_KEYWORD) + retval = strcmp (stra, strb); + break; + case G_TYPE_BOOLEAN: + if (g_value_get_boolean (&a_value) < g_value_get_boolean (&b_value)) + retval = -1; + else if (g_value_get_boolean (&a_value) == g_value_get_boolean (&b_value)) + retval = 0; + else + retval = 1; + break; + default: + g_warning ("Attempting to sort on invalid type %s\n", g_type_name (type)); + break; + } + + g_value_unset (&a_value); + g_value_unset (&b_value); + } + + return retval; + +} + +static gboolean +set_sort_column_id (EphyNodeView *view) +{ + EphyTreeModelNodeColumn priority = EPHY_TREE_MODEL_NODE_COL_PRIORITY; + GList *sort_order = NULL; + sort_order = g_list_append (sort_order, GINT_TO_POINTER (priority)); + sort_order = g_list_append (sort_order, GINT_TO_POINTER (view->priv->default_sort_column_id)); + + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (view->priv->sortmodel), + GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, + GTK_SORT_ASCENDING); + gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (view->priv->sortmodel), + ephy_node_view_sort_func, + sort_order, + (GtkDestroyNotify) g_list_free); + + return FALSE; +} + void ephy_node_view_add_column (EphyNodeView *view, const char *title, @@ -409,6 +488,7 @@ ephy_node_view_add_column (EphyNodeView *view, gtk_tree_view_column_pack_start (gcolumn, renderer, TRUE); gtk_tree_view_column_set_attributes (gcolumn, renderer, "text", column, + "weight", EPHY_TREE_MODEL_NODE_COL_TITLE_WEIGHT, NULL); gtk_tree_view_column_set_sizing (gcolumn, GTK_TREE_VIEW_COLUMN_AUTOSIZE); @@ -417,7 +497,8 @@ ephy_node_view_add_column (EphyNodeView *view, gcolumn); if (sortable) { - gtk_tree_view_column_set_sort_column_id (gcolumn, column); + view->priv->default_sort_column_id = column; + g_idle_add ((GSourceFunc) set_sort_column_id, view); } } diff --git a/src/bookmarks/ephy-tree-model-node.c b/src/bookmarks/ephy-tree-model-node.c index 41bdc235e..e62acbad7 100644 --- a/src/bookmarks/ephy-tree-model-node.c +++ b/src/bookmarks/ephy-tree-model-node.c @@ -360,7 +360,10 @@ ephy_tree_model_node_get_column_type (GtkTreeModel *tree_model, case EPHY_TREE_MODEL_NODE_COL_BOOKMARK: case EPHY_TREE_MODEL_NODE_COL_KEYWORD: return G_TYPE_STRING; + case EPHY_TREE_MODEL_NODE_COL_TITLE_WEIGHT: + return G_TYPE_INT; case EPHY_TREE_MODEL_NODE_COL_VISIBLE: + case EPHY_TREE_MODEL_NODE_COL_PRIORITY: return G_TYPE_BOOLEAN; case EPHY_TREE_MODEL_NODE_COL_ICON: return GDK_TYPE_PIXBUF; @@ -504,6 +507,18 @@ ephy_tree_model_node_get_value (GtkTreeModel *tree_model, g_value_set_boolean (value, TRUE); } break; + case EPHY_TREE_MODEL_NODE_COL_TITLE_WEIGHT: + g_value_init (value, G_TYPE_INT); + if (!ephy_node_get_property_boolean (node, EPHY_NODE_KEYWORD_PROP_ALL_PRIORITY)) + g_value_set_int (value, PANGO_WEIGHT_NORMAL); + else + g_value_set_int (value, PANGO_WEIGHT_BOLD); + break; + case EPHY_TREE_MODEL_NODE_COL_PRIORITY: + g_value_init (value, G_TYPE_BOOLEAN); + g_value_set_boolean (value, !ephy_node_get_property_boolean (node, + EPHY_NODE_KEYWORD_PROP_ALL_PRIORITY)); + break; default: g_assert_not_reached (); break; @@ -714,6 +729,8 @@ ephy_tree_model_node_column_get_type (void) { EPHY_TREE_MODEL_NODE_COL_KEYWORD, "EPHY_TREE_MODEL_NODE_COL_KEYWORD", "keyword" }, { EPHY_TREE_MODEL_NODE_COL_ICON, "EPHY_TREE_MODEL_NODE_COL_ICON", "icon" }, { EPHY_TREE_MODEL_NODE_COL_VISIBLE, "EPHY_TREE_MODEL_NODE_COL_VISIBLE", "visible" }, + { EPHY_TREE_MODEL_NODE_COL_TITLE_WEIGHT, "EPHY_TREE_MODEL_NODE_COL_TITLE_WEIGHT", "title weight" }, + { EPHY_TREE_MODEL_NODE_COL_PRIORITY, "EPHY_TREE_MODEL_NODE_COL_PRIORITY", "priority" }, { 0, 0, 0 } }; diff --git a/src/bookmarks/ephy-tree-model-node.h b/src/bookmarks/ephy-tree-model-node.h index 5ebefa4fd..afc862f58 100644 --- a/src/bookmarks/ephy-tree-model-node.h +++ b/src/bookmarks/ephy-tree-model-node.h @@ -41,6 +41,8 @@ typedef enum EPHY_TREE_MODEL_NODE_COL_KEYWORD, EPHY_TREE_MODEL_NODE_COL_VISIBLE, EPHY_TREE_MODEL_NODE_COL_ICON, + EPHY_TREE_MODEL_NODE_COL_TITLE_WEIGHT, + EPHY_TREE_MODEL_NODE_COL_PRIORITY, EPHY_TREE_MODEL_NODE_NUM_COLUMNS } EphyTreeModelNodeColumn; |