[gnome-todo] task-list-view: Properly remove subtasks



commit ea30cae43303dfcbe7c0b083424732c84e333cc9
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Mar 7 20:43:20 2018 -0300

    task-list-view: Properly remove subtasks
    
    We also need to remove the subtasks of the removed
    task to keep it consistent.
    
    Issue: #136

 src/gtd-task-list-view.c | 54 ++++++++++++++++++++++++++----------------------
 1 file changed, 29 insertions(+), 25 deletions(-)
---
diff --git a/src/gtd-task-list-view.c b/src/gtd-task-list-view.c
index 20dc7f7..adea0f9 100644
--- a/src/gtd-task-list-view.c
+++ b/src/gtd-task-list-view.c
@@ -534,31 +534,6 @@ add_task (GtdTaskListView *view,
  * Callbacks
  */
 
-static void
-on_clear_completed_tasks_activated_cb (GSimpleAction *simple,
-                                       GVariant      *parameter,
-                                       gpointer       user_data)
-{
-  GtdTaskListView *view;
-  GList *tasks;
-  GList *l;
-
-  view = GTD_TASK_LIST_VIEW (user_data);
-  tasks = gtd_task_list_view_get_list (view);
-
-  for (l = tasks; l != NULL; l = l->next)
-    {
-      GtdTask *task = l->data;
-
-      if (gtd_task_get_complete (task))
-        gtd_provider_remove_task (gtd_task_get_provider (task), task);
-    }
-
-  update_done_label (view);
-
-  g_list_free (tasks);
-}
-
 static gboolean
 undo_remove_task_cb (GtdTaskListView *self,
                      GtdTask         *task)
@@ -579,6 +554,35 @@ real_remove_task_cb (GtdTaskListView *self,
   return TRUE;
 }
 
+static void
+on_clear_completed_tasks_activated_cb (GSimpleAction *simple,
+                                       GVariant      *parameter,
+                                       gpointer       user_data)
+{
+  GtdTaskListView *view;
+  g_autoptr (GList) tasks = NULL;
+  g_autoptr (GList) l = NULL;
+
+  view = GTD_TASK_LIST_VIEW (user_data);
+  tasks = gtd_task_list_view_get_list (view);
+
+  for (l = tasks; l; l = l->next)
+    {
+      GtdTask *task = l->data;
+
+      if (!gtd_task_get_complete (task))
+        continue;
+
+      if (gtd_task_get_parent (task))
+        gtd_task_remove_subtask (gtd_task_get_parent (task), task);
+
+      /* Remove the subtasks recursively */
+      iterate_subtasks (view, task, real_remove_task_cb);
+    }
+
+  update_done_label (view);
+}
+
 static void
 on_remove_task_action_cb (GtdNotification *notification,
                           gpointer         user_data)


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