From aaa8c5e950e28934f3c14c5aa4d8225e7cfa204a Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 15 Oct 2011 23:07:35 -0400 Subject: [PATCH] Confirmation - Modified the 'modify' command so that it only applies changes if the requested changes made a difference. For example if the command task 1 mod pri:H was followed by: task 1 mod pri:H then the second command will report 'task not changed'. --- src/commands/CmdModify.cpp | 114 +++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 56 deletions(-) diff --git a/src/commands/CmdModify.cpp b/src/commands/CmdModify.cpp index 979bc9e22..edba6811b 100644 --- a/src/commands/CmdModify.cpp +++ b/src/commands/CmdModify.cpp @@ -72,70 +72,72 @@ int CmdModify::execute (std::string& output) { Task before (*task); modify_task_description_replace (*task, modifications); - - // Perform some logical consistency checks. - if (task->has ("recur") && - !task->has ("due") && - !before.has ("due")) - throw std::string (STRING_CMD_MODIFY_NO_DUE); - - if (task->has ("until") && - !task->has ("recur") && - !before.has ("recur")) - throw std::string (STRING_CMD_MODIFY_UNTIL); - - if (before.has ("recur") && - before.has ("due") && - (!task->has ("due") || - task->get ("due") == "")) - throw std::string (STRING_CMD_MODIFY_REM_DUE); - - if (before.has ("recur") && - task->has ("recur") && - (!task->has ("recur") || - task->get ("recur") == "")) - throw std::string (STRING_CMD_MODIFY_REC_ALWAYS); - - // Delete the specified task. - std::string question = format (STRING_CMD_MODIFY_CONFIRM, - task->id, - task->get ("description")); - - if (permission (*task, taskDifferences (before, *task) + question, filtered.size ())) + if (taskDiff (before, *task)) { - updateRecurrenceMask (*task); - context.tdb2.modify (*task); - ++count; - feedback_affected (STRING_CMD_MODIFY_TASK, *task); - dependencyChainOnModify (before, *task); - context.footnote (onProjectChange (*task, true)); + // Perform some logical consistency checks. + if (task->has ("recur") && + !task->has ("due") && + !before.has ("due")) + throw std::string (STRING_CMD_MODIFY_NO_DUE); - // Delete siblings. - if (task->has ("parent")) + if (task->has ("until") && + !task->has ("recur") && + !before.has ("recur")) + throw std::string (STRING_CMD_MODIFY_UNTIL); + + if (before.has ("recur") && + before.has ("due") && + (!task->has ("due") || + task->get ("due") == "")) + throw std::string (STRING_CMD_MODIFY_REM_DUE); + + if (before.has ("recur") && + task->has ("recur") && + (!task->has ("recur") || + task->get ("recur") == "")) + throw std::string (STRING_CMD_MODIFY_REC_ALWAYS); + + // Delete the specified task. + std::string question = format (STRING_CMD_MODIFY_CONFIRM, + task->id, + task->get ("description")); + + if (permission (*task, taskDifferences (before, *task) + question, filtered.size ())) { - std::vector siblings = context.tdb2.siblings (*task); - if (siblings.size () && - confirm (STRING_CMD_MODIFY_RECUR)) + updateRecurrenceMask (*task); + context.tdb2.modify (*task); + ++count; + feedback_affected (STRING_CMD_MODIFY_TASK, *task); + dependencyChainOnModify (before, *task); + context.footnote (onProjectChange (*task, true)); + + // Delete siblings. + if (task->has ("parent")) { - std::vector ::iterator sibling; - for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling) + std::vector siblings = context.tdb2.siblings (*task); + if (siblings.size () && + confirm (STRING_CMD_MODIFY_RECUR)) { - Task alternate (*sibling); - modify_task_description_replace (*sibling, modifications); - updateRecurrenceMask (*sibling); - context.tdb2.modify (*sibling); - dependencyChainOnModify (alternate, *sibling); - context.footnote (onProjectChange (*sibling, true)); - ++count; - feedback_affected (STRING_CMD_MODIFY_TASK_R, *sibling); + std::vector ::iterator sibling; + for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling) + { + Task alternate (*sibling); + modify_task_description_replace (*sibling, modifications); + updateRecurrenceMask (*sibling); + context.tdb2.modify (*sibling); + dependencyChainOnModify (alternate, *sibling); + context.footnote (onProjectChange (*sibling, true)); + ++count; + feedback_affected (STRING_CMD_MODIFY_TASK_R, *sibling); + } } } } - } - else - { - std::cout << STRING_CMD_MODIFY_NO << "\n"; - rc = 1; + else + { + std::cout << STRING_CMD_MODIFY_NO << "\n"; + rc = 1; + } } }