From af7803ea27d7329c63fb8f52fe3fcdcf7a05eb03 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 28 Jun 2009 21:51:43 -0400 Subject: [PATCH] Enhancement - undo - Removed obsolete undelete command. - Removed obsolete undo command. - Implemented new undo command as a call to the stubbed TDB::undo call. --- src/Context.cpp | 3 +- src/TDB.cpp | 5 +++ src/TDB.h | 1 + src/command.cpp | 102 +----------------------------------------------- src/main.h | 3 +- src/report.cpp | 12 ++---- 6 files changed, 14 insertions(+), 112 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index 56db73fed..15fa89113 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -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 (); } diff --git a/src/TDB.cpp b/src/TDB.cpp index f9bd14a23..33f13302f 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -488,6 +488,11 @@ int TDB::nextId () return mId++; } +//////////////////////////////////////////////////////////////////////////////// +void TDB::undo () +{ +} + //////////////////////////////////////////////////////////////////////////////// FILE* TDB::openAndLock (const std::string& file) { diff --git a/src/TDB.h b/src/TDB.h index b2e159d9a..fbaad4321 100644 --- a/src/TDB.h +++ b/src/TDB.h @@ -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&); diff --git a/src/command.cpp b/src/command.cpp index 2256c7112..cbe7ae482 100644 --- a/src/command.cpp +++ b/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 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 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 (); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/main.h b/src/main.h index 3f6a566fc..9a39ee35b 100644 --- a/src/main.h +++ b/src/main.h @@ -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 diff --git a/src/report.cpp b/src/report.cpp index 624752a97..c86ac55d1 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -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.");