///////////////////////////////////////////////////////////////////////////
| 54 | |
| 55 | //////////////////////////////////////////////////////////////////////////////// |
| 56 | int CmdAnnotate::execute(std::string&) { |
| 57 | int rc = 0; |
| 58 | int count = 0; |
| 59 | |
| 60 | // Apply filter. |
| 61 | Filter filter; |
| 62 | std::vector<Task> filtered; |
| 63 | filter.subset(filtered); |
| 64 | if (filtered.size() == 0) { |
| 65 | Context::getContext().footnote("No tasks specified."); |
| 66 | return 1; |
| 67 | } |
| 68 | |
| 69 | // TODO Complain when no modifications are specified. |
| 70 | |
| 71 | // Accumulated project change notifications. |
| 72 | std::map<std::string, std::string> projectChanges; |
| 73 | |
| 74 | if (filtered.size() > 1) { |
| 75 | feedback_affected("This command will alter {1} tasks.", filtered.size()); |
| 76 | } |
| 77 | for (auto& task : filtered) { |
| 78 | Task before(task); |
| 79 | |
| 80 | // Annotate the specified task. |
| 81 | std::string question = |
| 82 | format("Annotate task {1} '{2}'?", task.identifier(true), task.get("description")); |
| 83 | |
| 84 | task.modify(Task::modAnnotate, true); |
| 85 | |
| 86 | if (permission(before.diff(task) + question, filtered.size())) { |
| 87 | Context::getContext().tdb2.modify(task); |
| 88 | ++count; |
| 89 | feedback_affected("Annotating task {1} '{2}'.", task); |
| 90 | if (Context::getContext().verbose("project")) |
| 91 | projectChanges[task.get("project")] = onProjectChange(task, false); |
| 92 | |
| 93 | // Annotate siblings. |
| 94 | if (task.has("parent")) { |
| 95 | if ((Context::getContext().config.get("recurrence.confirmation") == "prompt" && |
| 96 | confirm("This is a recurring task. Do you want to annotate all pending recurrences " |
| 97 | "of this same task?")) || |
| 98 | Context::getContext().config.getBoolean("recurrence.confirmation")) { |
| 99 | auto siblings = Context::getContext().tdb2.siblings(task); |
| 100 | for (auto& sibling : siblings) { |
| 101 | sibling.modify(Task::modAnnotate, true); |
| 102 | Context::getContext().tdb2.modify(sibling); |
| 103 | ++count; |
| 104 | feedback_affected("Annotating recurring task {1} '{2}'.", sibling); |
| 105 | } |
| 106 | |
| 107 | // Annotate the parent |
| 108 | Task parent; |
| 109 | Context::getContext().tdb2.get(task.get("parent"), parent); |
| 110 | parent.modify(Task::modAnnotate, true); |
| 111 | Context::getContext().tdb2.modify(parent); |
| 112 | } |
| 113 | } |
nothing calls this directly
no test coverage detected