[latexila] Fix structure update when active document changes
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] Fix structure update when active document changes
- Date: Fri, 10 Jun 2011 19:44:21 +0000 (UTC)
commit 9524300a93ce498d9fc37398866fd9158447644f
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date: Thu Jun 9 13:55:14 2011 +0200
Fix structure update when active document changes
At first, I tried
StructType? _current_list_type;
and set this variable to null if the simple list is hidden.
But when comparing this variable with another StructType, the comparison
was a "pointer comparison" (not the values). So there is a second boolean
variable:
bool _list_is_hidden;
And it is better like that because a variable should be used only for
one purpose.
src/document_structure.vala | 5 ++-
src/structure.vala | 59 +++++++++++++++++++++++++++++-------------
2 files changed, 44 insertions(+), 20 deletions(-)
---
diff --git a/src/document_structure.vala b/src/document_structure.vala
index f8f06ad..b235099 100644
--- a/src/document_structure.vala
+++ b/src/document_structure.vala
@@ -43,7 +43,7 @@ public class DocumentStructure : GLib.Object
private static const bool _measure_parsing_time = false;
private Timer _timer = null;
- public signal void parsing_done ();
+ public bool parsing_done { get; private set; default = false; }
public DocumentStructure (TextBuffer doc)
{
@@ -70,6 +70,7 @@ public class DocumentStructure : GLib.Object
public void parse ()
{
// reset
+ parsing_done = false;
_model = new StructureModel ();
_in_figure_env = false;
_in_table_env = false;
@@ -182,7 +183,7 @@ public class DocumentStructure : GLib.Object
_timer.reset ();
}
- parsing_done ();
+ parsing_done = true;
return false;
}
diff --git a/src/structure.vala b/src/structure.vala
index 348a55b..6ac0998 100644
--- a/src/structure.vala
+++ b/src/structure.vala
@@ -47,6 +47,8 @@ public class Structure : VBox
private StructureModel? _model = null;
private Widget _list_view_sw;
private ListStore _list_store;
+ private StructType _current_list_type;
+ private bool _list_is_hidden = true;
private static string[] _icons = null;
private static string[] _names = null;
@@ -125,8 +127,9 @@ public class Structure : VBox
{
return_val_if_fail (types.length > 0, null);
+ StructType cur_type = types[0];
ToggleButton button =
- Utils.get_toolbar_toggle_button (get_icon_from_type (types[0]));
+ Utils.get_toolbar_toggle_button (get_icon_from_type (cur_type));
button.tooltip_text = tooltip;
@@ -136,10 +139,20 @@ public class Structure : VBox
{
if (! button.get_active ())
{
- _list_view_sw.hide ();
+ if (! _list_is_hidden && _current_list_type == cur_type)
+ {
+ _list_is_hidden = true;
+ _list_view_sw.hide ();
+ }
return;
}
+ _current_list_type = cur_type;
+ _list_is_hidden = false;
+ _list_view_sw.show_all ();
+ populate_simple_list ();
+
+ // deselect the other buttons
foreach (ToggleButton simple_list_button in _simple_list_buttons)
{
if (simple_list_button == button)
@@ -147,19 +160,19 @@ public class Structure : VBox
simple_list_button.set_active (false);
}
-
- _list_view_sw.show_all ();
-
- // populate the list
- _list_store.clear ();
-
- if (_model != null)
- _model.populate_list (_list_store, types[0]);
});
return button;
}
+ private void populate_simple_list ()
+ {
+ _list_store.clear ();
+
+ if (_model != null && ! _list_is_hidden)
+ _model.populate_list (_list_store, _current_list_type);
+ }
+
private void init_vpaned ()
{
_vpaned = new VPaned ();
@@ -277,26 +290,36 @@ public class Structure : VBox
private void show_document (Document? doc, bool force_parse = false)
{
+ set_model (null);
+ _tree_view.columns_autosize ();
+
if (doc == null)
return;
- _model = null;
- _tree_view.set_model (null);
- _tree_view.columns_autosize ();
-
DocumentStructure doc_struct = doc.get_structure ();
if (force_parse)
doc_struct.parse ();
- doc_struct.parsing_done.connect (() =>
+ if (doc_struct.parsing_done)
+ set_model (doc_struct.get_model ());
+
+ doc_struct.notify["parsing-done"].connect (() =>
{
- _model = doc_struct.get_model ();
- _tree_view.set_model (_model);
- _tree_view.expand_all ();
+ if (doc_struct.parsing_done)
+ set_model (doc_struct.get_model ());
});
}
+ private void set_model (StructureModel? model)
+ {
+ _model = model;
+ _tree_view.set_model (model);
+ _tree_view.expand_all ();
+
+ populate_simple_list ();
+ }
+
public void connect_parsing ()
{
_main_window.notify["active-document"].connect (show_active_document);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]