[latexila] Structure: double-click to "re-select" the item



commit 2617809fc2b6c6c2cb670c734f95105055a14e28
Author: Sébastien Wilmet <swilmet src gnome org>
Date:   Fri Jun 10 23:08:25 2011 +0200

    Structure: double-click to "re-select" the item

 TODO               |   27 ++++---------
 src/structure.vala |  107 +++++++++++++++++++++++++++++-----------------------
 2 files changed, 68 insertions(+), 66 deletions(-)
---
diff --git a/TODO b/TODO
index 6771b14..5857377 100644
--- a/TODO
+++ b/TODO
@@ -7,29 +7,10 @@ LaTeXila 2.2
 ============
 
 - Structure (list of chapters, sections, etc. to easily navigate in a document):
-	- Items overview:
-	  The problem: if we search an item, for example a figure or a TODO, it takes time to
-	  find it if there are a lot of sections.
-	  Solution: possibility to view a simple list of a certain item type. The list would be
-	  displayed below the mini-toolbar. If we click on a item in this list, the corresponding
-	  item in the complete tree is selected. The show/hide buttons would be used to change
-	  the item type of the simple list.
-
 	- Right click: cut, copy, paste below, select, delete, comment, shift left/right.
 	  Shift left/right is new comparated to Kile. For example we have a big section (with
 	  subsections, etc.) and we want to shift it to the left so it becomes a chapter (the
 	  subsections becomes sections, etc.).
-	
-	(-) Update on the fly the structure when the document is modified. An item can be inserted,
-	    deleted or modified. The simplest way I think is to re-run the parsing only on the modified
-	    lines (with a lower and upper bounds) every 2 seconds for example. This way, we simply
-	    delete all items between the two bounds, and the parsing will re-add them correcly.
-
-	(-) Scroll to the nearest item in the structure when the document's cursor moves.
-
-	(-) If the document's cursor is _in_ an item, select it in the structure. This is more
-	    complicated than it sounds because now we only know the beginning of an item, we don't
-	    know where the item ends.
 
 - Build Tools:
 	- build tools: copy button to make a copy of a build tool,
@@ -61,6 +42,14 @@ LaTeXila â?¥ 2.4
   gtk_source_completion_info_set_sizing() function.
   Also, GTK 3 widgets are a lot bigger, it doesn't fit well with LaTeXila.
 
+(-) Structure:
+	- Select the current section or item when the document cursor moves
+
+	- Update on the fly the structure when the document is modified. An item can be inserted,
+	  deleted or modified. The simplest way I think is to re-run the parsing only on the modified
+	  lines (with a lower and upper bounds) every 2 seconds for example. This way, we simply
+	  delete all items between the two bounds, and the parsing will re-add them correcly.
+
 (-) Edit toolbar: create a custom MenuToolButton:
     Now the icon does nothing when we click on it, we must always click first on the arrow and then select the item.
     It would be better if the icon is the last item used (and we can click on it).
diff --git a/src/structure.vala b/src/structure.vala
index 133c0d3..0773e15 100644
--- a/src/structure.vala
+++ b/src/structure.vala
@@ -227,8 +227,18 @@ public class Structure : VBox
         _list_view.set_model (_list_store);
 
         // selection
-        TreeSelection select = _list_view.get_selection ();
-        select.set_select_function (on_list_row_selection);
+        TreeSelection list_select = _list_view.get_selection ();
+        list_select.set_select_function ((select, model, path, path_currently_selected) =>
+        {
+            // always allow deselect
+            if (path_currently_selected)
+                return true;
+
+            return select_list_row (path);
+        });
+
+        // double-click
+        _list_view.row_activated.connect ((path) => select_list_row (path));
 
         // with a scrollbar
         _list_view_sw = Utils.add_scrollbar (_list_view);
@@ -241,8 +251,18 @@ public class Structure : VBox
             StructColumn.TOOLTIP);
 
         // selection
