- Implemented "task undo" to counteract "task do".

This commit is contained in:
Paul Beckingham 2008-07-19 22:12:01 -04:00
parent dc1760769f
commit d265ac6c2d
6 changed files with 55 additions and 2 deletions

View file

@ -7,7 +7,9 @@ represents a feature release, and the Z represents a patch.
------ current release ---------------------------
1.5.0 (?/?/?)
1.5.0 (?/?/2008)
+ "task undo" can now retract a "task done" command, provided no reports
have been run (and therefore TDB::gc run)
------ old releases ------------------------------

View file

@ -94,7 +94,8 @@
<h4>New in version 1.5.0 (?/?/?)</h4>
<ul>
<li>
<li>"task undo" can now retract a "task done" command, provided no
reports have been run.
</ul>
<p>

View file

@ -203,6 +203,49 @@ void handleUndelete (TDB& tdb, T& task, Config& conf)
<< "command is run immediately after the errant delete command." << std::endl;
}
////////////////////////////////////////////////////////////////////////////////
// If a task is done, but is still in the pending file, then it may be undone
// simply by changing it's status.
void handleUndo (TDB& tdb, T& task, Config& conf)
{
std::vector <T> all;
tdb.allPendingT (all);
int id = task.getId ();
std::vector <T>::iterator it;
for (it = all.begin (); it != all.end (); ++it)
{
if (it->getId () == id)
{
if (it->getStatus () == T::completed)
{
if (it->getAttribute ("recur") != "")
{
std::cout << "Task does not support 'undo' for recurring tasks." << std::endl;
return;
}
T restored (*it);
restored.setStatus (T::pending);
restored.removeAttribute ("end");
tdb.modifyT (restored);
std::cout << "Task " << id << " successfully undone." << std::endl;
return;
}
else
{
std::cout << "Task " << id << " is not done - therefore cannot be undone." << std::endl;
return;
}
}
}
std::cout << "Task " << id
<< " not found - tasks can only be reliably undone if the undo" << std::endl
<< "command is run immediately after the errant done command." << std::endl;
}
////////////////////////////////////////////////////////////////////////////////
void handleVersion (Config& conf)
{

View file

@ -141,6 +141,7 @@ static const char* commands[] =
"summary",
"tags",
"undelete",
"undo",
"usage",
"version",
"",

View file

@ -125,6 +125,10 @@ static void shortUsage (Config& conf)
table.addCell (row, 1, "task done ID");
table.addCell (row, 2, "Marks the specified task as completed");
row = table.addRow ();
table.addCell (row, 1, "task undo ID");
table.addCell (row, 2, "Marks the specified done task as pending, provided a report has not yet been run");
row = table.addRow ();
table.addCell (row, 1, "task projects");
table.addCell (row, 2, "Shows a list of all project names used, and how many tasks are in each");
@ -316,6 +320,7 @@ int main (int argc, char** argv)
else if (command == "delete") handleDelete (tdb, task, conf);
else if (command == "start") handleStart (tdb, task, conf);
else if (command == "done") handleDone (tdb, task, conf);
else if (command == "undo") handleUndo (tdb, task, conf);
else if (command == "export") handleExport (tdb, task, conf);
else if (command == "version") handleVersion ( conf);
else if (command == "summary") handleReportSummary (tdb, task, conf);

View file

@ -76,6 +76,7 @@ void handleExport (TDB&, T&, Config&);
void handleDelete (TDB&, T&, Config&);
void handleStart (TDB&, T&, Config&);
void handleDone (TDB&, T&, Config&);
void handleUndo (TDB&, T&, Config&);
void handleModify (TDB&, T&, Config&);
void handleColor (Config&);