[latexila] Structure: simple list: display items



commit deb058c36bd89e20b1dc15a4a027feed38d98575
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Wed Jun 8 20:08:36 2011 +0200

    Structure: simple list: display items
    
    If we click on an item, it does nothing. It's for the next commit ;)

 src/structure.vala       |   81 +++++++++++++++++++++++++++++++++++-----------
 src/structure_model.vala |   74 ++++++++++++++++++++++++++++++++++++++---
 2 files changed, 130 insertions(+), 25 deletions(-)
---
diff --git a/src/structure.vala b/src/structure.vala
index 4e45488..348a55b 100644
--- a/src/structure.vala
+++ b/src/structure.vala
@@ -43,8 +43,10 @@ public class Structure : VBox
 
     private ToggleButton[] _simple_list_buttons = {};
     private VPaned _vpaned;
-    private Label _simple_list;
     private TreeView _tree_view;
+    private StructureModel? _model = null;
+    private Widget _list_view_sw;
+    private ListStore _list_store;
 
     private static string[] _icons = null;
     private static string[] _names = null;
@@ -56,10 +58,10 @@ public class Structure : VBox
 
         init_toolbar ();
         init_vpaned ();
-        init_simple_list ();
+        init_list_view ();
         init_tree_view ();
         show_all ();
-        _simple_list.hide ();
+        _list_view_sw.hide ();
 
         show.connect (connect_parsing);
         hide.connect (disconnect_parsing);
@@ -134,7 +136,7 @@ public class Structure : VBox
         {
             if (! button.get_active ())
             {
-                _simple_list.hide ();
+                _list_view_sw.hide ();
                 return;
             }
 
@@ -146,7 +148,13 @@ public class Structure : VBox
                 simple_list_button.set_active (false);
             }
 
-            _simple_list.show_all ();
+            _list_view_sw.show_all ();
+
+            // populate the list
+            _list_store.clear ();
+
+            if (_model != null)
+                _model.populate_list (_list_store, types[0]);
         });
 
         return button;
@@ -167,19 +175,48 @@ public class Structure : VBox
         settings.set_int ("structure-paned-position", _vpaned.get_position ());
     }
 
-    private void init_simple_list ()
+    private void init_list_view ()
     {
-        _simple_list = new Label ("Simple list");
-        _vpaned.add1 (_simple_list);
+        TreeView list_view = get_new_tree_view ();
+
+        _list_store = new ListStore (StructColumn.N_COLUMNS,
+            typeof (string),    // pixbuf
+            typeof (string),    // text
+            typeof (string),    // tooltip
+            typeof (TextMark)   // mark (not used)
+        );
+
+        list_view.set_model (_list_store);
+
+        // selection
+        TreeSelection select = list_view.get_selection ();
+        select.set_select_function (on_list_row_selection);
+
+        // with a scrollbar
+        _list_view_sw = Utils.add_scrollbar (list_view);
+        _vpaned.add1 (_list_view_sw);
     }
 
     private void init_tree_view ()
     {
-        _tree_view = new TreeView ();
-        _tree_view.headers_visible = false;
+        _tree_view = get_new_tree_view ();
+
+        // selection
+        TreeSelection select = _tree_view.get_selection ();
+        select.set_select_function (on_tree_row_selection);
+
+        // with a scrollbar
+        Widget sw = Utils.add_scrollbar (_tree_view);
+        _vpaned.add2 (sw);
+    }
+
+    private TreeView get_new_tree_view ()
+    {
+        TreeView tree_view = new TreeView ();
+        tree_view.headers_visible = false;
 
         TreeViewColumn column = new TreeViewColumn ();
-        _tree_view.append_column (column);
+        tree_view.append_column (column);
 
         // icon
         CellRendererPixbuf pixbuf_renderer = new CellRendererPixbuf ();
@@ -192,19 +229,16 @@ public class Structure : VBox
         column.set_attributes (text_renderer, "text", StructColumn.TEXT, null);
 
         // tooltip
-        _tree_view.set_tooltip_column (StructColumn.TOOLTIP);
+        tree_view.set_tooltip_column (StructColumn.TOOLTIP);
 
         // selection
-        TreeSelection select = _tree_view.get_selection ();
+        TreeSelection select = tree_view.get_selection ();
         select.set_mode (SelectionMode.SINGLE);
-        select.set_select_function (on_row_selection);
 
-        // with a scrollbar
-        Widget sw = Utils.add_scrollbar (_tree_view);
-        _vpaned.add2 (sw);
+        return tree_view;
     }
 
