mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Enhancement - undo
- Removed obsolete undelete command. - Removed obsolete undo command. - Implemented new undo command as a call to the stubbed TDB::undo call.
This commit is contained in:
parent
dc2bac1b5e
commit
af7803ea27
6 changed files with 14 additions and 112 deletions
|
@ -200,9 +200,7 @@ std::string Context::dispatch ()
|
|||
else if (cmd.command == "append") { out = handleAppend (); }
|
||||
else if (cmd.command == "annotate") { out = handleAnnotate (); }
|
||||
else if (cmd.command == "done") { out = handleDone (); }
|
||||
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 (); }
|
||||
|
@ -212,6 +210,7 @@ std::string Context::dispatch ()
|
|||
#ifdef FEATURE_SHELL
|
||||
else if (cmd.command == "shell") { handleShell (); }
|
||||
#endif
|
||||
else if (cmd.command == "undo") { handleUndo (); }
|
||||
else if (cmd.command == "" &&
|
||||
sequence.size ()) { out = handleModify (); }
|
||||
|
||||
|
|
|
@ -488,6 +488,11 @@ int TDB::nextId ()
|
|||
return mId++;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void TDB::undo ()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
FILE* TDB::openAndLock (const std::string& file)
|
||||
{
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
int commit (); // Write out all tasks
|
||||
int gc (); // Clean up pending
|
||||
int nextId ();
|
||||
void undo ();
|
||||
|
||||
private:
|
||||
FILE* openAndLock (const std::string&);
|
||||
|
|
102
src/command.cpp
102
src/command.cpp
|
@ -206,107 +206,9 @@ std::string handleTags ()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// If a task is deleted, but is still in the pending file, then it may be
|
||||
// undeleted simply by changing it's status.
|
||||
std::string handleUndelete ()
|
||||
void handleUndo ()
|
||||
{
|
||||
std::stringstream out;
|
||||
|
||||
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 (task->getStatus () == Task::deleted)
|
||||
{
|
||||
if (task->has ("recur"))
|
||||
out << "Task does not support 'undelete' for recurring tasks.\n";
|
||||
|
||||
task->setStatus (Task::pending);
|
||||
task->remove ("end");
|
||||
context.tdb.update (*task);
|
||||
|
||||
out << "Task "
|
||||
<< task->id
|
||||
<< " '"
|
||||
<< task->get ("description")
|
||||
<< "' successfully undeleted.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
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 ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// If a task is done, but is still in the pending file, then it may be undone
|
||||
// simply by changing it's status.
|
||||
std::string handleUndo ()
|
||||
{
|
||||
std::stringstream out;
|
||||
|
||||
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 (task->getStatus () == Task::completed)
|
||||
{
|
||||
if (task->has ("recur"))
|
||||
out << "Task does not support 'undo' for recurring tasks.\n";
|
||||
|
||||
task->setStatus (Task::pending);
|
||||
task->remove ("end");
|
||||
context.tdb.update (*task);
|
||||
|
||||
out << "Task "
|
||||
<< task->id
|
||||
<< " '"
|
||||
<< task->get ("description")
|
||||
<< "' successfully undone.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
out << "Task "
|
||||
<< task->id
|
||||
<< " '"
|
||||
<< task->get ("description")
|
||||
<< "' is not completed - therefore cannot be undone.\n";
|
||||
}
|
||||
}
|
||||
|
||||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
out << "\n"
|
||||
<< "Please note that tasks can only be reliably undone if the undo "
|
||||
<< "command is run immediately after the errant done command."
|
||||
<< std::endl;
|
||||
|
||||
return out.str ();
|
||||
context.tdb.undo ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -61,15 +61,14 @@ std::string handleDone ();
|
|||
std::string handleModify ();
|
||||
std::string handleProjects ();
|
||||
std::string handleTags ();
|
||||
std::string handleUndelete ();
|
||||
std::string handleVersion ();
|
||||
std::string handleDelete ();
|
||||
std::string handleStart ();
|
||||
std::string handleStop ();
|
||||
std::string handleUndo ();
|
||||
std::string handleColor ();
|
||||
std::string handleAnnotate ();
|
||||
std::string handleDuplicate ();
|
||||
void handleUndo ();
|
||||
#ifdef FEATURE_SHELL
|
||||
void handleShell ();
|
||||
#endif
|
||||
|
|
|
@ -99,6 +99,10 @@ std::string shortUsage ()
|
|||
table.addCell (row, 1, "task edit ID");
|
||||
table.addCell (row, 2, "Launches an editor to let you modify all aspects of a task directly, therefore it is to be used carefully.");
|
||||
|
||||
row = table.addRow ();
|
||||
table.addCell (row, 1, "task undo");
|
||||
table.addCell (row, 2, "Reverts the most recent action.");
|
||||
|
||||
#ifdef FEATURE_SHELL
|
||||
row = table.addRow ();
|
||||
table.addCell (row, 1, "task shell");
|
||||
|
@ -113,10 +117,6 @@ std::string shortUsage ()
|
|||
table.addCell (row, 1, "task delete ID");
|
||||
table.addCell (row, 2, "Deletes the specified task.");
|
||||
|
||||
row = table.addRow ();
|
||||
table.addCell (row, 1, "task undelete ID");
|
||||
table.addCell (row, 2, "Undeletes the specified task, provided a report has not yet been run.");
|
||||
|
||||
row = table.addRow ();
|
||||
table.addCell (row, 1, "task info ID");
|
||||
table.addCell (row, 2, "Shows all data, metadata for specified task.");
|
||||
|
@ -133,10 +133,6 @@ std::string shortUsage ()
|
|||
table.addCell (row, 1, "task done ID [tags] [attrs] [desc...]");
|
||||
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.");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue