[gnome-todo] task: Fix total subtask counter update issue
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo] task: Fix total subtask counter update issue
- Date: Thu, 13 Sep 2018 09:22:10 +0000 (UTC)
commit a360c4acf971c318b5d995ebbbe6468d3a326a2d
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Sep 12 20:05:48 2018 -0300
task: Fix total subtask counter update issue
When the total subtasks counter changes, it needs
to propagate up in the task tree
src/gtd-task.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
---
diff --git a/src/gtd-task.c b/src/gtd-task.c
index 67b08ac..1c407ad 100644
--- a/src/gtd-task.c
+++ b/src/gtd-task.c
@@ -295,6 +295,23 @@ set_depth (GtdTask *self,
}
}
+static void
+update_total_subtasks_counters (GtdTask *self,
+ gint64 total_difference)
+{
+ GtdTask *aux;
+
+ aux = self;
+ while (aux)
+ {
+ GtdTaskPrivate *aux_priv = gtd_task_get_instance_private (aux);
+
+ aux_priv->n_total_subtasks += total_difference;
+
+ aux = aux_priv->parent_task;
+ }
+}
+
static void
real_add_subtask (GtdTask *self,
GtdTask *subtask)
@@ -317,7 +334,7 @@ real_add_subtask (GtdTask *self,
/* Update counters */
priv->n_direct_subtasks += 1;
- priv->n_total_subtasks += subtask_priv->n_total_subtasks + 1;
+ update_total_subtasks_counters (self, subtask_priv->n_total_subtasks + 1);
GTD_TRACE_MSG ("Task %p is now subtask of %p", subtask, self);
@@ -339,7 +356,7 @@ real_remove_subtask (GtdTask *self,
{
GtdTaskPrivate *priv, *subtask_priv;
- g_assert (!gtd_task_is_subtask (self, subtask));
+ g_assert (gtd_task_is_subtask (self, subtask));
priv = gtd_task_get_instance_private (self);
subtask_priv = gtd_task_get_instance_private (subtask);
@@ -349,7 +366,7 @@ real_remove_subtask (GtdTask *self,
/* Update counters */
priv->n_direct_subtasks -= 1;
- priv->n_total_subtasks -= subtask_priv->n_total_subtasks + 1;
+ update_total_subtasks_counters (self, -subtask_priv->n_total_subtasks - 1);
GTD_TRACE_MSG ("Task %p was detached from %p", subtask, self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]