-    private bool on_row_selection (TreeSelection selection, TreeModel model,
+    private bool on_tree_row_selection (TreeSelection selection, TreeModel model,
         TreePath path, bool path_currently_selected)
     {
         TreeIter tree_iter;
@@ -229,6 +263,13 @@ public class Structure : VBox
         return true;
     }
 
+    private bool on_list_row_selection (TreeSelection selection, TreeModel model,
+        TreePath path, bool path_currently_selected)
+    {
+        // the row is not selected
+        return false;
+    }
+
     private void show_active_document ()
     {
         show_document (_main_window.active_document);
@@ -239,6 +280,7 @@ public class Structure : VBox
         if (doc == null)
             return;
 
+        _model = null;
         _tree_view.set_model (null);
         _tree_view.columns_autosize ();
 
@@ -249,7 +291,8 @@ public class Structure : VBox
 
         doc_struct.parsing_done.connect (() =>
         {
-            _tree_view.set_model (doc_struct.get_model ());
+            _model = doc_struct.get_model ();
+            _tree_view.set_model (_model);
             _tree_view.expand_all ();
         });
     }
diff --git a/src/structure_model.vala b/src/structure_model.vala
index ae3d910..02ffbb3 100644
--- a/src/structure_model.vala
+++ b/src/structure_model.vala
@@ -29,7 +29,6 @@ public struct StructData
 public enum StructColumn
 {
     PIXBUF,
-    TYPE,
     TEXT,
     TOOLTIP,
     MARK,
@@ -42,11 +41,16 @@ public class StructureModel : TreeModel, GLib.Object
     private Node<StructData?> _tree;
     private int _stamp;
 
+    private Gee.ArrayList<unowned Node<StructData?>> _list_labels;
+    private Gee.ArrayList<unowned Node<StructData?>> _list_includes;
+    private Gee.ArrayList<unowned Node<StructData?>> _list_tables;
+    private Gee.ArrayList<unowned Node<StructData?>> _list_figures;
+    private Gee.ArrayList<unowned Node<StructData?>> _list_todo_and_fixme;
+
     public StructureModel ()
     {
         _column_types = new Type[StructColumn.N_COLUMNS];
         _column_types[StructColumn.PIXBUF]  = typeof (string);
-        _column_types[StructColumn.TYPE]    = typeof (StructType);
         _column_types[StructColumn.TEXT]    = typeof (string);
         _column_types[StructColumn.TOOLTIP] = typeof (string);
         _column_types[StructColumn.MARK]    = typeof (TextMark);
@@ -55,6 +59,12 @@ public class StructureModel : TreeModel, GLib.Object
         _tree = new Node<StructData?> (empty_data);
 
         new_stamp ();
+
+        _list_labels = new Gee.ArrayList<unowned Node<StructData?>> ();
+        _list_includes = new Gee.ArrayList<unowned Node<StructData?>> ();
+        _list_tables = new Gee.ArrayList<unowned Node<StructData?>> ();
+        _list_figures = new Gee.ArrayList<unowned Node<StructData?>> ();
+        _list_todo_and_fixme = new Gee.ArrayList<unowned Node<StructData?>> ();
     }
 
     // A new stamp should be generated each time the data in the model change
@@ -167,10 +177,6 @@ public class StructureModel : TreeModel, GLib.Object
 
         switch (column)
         {
-            case StructColumn.TYPE:
-                val = data.type;
-                break;
-
             case StructColumn.TEXT:
                 val = data.text;
                 break;
@@ -456,6 +462,13 @@ public class StructureModel : TreeModel, GLib.Object
             TreePath parent_path = get_path (parent_iter);
             row_has_child_toggled (parent_path, parent_iter);
         }
+
+        /* Store the node to a list, if it's not a section */
+        if (Structure.is_section (item.type))
+            return;
+
+        var list = get_list (item.type);
+        list.add (new_node);
     }
 
     private static int get_position_from_mark (TextMark mark)
@@ -466,6 +479,55 @@ public class StructureModel : TreeModel, GLib.Object
         return iter.get_offset ();
     }
 
+
+    /*************************************************************************/
+    // Simple lists
+
+    public void populate_list (ListStore store, StructType type)
+    {
+        var list = get_list (type);
+
+        foreach (unowned Node<StructData?> node in list)
+        {
+            StructData data = node.data;
+
+            TreeIter iter;
+            store.append (out iter);
+            store.set (iter,
+                StructColumn.PIXBUF, Structure.get_icon_from_type (data.type),
+                StructColumn.TEXT, data.text,
+                StructColumn.TOOLTIP, Structure.get_type_name (data.type),
+                -1);
+        }
+    }
+
+    private Gee.ArrayList<unowned Node<StructData?>> get_list (StructType type)
+    {
+        return_val_if_fail (! Structure.is_section (type), null);
+
+        switch (type)
+        {
+            case StructType.LABEL:
+                return _list_labels;
+
+            case StructType.INCLUDE:
+                return _list_includes;
+
+            case StructType.TABLE:
+                return _list_tables;
+
+            case StructType.FIGURE:
+                return _list_figures;
+
+            case StructType.TODO:
+            case StructType.FIXME:
+                return _list_todo_and_fixme;
+
+            default:
+                return_val_if_reached (null);
+        }
+    }
+
 //    private void print_item (StructData item)
 //    {
 //        stdout.printf ("\n=== ITEM ===\n");



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