[latexila] Structure: set_model: expand all only if the tree isn't too big



commit 7dae5b079f3e22ac261e24c96cb77c4c7d68ae6e
Author: SÃbastien Wilmet <swilmet src gnome org>
Date:   Sat Jul 16 01:34:12 2011 +0200

    Structure: set_model: expand all only if the tree isn't too big
    
    And disconnect the signal "parsing-done" when the document changes.

 TODO                     |    2 --
 src/structure.vala       |   27 ++++++++++++++++++++-------
 src/structure_model.vala |   10 ++++++++++
 3 files changed, 30 insertions(+), 9 deletions(-)
---
diff --git a/TODO b/TODO
index 9c67182..24e2856 100644
--- a/TODO
+++ b/TODO
@@ -13,8 +13,6 @@ LaTeXila 2.2
 	- Some problems with the latex and latexmk post processors
 
 - Structure:
-	- When setting a model, expand all only if the tree is not too big
-
 	- Insert in middle is very slow comparated to insert at the end
 	  => Insert environments as soon as we find the \begin, and then update the item (or delete it)
 
diff --git a/src/structure.vala b/src/structure.vala
index eb27d45..d983385 100644
--- a/src/structure.vala
+++ b/src/structure.vala
@@ -480,8 +480,14 @@ public class Structure : VBox
         set_model (null);
         _tree_view.columns_autosize ();
 
+        if (_document_structure != null)
+            _document_structure.notify["parsing-done"].disconnect (on_parsing_done);
+
         if (doc == null)
+        {
+            _document_structure = null;
             return;
+        }
 
         _document_structure = doc.get_structure ();
 
@@ -489,20 +495,27 @@ public class Structure : VBox
             _document_structure.parse ();
 
         if (_document_structure.parsing_done)
-            set_model (_document_structure.get_model ());
+            on_parsing_done ();
+        else
+            _document_structure.notify["parsing-done"].connect (on_parsing_done);
+    }
 
-        _document_structure.notify["parsing-done"].connect (() =>
-        {
-            if (_document_structure.parsing_done)
-                set_model (_document_structure.get_model ());
-        });
+    private void on_parsing_done ()
+    {
+        return_if_fail (_document_structure != null);
+
+        if (_document_structure.parsing_done)
+            set_model (_document_structure.get_model ());
     }
 
     private void set_model (StructureModel? model)
     {
         _model = model;
         _tree_view.set_model (model);
-        _tree_view.expand_all ();
+
+        // expand all can be slow with big documents
+        if (model != null && model.get_nb_items () <= 2000)
+            _tree_view.expand_all ();
 
         populate_simple_list ();
     }
diff --git a/src/structure_model.vala b/src/structure_model.vala
index f90453e..220cc7c 100644
--- a/src/structure_model.vala
+++ b/src/structure_model.vala
@@ -56,6 +56,7 @@ public class StructureModel : TreeModel, GLib.Object
     private Type[] _column_types;
     private Node<StructData?> _tree;
     private int _stamp;
+    private uint _nb_nodes = 0;
 
     private Gee.ArrayList<unowned Node<StructData?>> _list_labels;
     private Gee.ArrayList<unowned Node<StructData?>> _list_includes;
@@ -343,6 +344,11 @@ public class StructureModel : TreeModel, GLib.Object
     /*************************************************************************/
     // Custom methods
 
+    public uint get_nb_items ()
+    {
+        return _nb_nodes;
+    }
+
     public void add_item_at_end (StructData item)
     {
         /* search the parent, based on the type */
@@ -595,6 +601,8 @@ public class StructureModel : TreeModel, GLib.Object
             TreePath parent_path = get_path (parent_iter);
             row_has_child_toggled (parent_path, parent_iter);
         }
+
+        _nb_nodes++;
     }
 
     private Node<StructData?>? delete_node (Node<StructData?> node)
@@ -616,6 +624,8 @@ public class StructureModel : TreeModel, GLib.Object
             row_has_child_toggled (parent_path, parent_iter);
         }
 
+        _nb_nodes -= node_unlinked.n_nodes (TraverseFlags.ALL);
+
         return node_unlinked;
     }
 



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