mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-29 17:07:19 +02:00
- Implemented "task undo" to counteract "task do".
This commit is contained in:
parent
dc1760769f
commit
d265ac6c2d
6 changed files with 55 additions and 2 deletions
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue