[latexila] DeleteTemplateDialog: delete the good templates



commit 140a6613496bdc476b88380d7f9af5b5865ff856
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Apr 19 10:50:12 2015 +0200

    DeleteTemplateDialog: delete the good templates
    
    This is an important bug fix. Wrong templates could have been deleted!
    This bug is present in latexila since many versions, and hasn't been
    reported (the FIXME comment has been added recently). I guess the dialog
    window is usually used to delete only one template at a time (in that
    case the bug doesn't occur). Many users are hopefully not aware that it
    is possible to select several templates and delete them in one go.

 src/templates_dialogs.vala |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/src/templates_dialogs.vala b/src/templates_dialogs.vala
index caa5767..0f72fad 100644
--- a/src/templates_dialogs.vala
+++ b/src/templates_dialogs.vala
@@ -279,14 +279,18 @@ public class DeleteTemplateDialog : Dialog
         while (run () == ResponseType.APPLY)
         {
             TreeSelection select = templates_list.get_selection ();
-            List<TreePath> selected_items = select.get_selected_rows (null);
-            uint nb_selected_items = selected_items.length ();
+            unowned TreeModel model;
+            List<TreePath> selected_rows = select.get_selected_rows (out model);
+            List<TreeRowReference> row_refs = null;
+
+            foreach (TreePath path in selected_rows)
+            {
+                row_refs.prepend (new TreeRowReference (model, path));
+            }
 
-            // FIXME first convert to GtkTreeRowReferences, because if there
-            // are several templates selected, the wrong templates are deleted!
-            for (int item_num = 0 ; item_num < nb_selected_items ; item_num++)
+            foreach (TreeRowReference row_ref in row_refs)
             {
-                TreePath path = selected_items.nth_data (item_num);
+                TreePath path = row_ref.get_path ();
                 templates.delete_personal_template (path);
                 template_deleted = true;
             }


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