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'.
This commit is contained in:
Paul Beckingham
2011-10-15 23:07:35 -04:00
parent 3786e6cff3
commit aaa8c5e950

View File

@@ -72,70 +72,72 @@ int CmdModify::execute (std::string& output)
{ {
Task before (*task); Task before (*task);
modify_task_description_replace (*task, modifications); modify_task_description_replace (*task, modifications);
if (taskDiff (before, *task))
// 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 ()))
{ {
updateRecurrenceMask (*task); // Perform some logical consistency checks.
context.tdb2.modify (*task); if (task->has ("recur") &&
++count; !task->has ("due") &&
feedback_affected (STRING_CMD_MODIFY_TASK, *task); !before.has ("due"))
dependencyChainOnModify (before, *task); throw std::string (STRING_CMD_MODIFY_NO_DUE);
context.footnote (onProjectChange (*task, true));
// Delete siblings. if (task->has ("until") &&
if (task->has ("parent")) !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 <Task> siblings = context.tdb2.siblings (*task); updateRecurrenceMask (*task);
if (siblings.size () && context.tdb2.modify (*task);
confirm (STRING_CMD_MODIFY_RECUR)) ++count;
feedback_affected (STRING_CMD_MODIFY_TASK, *task);
dependencyChainOnModify (before, *task);
context.footnote (onProjectChange (*task, true));
// Delete siblings.
if (task->has ("parent"))
{ {
std::vector <Task>::iterator sibling; std::vector <Task> siblings = context.tdb2.siblings (*task);
for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling) if (siblings.size () &&
confirm (STRING_CMD_MODIFY_RECUR))
{ {
Task alternate (*sibling); std::vector <Task>::iterator sibling;
modify_task_description_replace (*sibling, modifications); for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling)
updateRecurrenceMask (*sibling); {
context.tdb2.modify (*sibling); Task alternate (*sibling);
dependencyChainOnModify (alternate, *sibling); modify_task_description_replace (*sibling, modifications);
context.footnote (onProjectChange (*sibling, true)); updateRecurrenceMask (*sibling);
++count; context.tdb2.modify (*sibling);
feedback_affected (STRING_CMD_MODIFY_TASK_R, *sibling); dependencyChainOnModify (alternate, *sibling);
context.footnote (onProjectChange (*sibling, true));
++count;
feedback_affected (STRING_CMD_MODIFY_TASK_R, *sibling);
}
} }
} }
} }
} else
else {
{ std::cout << STRING_CMD_MODIFY_NO << "\n";
std::cout << STRING_CMD_MODIFY_NO << "\n"; rc = 1;
rc = 1; }
} }
} }