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:
Paul Beckingham 2009-06-28 21:51:43 -04:00
parent dc2bac1b5e
commit af7803ea27
6 changed files with 14 additions and 112 deletions

View file

@ -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 (); }

View file

@ -488,6 +488,11 @@ int TDB::nextId ()
return mId++;
}
////////////////////////////////////////////////////////////////////////////////
void TDB::undo ()
{
}
////////////////////////////////////////////////////////////////////////////////
FILE* TDB::openAndLock (const std::string& file)
{

View 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&);

View file

@ -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 ();
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -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

View file

@ -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.");