Enhancements - undo command

- Implemented the undo command.
This commit is contained in:
Paul Beckingham 2009-06-16 00:16:43 -04:00
parent 71b320b361
commit 6a77d61faa
2 changed files with 30 additions and 18 deletions

View file

@ -184,9 +184,7 @@ std::string Context::dispatch ()
else if (cmd.command == "annotate") { out = handleAnnotate (); } else if (cmd.command == "annotate") { out = handleAnnotate (); }
*/ */
else if (cmd.command == "done") { out = handleDone (); } else if (cmd.command == "done") { out = handleDone (); }
/*
else if (cmd.command == "undo") { out = handleUndo (); } else if (cmd.command == "undo") { out = handleUndo (); }
*/
else if (cmd.command == "delete") { out = handleDelete (); } else if (cmd.command == "delete") { out = handleDelete (); }
else if (cmd.command == "undelete") { out = handleUndelete (); } else if (cmd.command == "undelete") { out = handleUndelete (); }
else if (cmd.command == "start") { out = handleStart (); } else if (cmd.command == "start") { out = handleStart (); }

View file

@ -201,7 +201,7 @@ std::string handleUndelete ()
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.get ("locking", true));
context.tdb.load (tasks, context.filter); context.tdb.loadPending (tasks, context.filter);
// Filter sequence. // Filter sequence.
context.filter.applySequence (tasks, context.sequence); context.filter.applySequence (tasks, context.sequence);
@ -211,7 +211,7 @@ std::string handleUndelete ()
if (task->getStatus () == Task::deleted) if (task->getStatus () == Task::deleted)
{ {
if (task->has ("recur")) if (task->has ("recur"))
out << "Task does not support 'undo' for recurring tasks.\n"; out << "Task does not support 'undelete' for recurring tasks.\n";
task->setStatus (Task::pending); task->setStatus (Task::pending);
task->remove ("end"); task->remove ("end");
@ -250,35 +250,49 @@ std::string handleUndelete ()
std::string handleUndo () std::string handleUndo ()
{ {
std::stringstream out; std::stringstream out;
/*
std::vector <T> all;
tdb.allPendingT (all);
filterSequence (all, task);
foreach (t, all) std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true));
context.tdb.loadPending (tasks, context.filter);
// Filter sequence.
context.filter.applySequence (tasks, context.sequence);
foreach (task, tasks)
{ {
if (t->getStatus () == T::completed) if (task->getStatus () == Task::completed)
{ {
if (t->has ("recur")) if (task->has ("recur"))
out << "Task does not support 'undo' for recurring tasks.\n"; out << "Task does not support 'undo' for recurring tasks.\n";
t->setStatus (T::pending); task->setStatus (Task::pending);
t->removeAttribute ("end"); task->remove ("end");
tdb.modifyT (*t); context.tdb.update (*task);
out << "Task " << t->getId () << " '" << t->getDescription () << "' successfully undone." << std::endl; out << "Task "
<< task->id
<< " '"
<< task->get ("description")
<< "' successfully undone.\n";
} }
else else
{ {
out << "Task " << t->getId () << " '" << t->getDescription () << "' is not done - therefore cannot be undone." << std::endl; out << "Task "
<< task->id
<< " '"
<< task->get ("description")
<< "' is not completed - therefore cannot be undone.\n";
} }
} }
out << std::endl context.tdb.commit ();
context.tdb.unlock ();
out << "\n"
<< "Please note that tasks can only be reliably undone if the undo " << "Please note that tasks can only be reliably undone if the undo "
<< "command is run immediately after the errant done command." << "command is run immediately after the errant done command."
<< std::endl; << std::endl;
*/
return out.str (); return out.str ();
} }