[latexila] Structure actions: display a warning if the action fails



commit fbdb81da4707782f25e5ba2d63a6d59ba0eca3bb
Author: SÃbastien Wilmet <swilmet src gnome org>
Date:   Tue Jul 5 23:50:12 2011 +0200

    Structure actions: display a warning if the action fails

 TODO                        |    4 ++--
 src/document_structure.vala |   25 ++++++++++++++++++++-----
 src/structure.vala          |    6 +++++-
 src/structure_model.vala    |    3 ++-
 4 files changed, 29 insertions(+), 9 deletions(-)
---
diff --git a/TODO b/TODO
index 4e200f5..cf68ae1 100644
--- a/TODO
+++ b/TODO
@@ -9,8 +9,8 @@ LaTeXila 2.2
 - Structure (list of chapters, sections, etc. to easily navigate in a document):
 	- Right click:
 		- shift left
-		- display a warning if the action fails (most probably when the structure data
-		  is not up-to-date)
+		- shift right: if an error occurs but some changes are already made to the document,
+		  undo these changes.
 
 	  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
diff --git a/src/document_structure.vala b/src/document_structure.vala
index 3f742b6..6dffd3b 100644
--- a/src/document_structure.vala
+++ b/src/document_structure.vala
@@ -565,9 +565,10 @@ public class DocumentStructure : GLib.Object
     {
         if (action_type == StructAction.COMMENT)
         {
-            bool item_commented = comment_item (tree_iter);
-            if (item_commented)
-                _model.delete (tree_iter);
+            if (! comment_item (tree_iter))
+                throw new StructError.DATA_OUTDATED ("");
+
+            _model.delete (tree_iter);
             return;
         }
 
@@ -581,19 +582,24 @@ public class DocumentStructure : GLib.Object
                     _("The structure item already contains a sub-paragraph."));
 
             _doc.begin_user_action ();
-            shift_right (tree_iter);
+            bool success = shift_right (tree_iter);
             _doc.end_user_action ();
 
+            if (! success)
+                throw new StructError.DATA_OUTDATED ("");
+
             _model.shift_right (tree_iter);
             return;
         }
 
+        /* Select, copy, cut and delete */
+
         TextIter? start_iter;
         TextIter? end_iter;
         bool found = get_exact_item_bounds (tree_iter, out start_iter, out end_iter);
 
         if (! found)
-            return;
+            throw new StructError.DATA_OUTDATED ("");
 
         if (start_iter.get_line () != end_iter.get_line ())
         {
@@ -942,6 +948,15 @@ public class DocumentStructure : GLib.Object
         if (markup_name == null)
             return false;
 
+        LowLevelType? markup_type = get_markup_low_level_type (markup_name);
+        if (markup_type == null)
+            return false;
+
+        // HACK see https://bugzilla.gnome.org/show_bug.cgi?id=652781
+        LowLevelType markup_type_hack = markup_type;
+        if ((int) type != (int) markup_type_hack)
+            return false;
+
         /* Get the new markup name */
         bool with_star = markup_name.has_suffix ("*");
 
diff --git a/src/structure.vala b/src/structure.vala
index 3ba8df6..cc3910b 100644
--- a/src/structure.vala
+++ b/src/structure.vala
@@ -563,7 +563,11 @@ public class Structure : VBox
                 _("Structure action error: %s"),
                 get_action_name (action_type));
 
-            dialog.secondary_text = e.message;
+            if (e is StructError.DATA_OUTDATED)
+                dialog.secondary_text =
+                    _("The structure data seems outdated. Please refresh the structure.");
+            else
+                dialog.secondary_text = e.message;
 
             dialog.run ();
             dialog.destroy ();
diff --git a/src/structure_model.vala b/src/structure_model.vala
index 2b713b3..7a13eba 100644
--- a/src/structure_model.vala
+++ b/src/structure_model.vala
@@ -47,7 +47,8 @@ public enum StructListColumn
 }
 
 public errordomain StructError {
-    GENERAL
+    GENERAL,
+    DATA_OUTDATED
 }
 
 public class StructureModel : TreeModel, GLib.Object



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