- TDB2::add no longer assumes that adding one task results in only one task
  begin added, as hook processing may expand the set.
This commit is contained in:
Paul Beckingham 2014-09-14 14:56:54 -04:00
parent f3c035d2b8
commit ac833c183a

View file

@ -560,31 +560,49 @@ void TDB2::add (Task& task, bool add_to_backlog /* = true */)
{ {
// Ensure the task is consistent, and provide defaults if necessary. // Ensure the task is consistent, and provide defaults if necessary.
task.validate (); task.validate ();
std::string uuid = task.get ("uuid");
// If the tasks are loaded, then verify that this uuid is not already in // If the tasks are loaded, then verify that this uuid is not already in
// the file. // the file.
if (!verifyUniqueUUID (task.get ("uuid"))) if (!verifyUniqueUUID (uuid))
throw format (STRING_TDB2_UUID_NOT_UNIQUE, task.get ("uuid")); throw format (STRING_TDB2_UUID_NOT_UNIQUE, uuid);
// Add new task to either pending or completed. // Create a vector tasks, as hooks can cause them to multiply.
std::string status = task.get ("status"); std::vector <Task> toAdd;
if (status == "completed" || toAdd.push_back (task);
status == "deleted")
completed.add_task (task);
else
pending.add_task (task);
// Add undo data lines: // TODO call hooks.
// time <time> // context.hooks.onAdd (toAdd);
// new <task>
// ---
undo.add_line ("time " + Date ().toEpochString () + "\n");
undo.add_line ("new " + task.composeF4 () + "\n");
undo.add_line ("---\n");
// Add task to backlog. std::vector <Task>::iterator i;
if (add_to_backlog) for (i = toAdd.begin (); i != toAdd.end (); ++i)
backlog.add_line (task.composeJSON () + "\n"); {
// TODO Upgrade to add or modify, not just add.
// Add new task to either pending or completed.
std::string status = i->get ("status");
if (status == "completed" ||
status == "deleted")
completed.add_task (*i);
else
pending.add_task (*i);
// Add undo data lines:
// time <time>
// new <task>
// ---
undo.add_line ("time " + Date ().toEpochString () + "\n");
undo.add_line ("new " + i->composeF4 () + "\n");
undo.add_line ("---\n");
// Add task to backlog.
if (add_to_backlog)
backlog.add_line (i->composeJSON () + "\n");
// The original task may be further referenced by the caller.
if (i->get ("uuid") == uuid)
task = *i;
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -593,28 +611,41 @@ void TDB2::modify (Task& task, bool add_to_backlog /* = true */)
// Ensure the task is consistent, and provide defaults if necessary. // Ensure the task is consistent, and provide defaults if necessary.
task.validate (false); task.validate (false);
// Find task, overwrite it. // Create a vector tasks, as hooks can cause them to multiply.
Task original; std::vector <Task> toModify;
get (task.get ("uuid"), original); toModify.push_back (task);
if (taskDiff (original, task)) // TODO call hooks.
// context.hooks.onModify (toModify);
std::vector <Task>::iterator i;
for (i = toModify.begin (); i != toModify.end (); ++i)
{ {
// Update the task, wherever it is. // Find task, overwrite it.
if (!pending.modify_task (task)) Task original;
completed.modify_task (task); get (task.get ("uuid"), original);
// time <time> if (taskDiff (original, task))
// old <task> {
// new <task> // TODO Upgrade to add or modify, not just add.
// ---
undo.add_line ("time " + Date ().toEpochString () + "\n");
undo.add_line ("old " + original.composeF4 () + "\n");
undo.add_line ("new " + task.composeF4 () + "\n");
undo.add_line ("---\n");
// Add modified task to backlog. // Update the task, wherever it is.
if (add_to_backlog) if (!pending.modify_task (task))
backlog.add_line (task.composeJSON () + "\n"); completed.modify_task (task);
// time <time>
// old <task>
// new <task>
// ---
undo.add_line ("time " + Date ().toEpochString () + "\n");
undo.add_line ("old " + original.composeF4 () + "\n");
undo.add_line ("new " + task.composeF4 () + "\n");
undo.add_line ("---\n");
// Add modified task to backlog.
if (add_to_backlog)
backlog.add_line (task.composeJSON () + "\n");
}
} }
} }