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 | |
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
-rw-r--r-- | ChangeLog | 17 | ||||
-rw-r--r-- | lib/widgets/ephy-node-view.c | 170 | ||||
-rw-r--r-- | lib/widgets/ephy-node-view.h | 21 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-editor.c | 14 | ||||
-rw-r--r-- | src/ephy-encoding-dialog.c | 6 | ||||
-rw-r--r-- | src/ephy-history-window.c | 17 |
6 files changed, 168 insertions, 77 deletions
@@ -1,3 +1,20 @@ +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 + 2004-07-12 Marco Pesenti Gritti <marco@gnome.org> * src/bookmarks/ephy-bookmark-action.c: (properties_activate_cb), 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, diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c index a22ae3191..26f657154 100644 --- a/src/bookmarks/ephy-bookmarks-editor.c +++ b/src/bookmarks/ephy-bookmarks-editor.c @@ -1500,10 +1500,13 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor) ephy_node_view_add_column (EPHY_NODE_VIEW (key_view), _("Topics"), G_TYPE_STRING, EPHY_NODE_KEYWORD_PROP_NAME, - EPHY_NODE_KEYWORD_PROP_PRIORITY, - EPHY_NODE_VIEW_AUTO_SORT | + EPHY_NODE_VIEW_SHOW_PRIORITY | EPHY_NODE_VIEW_EDITABLE | EPHY_NODE_VIEW_SEARCHABLE, NULL); + ephy_node_view_set_priority (EPHY_NODE_VIEW (key_view), + EPHY_NODE_KEYWORD_PROP_PRIORITY); + ephy_node_view_set_sort (EPHY_NODE_VIEW (key_view), G_TYPE_STRING, + EPHY_NODE_KEYWORD_PROP_NAME, GTK_SORT_ASCENDING); gtk_container_add (GTK_CONTAINER (scrolled_window), key_view); gtk_widget_set_size_request (key_view, 130, -1); gtk_widget_show (key_view); @@ -1560,15 +1563,16 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor) col_id); editor->priv->title_col = ephy_node_view_add_column (EPHY_NODE_VIEW (bm_view), _("Title"), - G_TYPE_STRING, EPHY_NODE_BMK_PROP_TITLE, -1, - EPHY_NODE_VIEW_AUTO_SORT | + G_TYPE_STRING, EPHY_NODE_BMK_PROP_TITLE, EPHY_NODE_VIEW_EDITABLE | EPHY_NODE_VIEW_SEARCHABLE, provide_favicon); editor->priv->address_col = ephy_node_view_add_column (EPHY_NODE_VIEW (bm_view), _("Address"), G_TYPE_STRING, EPHY_NODE_BMK_PROP_LOCATION, - -1, 0, NULL); + 0, NULL); + ephy_node_view_set_sort (EPHY_NODE_VIEW (bm_view), G_TYPE_STRING, + EPHY_NODE_BMK_PROP_TITLE, GTK_SORT_ASCENDING); gtk_container_add (GTK_CONTAINER (scrolled_window), bm_view); gtk_widget_show (bm_view); editor->priv->bm_view = bm_view; diff --git a/src/ephy-encoding-dialog.c b/src/ephy-encoding-dialog.c index adf0f61f3..3f6cae00b 100644 --- a/src/ephy-encoding-dialog.c +++ b/src/ephy-encoding-dialog.c @@ -315,11 +315,13 @@ ephy_encoding_dialog_init (EphyEncodingDialog *dialog) ephy_node_view_add_column (EPHY_NODE_VIEW (treeview), _("Encodings"), G_TYPE_STRING, EPHY_NODE_ENCODING_PROP_TITLE_ELIDED, - -1, - EPHY_NODE_VIEW_AUTO_SORT | EPHY_NODE_VIEW_SEARCHABLE, NULL); + ephy_node_view_set_sort (EPHY_NODE_VIEW (treeview), G_TYPE_STRING, + EPHY_NODE_ENCODING_PROP_TITLE_ELIDED, + GTK_SORT_ASCENDING); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(treeview), FALSE); diff --git a/src/ephy-history-window.c b/src/ephy-history-window.c index 76da44ec3..69f3a3c91 100644 --- a/src/ephy-history-window.c +++ b/src/ephy-history-window.c @@ -1272,10 +1272,14 @@ ephy_history_window_construct (EphyHistoryWindow *editor) ephy_node_view_add_column (EPHY_NODE_VIEW (sites_view), _("Sites"), G_TYPE_STRING, EPHY_NODE_PAGE_PROP_TITLE, - EPHY_NODE_PAGE_PROP_PRIORITY, - EPHY_NODE_VIEW_AUTO_SORT | - EPHY_NODE_VIEW_SEARCHABLE, + EPHY_NODE_VIEW_SEARCHABLE | + EPHY_NODE_VIEW_SHOW_PRIORITY, provide_favicon); + ephy_node_view_set_priority (EPHY_NODE_VIEW (sites_view), + EPHY_NODE_PAGE_PROP_PRIORITY); + ephy_node_view_set_sort (EPHY_NODE_VIEW (sites_view), G_TYPE_STRING, + EPHY_NODE_PAGE_PROP_TITLE, + GTK_SORT_ASCENDING); gtk_container_add (GTK_CONTAINER (scrolled_window), sites_view); gtk_widget_show (sites_view); editor->priv->sites_view = sites_view; @@ -1325,15 +1329,18 @@ ephy_history_window_construct (EphyHistoryWindow *editor) n_page_drag_types, col_id); col = ephy_node_view_add_column (EPHY_NODE_VIEW (pages_view), _("Title"), G_TYPE_STRING, EPHY_NODE_PAGE_PROP_TITLE, - -1, EPHY_NODE_VIEW_USER_SORT | + EPHY_NODE_VIEW_SORTABLE | EPHY_NODE_VIEW_SEARCHABLE, NULL); gtk_tree_view_column_set_max_width (col, 250); editor->priv->title_col = col; col = ephy_node_view_add_column (EPHY_NODE_VIEW (pages_view), _("Address"), G_TYPE_STRING, EPHY_NODE_PAGE_PROP_LOCATION, - -1, EPHY_NODE_VIEW_USER_SORT, NULL); + EPHY_NODE_VIEW_SORTABLE, NULL); gtk_tree_view_column_set_max_width (col, 200); editor->priv->address_col = col; + ephy_node_view_set_sort (EPHY_NODE_VIEW (pages_view), G_TYPE_INT, + EPHY_NODE_PAGE_PROP_LAST_VISIT, + GTK_SORT_DESCENDING); gtk_container_add (GTK_CONTAINER (scrolled_window), pages_view); gtk_widget_show (pages_view); editor->priv->pages_view = pages_view; |