[devhelp/wip/swilmet/various-code-improvements: 1/2] book-tree: fix get_selected_book() when books are grouped by language
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp/wip/swilmet/various-code-improvements: 1/2] book-tree: fix get_selected_book() when books are grouped by language
- Date: Thu, 12 Nov 2015 10:41:13 +0000 (UTC)
commit 67ccbb46ec84849827d4ee897bb64471408d077b
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Nov 11 20:25:37 2015 +0100
book-tree: fix get_selected_book() when books are grouped by language
dh_book_tree_get_selected_book() is used by the search hitlist to mark
in bold the results that are part of the current book. But it didn't
work when books are grouped by language.
src/dh-book-tree.c | 33 +++++++++++++++++++--------------
1 files changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/src/dh-book-tree.c b/src/dh-book-tree.c
index fbc3ef1..33d5599 100644
--- a/src/dh-book-tree.c
+++ b/src/dh-book-tree.c
@@ -822,26 +822,31 @@ dh_book_tree_get_selected_book (DhBookTree *tree)
GtkTreeSelection *selection;
GtkTreeModel *model;
GtkTreeIter iter;
- GtkTreePath *path;
- DhLink *link;
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
- if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
+ if (!gtk_tree_selection_get_selected (selection, &model, &iter))
return NULL;
- }
- path = gtk_tree_model_get_path (model, &iter);
+ /* Depending on whether books are grouped by language, the book link can
+ * be at a different depth. And it's safer to check that the returned
+ * link has the good type. So walk up the tree to find the book.
+ */
+ while (TRUE) {
+ DhLink *link;
+ GtkTreeIter parent;
- /* Get the book node for this link. */
- while (gtk_tree_path_get_depth (path) > 1)
- gtk_tree_path_up (path);
+ gtk_tree_model_get (model, &iter,
+ COL_LINK, &link,
+ -1);
- gtk_tree_model_get_iter (model, &iter, path);
- gtk_tree_path_free (path);
+ if (dh_link_get_link_type (link) == DH_LINK_TYPE_BOOK)
+ return link;
- gtk_tree_model_get (model, &iter,
- COL_LINK, &link,
- -1);
+ if (!gtk_tree_model_iter_parent (model, &parent, &iter))
+ break;
+
+ iter = parent;
+ }
- return link;
+ g_return_val_if_reached (NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]