[devhelp/wip/swilmet/various-code-improvements] book-tree: nicer behavior when changing the group-by-language setting



commit 7f0a176d7bbfe3623c41d50195d0bee2747dc4a7
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Nov 12 21:11:04 2015 +0100

    book-tree: nicer behavior when changing the group-by-language setting
    
    1. launch devhelp, select a page
    2. go to the preferences and change the group-by-language setting
       -> the last book in the tree was opened and expanded, why?
    
    When gtk_tree_store_clear() was called after changing the setting, the
    GtkTreeView selection changed for each row deleted from the store, one
    by one. So there was a signal to open each book, and the last one wins.
    
    Now disconnect the model from the view when clearing the store, so the
    signals are not emitted, so the WebkitWebView doesn't change. Ideally I
    think it would be better to clear the WebkitWebView as well, to have a
    blank page after changing the setting. But it would be a bit more
    complicated, and the new behavior is already much better than before.
    
    Also, book_tree_init_selection() must be called.

 src/dh-book-tree.c |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/src/dh-book-tree.c b/src/dh-book-tree.c
index f56febd..e2224ee 100644
--- a/src/dh-book-tree.c
+++ b/src/dh-book-tree.c
@@ -518,7 +518,10 @@ book_tree_populate_tree (DhBookTree *tree)
         DhBookTreePrivate *priv = dh_book_tree_get_instance_private (tree);
         GList *l;
 
+        gtk_tree_view_set_model (GTK_TREE_VIEW (tree), NULL);
         gtk_tree_store_clear (priv->store);
+        gtk_tree_view_set_model (GTK_TREE_VIEW (tree),
+                                 GTK_TREE_MODEL (priv->store));
 
         /* This list comes in order, but we don't really mind */
         for (l = dh_book_manager_get_books (priv->book_manager);
@@ -608,14 +611,6 @@ book_tree_book_deleted_or_disabled_cb (DhBookManager *book_manager,
 }
 
 static void
-book_tree_group_by_language_cb (GObject    *object,
-                                GParamSpec *pspec,
-                                DhBookTree *tree)
-{
-        book_tree_populate_tree (tree);
-}
-
-static void
 book_tree_init_selection (DhBookTree *tree)
 {
         DhBookTreePrivate   *priv;
@@ -673,6 +668,15 @@ book_tree_init_selection (DhBookTree *tree)
 }
 
 static void
+book_tree_group_by_language_cb (GObject    *object,
+                                GParamSpec *pspec,
+                                DhBookTree *tree)
+{
+        book_tree_populate_tree (tree);
+        book_tree_init_selection (tree);
+}
+
+static void
 dh_book_tree_constructed (GObject *object)
 {
         DhBookTree *tree = DH_BOOK_TREE (object);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]