[latexila] Structure actions: refresh the simple list if needed
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] Structure actions: refresh the simple list if needed
- Date: Fri, 15 Jul 2011 17:55:02 +0000 (UTC)
commit 12bf3c6a51a3ff0fd3382185a88f658ecea192c0
Author: SÃbastien Wilmet <swilmet src gnome org>
Date: Fri Jul 15 19:53:53 2011 +0200
Structure actions: refresh the simple list if needed
src/document_structure.vala | 9 +++-
src/structure.vala | 10 ++++-
src/structure_model.vala | 108 +++++++++++++++++++++++++++---------------
3 files changed, 85 insertions(+), 42 deletions(-)
---
diff --git a/src/document_structure.vala b/src/document_structure.vala
index 2fb6392..40d1835 100644
--- a/src/document_structure.vala
+++ b/src/document_structure.vala
@@ -560,9 +560,11 @@ public class DocumentStructure : GLib.Object
/*************************************************************************/
// Actions: cut, copy, delete, select, comment, shift left/right
- public void do_action (StructAction action_type, TreeIter tree_iter)
- throws StructError
+ public void do_action (StructAction action_type, TreeIter tree_iter,
+ out bool refresh_simple_list) throws StructError
{
+ refresh_simple_list = false;
+
/* Comment */
if (action_type == StructAction.COMMENT)
@@ -571,6 +573,7 @@ public class DocumentStructure : GLib.Object
throw new StructError.DATA_OUTDATED ("");
_model.delete (tree_iter);
+ refresh_simple_list = true;
return;
}
@@ -636,7 +639,9 @@ public class DocumentStructure : GLib.Object
_doc.begin_user_action ();
_doc.delete (start_iter, end_iter);
_doc.end_user_action ();
+
_model.delete (tree_iter);
+ refresh_simple_list = true;
}
}
diff --git a/src/structure.vala b/src/structure.vala
index 6dc76b7..eb27d45 100644
--- a/src/structure.vala
+++ b/src/structure.vala
@@ -560,9 +560,12 @@ public class Structure : VBox
return_if_fail (selected_row != -1);
+ bool refresh_simple_list = false;
+
try
{
- _document_structure.do_action (action_type, selected_iter);
+ _document_structure.do_action (action_type, selected_iter,
+ out refresh_simple_list);
}
catch (StructError e)
{
@@ -581,7 +584,12 @@ public class Structure : VBox
dialog.run ();
dialog.destroy ();
+ return;
}
+
+ // refresh the simple list if needed
+ if (refresh_simple_list)
+ populate_simple_list ();
}
private static string get_action_name (StructAction action_type)
diff --git a/src/structure_model.vala b/src/structure_model.vala
index 0909a19..f90453e 100644
--- a/src/structure_model.vala
+++ b/src/structure_model.vala
@@ -61,7 +61,7 @@ public class StructureModel : TreeModel, GLib.Object
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;
+ private Gee.ArrayList<unowned Node<StructData?>> _list_todos_and_fixmes;
public StructureModel ()
{
@@ -77,12 +77,7 @@ 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?>> ();
+ reset_simple_lists ();
}
// A new stamp should be generated each time the data in the model change
@@ -463,6 +458,8 @@ public class StructureModel : TreeModel, GLib.Object
unowned Node<StructData?> node = get_node_from_iter (iter);
delete_node (node);
+
+ regenerate_simple_lists ();
}
public void shift_right (TreeIter iter)
@@ -722,34 +719,6 @@ public class StructureModel : TreeModel, GLib.Object
make_children_between_marks (new_node);
}
- private void insert_node_in_list (Node<StructData?> node, bool at_end)
- {
- StructData item = node.data;
-
- if (Structure.is_section (item.type))
- return;
-
- var list = get_list (item.type);
-
- // if it's an append_item(), append the item to the list too
- if (at_end)
- {
- list.add (node);
- return;
- }
-
- // if the item is inserted in the middle, search where to insert it in the list
- int mark_pos = get_position_from_mark (item.start_mark);
- int i;
- for (i = 0 ; i < list.size ; i++)
- {
- int cur_mark_pos = get_position_from_mark (list[i].data.start_mark);
- if (cur_mark_pos > mark_pos)
- break;
- }
- list.insert (i, node);
- }
-
private void make_children_between_marks (Node<StructData?> node)
{
StructData data = node.data;
@@ -798,6 +767,7 @@ public class StructureModel : TreeModel, GLib.Object
public void populate_list (ListStore store, StructType type)
{
var list = get_list (type);
+ return_if_fail (list != null);
foreach (unowned Node<StructData?> node in list)
{
@@ -842,9 +812,69 @@ public class StructureModel : TreeModel, GLib.Object
return_val_if_reached (-1);
}
- private Gee.ArrayList<unowned Node<StructData?>> get_list (StructType type)
+ private void insert_node_in_list (Node<StructData?> node, bool at_end)
+ {
+ StructData item = node.data;
+
+ if (Structure.is_section (item.type))
+ return;
+
+ var list = get_list (item.type);
+ return_if_fail (list != null);
+
+ // if it's an append_item(), append the item to the list too
+ if (at_end)
+ {
+ list.add (node);
+ return;
+ }
+
+ // if the item is inserted in the middle, search where to insert it in the list
+ int mark_pos = get_position_from_mark (item.start_mark);
+ int i;
+ for (i = 0 ; i < list.size ; i++)
+ {
+ int cur_mark_pos = get_position_from_mark (list[i].data.start_mark);
+ if (cur_mark_pos > mark_pos)
+ break;
+ }
+ list.insert (i, node);
+ }
+
+ private void regenerate_simple_lists ()
+ {
+ reset_simple_lists ();
+
+ _tree.traverse (TraverseType.PRE_ORDER, TraverseFlags.ALL, -1, (node_param) =>
+ {
+ unowned Node<StructData?> node = (Node<StructData?>) node_param;
+ StructType type = node.data.type;
+ if (! Structure.is_section (type))
+ {
+ var list = get_list (type);
+ return_val_if_fail (list != null, true);
+
+ list.add (node);
+ }
+
+ // continue the traversal
+ return false;
+ });
+ }
+
+ private void reset_simple_lists ()
+ {
+ _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_todos_and_fixmes = new Gee.ArrayList<unowned Node<StructData?>> ();
+ }
+
+ private Gee.ArrayList<unowned Node<StructData?>>? get_list (StructType type)
{
- return_val_if_fail (! Structure.is_section (type), null);
+ if (Structure.is_section (type))
+ return null;
switch (type)
{
@@ -863,10 +893,10 @@ public class StructureModel : TreeModel, GLib.Object
case StructType.TODO:
case StructType.FIXME:
- return _list_todo_and_fixme;
+ return _list_todos_and_fixmes;
default:
- return_val_if_reached (null);
+ return null;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]