From 71b320b3618777982c05a1dbba165cd694942483 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 16 Jun 2009 00:08:02 -0400 Subject: [PATCH] Enhancement - undelete command - Implemented undelete command. --- src/Context.cpp | 2 -- src/command.cpp | 40 +++++++++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index a66f6fd77..cf36d091a 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -188,9 +188,7 @@ std::string Context::dispatch () else if (cmd.command == "undo") { out = handleUndo (); } */ else if (cmd.command == "delete") { out = handleDelete (); } -/* else if (cmd.command == "undelete") { out = handleUndelete (); } -*/ else if (cmd.command == "start") { out = handleStart (); } else if (cmd.command == "stop") { out = handleStop (); } else if (cmd.command == "export") { out = handleExport (); } diff --git a/src/command.cpp b/src/command.cpp index 401fd90a1..b12a05730 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -198,35 +198,49 @@ std::string handleTags () std::string handleUndelete () { std::stringstream out; -/* - std::vector all; - tdb.allPendingT (all); - filterSequence (all, task); - foreach (t, all) + std::vector tasks; + context.tdb.lock (context.config.get ("locking", true)); + context.tdb.load (tasks, context.filter); + + // Filter sequence. + context.filter.applySequence (tasks, context.sequence); + + foreach (task, tasks) { - if (t->getStatus () == T::deleted) + if (task->getStatus () == Task::deleted) { - if (t->has ("recur")) + if (task->has ("recur")) out << "Task does not support 'undo' for recurring tasks.\n"; - t->setStatus (T::pending); - t->removeAttribute ("end"); - tdb.modifyT (*t); + task->setStatus (Task::pending); + task->remove ("end"); + context.tdb.update (*task); - out << "Task " << t->getId () << " '" << t->getDescription () << "' successfully undeleted.\n"; + out << "Task " + << task->id + << " '" + << task->get ("description") + << "' successfully undeleted.\n"; } else { - out << "Task " << t->getId () << " '" << t->getDescription () << "' is not deleted - therefore cannot be undeleted.\n"; + out << "Task " + << task->id + << " '" + << task->get ("description") + << "' is not deleted - therefore cannot be undeleted.\n"; } } + context.tdb.commit (); + context.tdb.unlock (); + out << "\n" << "Please note that tasks can only be reliably undeleted if the undelete " << "command is run immediately after the errant delete command." << std::endl; -*/ + return out.str (); }