diff options
author | Marco Pesenti Gritti <marco@gnome.org> | 2004-07-15 00:44:35 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <marco@src.gnome.org> | 2004-07-15 00:44:35 +0800 |
commit | a73d4d600b8be7e21cd6ea9e956f6a7c6c3e4828 (patch) | |
tree | f597297100d3eaeb0dc76819a37e43d966f06a84 /lib/widgets | |
parent | e1ddd3e07929a6200ae58272b22c8bb98de323c7 (diff) | |
download | gsoc2013-epiphany-a73d4d600b8be7e21cd6ea9e956f6a7c6c3e4828.tar gsoc2013-epiphany-a73d4d600b8be7e21cd6ea9e956f6a7c6c3e4828.tar.gz gsoc2013-epiphany-a73d4d600b8be7e21cd6ea9e956f6a7c6c3e4828.tar.bz2 gsoc2013-epiphany-a73d4d600b8be7e21cd6ea9e956f6a7c6c3e4828.tar.lz gsoc2013-epiphany-a73d4d600b8be7e21cd6ea9e956f6a7c6c3e4828.tar.xz gsoc2013-epiphany-a73d4d600b8be7e21cd6ea9e956f6a7c6c3e4828.tar.zst gsoc2013-epiphany-a73d4d600b8be7e21cd6ea9e956f6a7c6c3e4828.zip |
Improve sort/priority API.
2004-07-14 Marco Pesenti Gritti <marco@gnome.org>
* lib/widgets/ephy-node-view.c: (compare_string_values),
(ephy_node_view_sort_func), (ephy_node_view_add_data_column),
(ephy_node_view_add_column), (ephy_node_view_set_priority),
(ephy_node_view_set_sort), (ephy_node_view_init):
* lib/widgets/ephy-node-view.h:
Improve sort/priority API.
* src/bookmarks/ephy-bookmarks-editor.c:
(ephy_bookmarks_editor_construct):
* src/ephy-encoding-dialog.c: (ephy_encoding_dialog_init):
* src/ephy-history-window.c: (ephy_history_window_construct):
Sort history items by last visit
Diffstat (limited to 'lib/widgets')
-rw-r--r-- | lib/widgets/ephy-node-view.c | 170 | ||||
-rw-r--r-- | lib/widgets/ephy-node-view.h | 21 |
2 files changed, 126 insertions, 65 deletions
diff --git a/lib/widgets/ephy-node-view.c b/lib/widgets/ephy-node-view.c index 3b037d3db..b6fc6480d 100644 --- a/lib/widgets/ephy-node-view.c +++ b/lib/widgets/ephy-node-view.c @@ -69,8 +69,10 @@ struct EphyNodeViewPrivate GtkTargetList *drag_targets; - int default_sort_column_id; - int priority_prop_id; + int sort_column; + GtkSortType sort_type; + guint priority_prop_id; + int priority_column; gboolean editing; int editable_property; @@ -1060,15 +1062,15 @@ cell_renderer_edited (GtkCellRendererText *cell, gtk_tree_path_free (path); } -static int +static inline int compare_string_values (const GValue *a_value, const GValue *b_value) { const char *str1, *str2; int retval; - + str1 = g_value_get_string (a_value); - str2 = g_value_get_string (b_value); - + str2 = g_value_get_string (b_value); + if (str1 == NULL) { retval = -1; @@ -1088,7 +1090,7 @@ compare_string_values (const GValue *a_value, const GValue *b_value) g_free (str_a); g_free (str_b); } - + return retval; } @@ -1096,23 +1098,48 @@ static int ephy_node_view_sort_func (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, - gpointer user_data) + EphyNodeView *view) { - GList *order; - GList *l; - int retval = 0; + GValue a_value = {0, }; + GValue b_value = {0, }; + int p_column, column, retval = 0; + GtkSortType sort_type; g_return_val_if_fail (model != NULL, 0); - g_return_val_if_fail (user_data != NULL, 0); + g_return_val_if_fail (view != NULL, 0); - order = (GList *) user_data; + p_column = view->priv->priority_column; + column = view->priv->sort_column; + sort_type = view->priv->sort_type; - for (l = order; l != NULL && retval == 0; l = g_list_next (l)) + if (p_column >= 0) { - 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, }; + gtk_tree_model_get_value (model, a, p_column, &a_value); + gtk_tree_model_get_value (model, b, p_column, &b_value); + + if (g_value_get_int (&a_value) < g_value_get_int (&b_value)) + { + retval = -1; + } + else if (g_value_get_int (&a_value) == g_value_get_int (&b_value)) + { + retval = 0; + } + else + { + retval = 1; + } + + g_value_unset (&a_value); + g_value_unset (&b_value); + } + + + if (retval == 0) + { + GType type; + + type = gtk_tree_model_get_column_type (model, column); gtk_tree_model_get_value (model, a, column, &a_value); gtk_tree_model_get_value (model, b, column, &b_value); @@ -1124,19 +1151,31 @@ ephy_node_view_sort_func (GtkTreeModel *model, break; case G_TYPE_INT: if (g_value_get_int (&a_value) < g_value_get_int (&b_value)) + { retval = -1; + } else if (g_value_get_int (&a_value) == g_value_get_int (&b_value)) + { retval = 0; + } else + { retval = 1; - break; + } + 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)); @@ -1147,8 +1186,19 @@ ephy_node_view_sort_func (GtkTreeModel *model, g_value_unset (&b_value); } - return retval; + if (sort_type == GTK_SORT_DESCENDING) + { + if (retval > 0) + { + retval = -1; + } + else if (retval < 0) + { + retval = 1; + } + } + return retval; } static void @@ -1187,7 +1237,7 @@ provide_text_weight (EphyNode *node, GValue *value, EphyNodeView *view) int ephy_node_view_add_data_column (EphyNodeView *view, GType value_type, - int prop_id, + guint prop_id, EphyTreeModelNodeValueFunc func, gpointer data) { @@ -1211,8 +1261,7 @@ GtkTreeViewColumn * ephy_node_view_add_column (EphyNodeView *view, const char *title, GType value_type, - int prop_id, - int priority_prop_id, + guint prop_id, EphyNodeViewFlags flags, EphyTreeModelNodeValueFunc icon_func) @@ -1261,12 +1310,14 @@ ephy_node_view_add_column (EphyNodeView *view, "text", column, NULL); - if (priority_prop_id >= 0) + gtk_tree_view_column_set_title (gcolumn, title); + gtk_tree_view_append_column (GTK_TREE_VIEW (view), + gcolumn); + + if (flags & EPHY_NODE_VIEW_SHOW_PRIORITY) { int wcol; - view->priv->priority_prop_id = priority_prop_id; - wcol = ephy_tree_model_node_add_func_column (view->priv->nodemodel, G_TYPE_INT, (EphyTreeModelNodeValueFunc) provide_text_weight, @@ -1275,47 +1326,46 @@ ephy_node_view_add_column (EphyNodeView *view, "weight", wcol); } - gtk_tree_view_column_set_title (gcolumn, title); - gtk_tree_view_append_column (GTK_TREE_VIEW (view), - gcolumn); - - if (flags & EPHY_NODE_VIEW_USER_SORT) + if (flags & EPHY_NODE_VIEW_SORTABLE) { - GList *order = NULL; - - order = g_list_append (order, GINT_TO_POINTER (column)); - gtk_tree_sortable_set_sort_func - (GTK_TREE_SORTABLE (view->priv->sortmodel), - column, ephy_node_view_sort_func, - order, (GtkDestroyNotify)g_list_free); gtk_tree_view_column_set_sort_column_id (gcolumn, column); } - else if (flags & EPHY_NODE_VIEW_AUTO_SORT) - { - int scol; - GList *order = NULL; - if (priority_prop_id >= 0) - { - scol = ephy_tree_model_node_add_func_column + return gcolumn; +} + +void +ephy_node_view_set_priority (EphyNodeView *view, guint priority_prop_id) +{ + int priority_column; + + priority_column = ephy_tree_model_node_add_func_column (view->priv->nodemodel, G_TYPE_INT, (EphyTreeModelNodeValueFunc) provide_priority, view); - order = g_list_append (order, GINT_TO_POINTER (scol)); - } - order = g_list_append (order, GINT_TO_POINTER (column)); - gtk_tree_sortable_set_default_sort_func - (GTK_TREE_SORTABLE (view->priv->sortmodel), - ephy_node_view_sort_func, - order, (GtkDestroyNotify)g_list_free); - gtk_tree_sortable_set_sort_column_id - (GTK_TREE_SORTABLE (view->priv->sortmodel), - GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, - GTK_SORT_ASCENDING); - } + view->priv->priority_column = priority_column; + view->priv->priority_prop_id = priority_prop_id; +} - return gcolumn; +void +ephy_node_view_set_sort (EphyNodeView *view, GType value_type, guint prop_id, + GtkSortType sort_type) +{ + GtkTreeSortable *sortable = GTK_TREE_SORTABLE (view->priv->sortmodel); + int column; + + column = ephy_tree_model_node_add_prop_column + (view->priv->nodemodel, value_type, prop_id); + view->priv->sort_column = column; + view->priv->sort_type = sort_type; + + gtk_tree_sortable_set_default_sort_func + (sortable, (GtkTreeIterCompareFunc)ephy_node_view_sort_func, + view, NULL); + gtk_tree_sortable_set_sort_column_id + (sortable, GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, + sort_type); } static void @@ -1327,6 +1377,10 @@ ephy_node_view_init (EphyNodeView *view) view->priv->editing = TRUE; view->priv->searchable_data_column = -1; view->priv->source_target_list = NULL; + view->priv->priority_column = -1; + view->priv->priority_prop_id = 0; + view->priv->sort_column = -1; + view->priv->sort_type = GTK_SORT_ASCENDING; gtk_tree_view_set_enable_search (GTK_TREE_VIEW (view), FALSE); } diff --git a/lib/widgets/ephy-node-view.h b/lib/widgets/ephy-node-view.h index 9af56e8a5..1896eb233 100644 --- a/lib/widgets/ephy-node-view.h +++ b/lib/widgets/ephy-node-view.h @@ -55,10 +55,10 @@ typedef enum typedef enum { - EPHY_NODE_VIEW_AUTO_SORT = 1, - EPHY_NODE_VIEW_USER_SORT = 2, - EPHY_NODE_VIEW_EDITABLE = 4, - EPHY_NODE_VIEW_SEARCHABLE = 8 + EPHY_NODE_VIEW_SHOW_PRIORITY = 1 << 0, + EPHY_NODE_VIEW_SORTABLE = 1 << 1, + EPHY_NODE_VIEW_EDITABLE = 1 << 2, + EPHY_NODE_VIEW_SEARCHABLE = 1 << 3 } EphyNodeViewFlags; typedef struct @@ -81,17 +81,24 @@ void ephy_node_view_enable_dnd (EphyNodeView *view); GtkTreeViewColumn *ephy_node_view_add_column (EphyNodeView *view, const char *title, GType value_type, - int prop_id, - int priority_prop_id, + guint prop_id, EphyNodeViewFlags flags, EphyTreeModelNodeValueFunc icon_func); int ephy_node_view_add_data_column (EphyNodeView *view, GType value_type, - int prop_id, + guint prop_id, EphyTreeModelNodeValueFunc func, gpointer data); +void ephy_node_view_set_sort (EphyNodeView *view, + GType value_type, + guint prop_id, + GtkSortType sort_type); + +void ephy_node_view_set_priority (EphyNodeView *view, + guint priority_prop_id); + void ephy_node_view_remove (EphyNodeView *view); gboolean ephy_node_view_has_selection (EphyNodeView *view, |