-        TreeSelection select = _tree_view.get_selection ();
-        select.set_select_function (on_tree_row_selection);
+        TreeSelection tree_select = _tree_view.get_selection ();
+        tree_select.set_select_function ((select, model, path, path_currently_selected) =>
+        {
+            // always allow deselect
+            if (path_currently_selected)
+                return true;
+
+            return select_tree_row (path);
+        });
+
+        // double-click
+        _tree_view.row_activated.connect ((path) => select_tree_row (path));
 
         // with a scrollbar
         Widget sw = Utils.add_scrollbar (_tree_view);
@@ -277,22 +297,51 @@ public class Structure : VBox
         return tree_view;
     }
 
-    private bool on_tree_row_selection (TreeSelection selection, TreeModel model,
-        TreePath path, bool path_currently_selected)
+    private bool select_list_row (TreePath list_path)
     {
-        // always allow deselect
-        if (path_currently_selected)
+        if (! _first_select)
+        {
+            _first_select = true;
             return true;
+        }
+
+        return_val_if_fail (_model != null, false);
+
+        /* select the corresponding item in the tree */
+        TreeSelection tree_select = _tree_view.get_selection ();
+        tree_select.unselect_all ();
+
+        int row_num = list_path.get_indices ()[0];
+
+        TreePath? tree_path =
+            _model.get_tree_path_from_list_num (_current_list_type, row_num);
+
+        return_val_if_fail (tree_path != null, false);
+
+        _tree_view.expand_to_path (tree_path);
+
+        _first_select = false;
+        tree_select.select_path (tree_path);
+
+        _tree_view.scroll_to_cell (tree_path, null, true, (float) 0.5, 0);
+
+        // the row is selected
+        return true;
+    }
 
+    private bool select_tree_row (TreePath tree_path)
+    {
+        // Reset _first_select and keep a copy, so if an error occurs, it's ok for the
+        // next select.
         bool first_select = _first_select;
         _first_select = true;
 
         TreeIter tree_iter;
-        if (! model.get_iter (out tree_iter, path))
+        if (! _model.get_iter (out tree_iter, tree_path))
             return_val_if_reached (false);
 
         TextMark mark;
-        model.get (tree_iter, StructColumn.MARK, out mark, -1);
+        _model.get (tree_iter, StructColumn.MARK, out mark, -1);
 
         /* go to the location in the document */
         TextBuffer doc = mark.get_buffer ();
@@ -302,6 +351,7 @@ public class Structure : VBox
         TextIter text_iter;
         doc.get_iter_at_mark (out text_iter, mark);
         doc.place_cursor (text_iter);
+
         // scroll to cursor, line at the top
         _main_window.active_view.scroll_to_mark (doc.get_insert (), 0, true, 0, 0);
 
@@ -315,43 +365,6 @@ public class Structure : VBox
         return true;
     }
 
-    private bool on_list_row_selection (TreeSelection selection, TreeModel model,
-        TreePath path, bool path_currently_selected)
-    {
-        // always allow deselect
-        if (path_currently_selected)
-            return true;
-
-        if (! _first_select)
-        {
-            _first_select = true;
-            return true;
-        }
-
-        return_val_if_fail (_model != null, false);
-
-        /* select the corresponding item in the tree */
-        TreeSelection tree_select = _tree_view.get_selection ();
-        tree_select.unselect_all ();
-
-        int row_num = path.get_indices ()[0];
-
-        TreePath? tree_path =
-            _model.get_tree_path_from_list_num (_current_list_type, row_num);
-
-        return_val_if_fail (tree_path != null, false);
-
-        _tree_view.expand_to_path (tree_path);
-
-        _first_select = false;
-        tree_select.select_path (tree_path);
-
-        _tree_view.scroll_to_cell (tree_path, null, true, (float) 0.5, 0);
-
-        // the row is selected
-        return true;
-    }
-
     // tree_iter is a TreeIter from the tree (not the simple list) and points to the
     // corresponding item.
     private void select_simple_list_item (TreeIter tree_iter)



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