diff --git a/src/columns/ColProject.cpp b/src/columns/ColProject.cpp index bef8ec723..a5890f1bb 100644 --- a/src/columns/ColProject.cpp +++ b/src/columns/ColProject.cpp @@ -36,8 +36,6 @@ #include #include -extern Task* contextTask; - //////////////////////////////////////////////////////////////////////////////// ColumnProject::ColumnProject () { @@ -121,9 +119,6 @@ void ColumnProject::modify (Task& task, const std::string& value) { Eval e; e.addSource (domSource); - if (!task.is_empty ()) { - contextTask = &task; - } Variant v; e.evaluateInfixExpression (value, v); diff --git a/src/columns/ColRecur.cpp b/src/columns/ColRecur.cpp index 8168770ed..844dcb5a5 100644 --- a/src/columns/ColRecur.cpp +++ b/src/columns/ColRecur.cpp @@ -36,8 +36,6 @@ #include #include -extern Task* contextTask; - //////////////////////////////////////////////////////////////////////////////// ColumnRecur::ColumnRecur () { @@ -108,9 +106,6 @@ void ColumnRecur::modify (Task& task, const std::string& value) { Eval e; e.addSource (domSource); - if (!task.is_empty ()) { - contextTask = &task; - } e.evaluateInfixExpression (value, evaluatedValue); } diff --git a/src/columns/ColTags.cpp b/src/columns/ColTags.cpp index 4680f4fed..e5d30ab57 100644 --- a/src/columns/ColTags.cpp +++ b/src/columns/ColTags.cpp @@ -36,8 +36,6 @@ #include #include -extern Task* contextTask; - //////////////////////////////////////////////////////////////////////////////// ColumnTags::ColumnTags () { @@ -162,9 +160,6 @@ void ColumnTags::modify (Task& task, const std::string& value) { Eval e; e.addSource (domSource); - if (!task.is_empty ()) { - contextTask = &task; - } Variant v; e.evaluateInfixExpression (value, v); diff --git a/src/columns/ColTypeDate.cpp b/src/columns/ColTypeDate.cpp index fc63f4c66..2fb283ef3 100644 --- a/src/columns/ColTypeDate.cpp +++ b/src/columns/ColTypeDate.cpp @@ -34,8 +34,6 @@ #include #include -extern Task* contextTask; - //////////////////////////////////////////////////////////////////////////////// ColumnTypeDate::ColumnTypeDate () { @@ -213,9 +211,6 @@ void ColumnTypeDate::modify (Task& task, const std::string& value) { Eval e; e.addSource (domSource); - if (!task.is_empty ()) { - contextTask = &task; - } e.evaluateInfixExpression (value, evaluatedValue); } diff --git a/src/columns/ColTypeDuration.cpp b/src/columns/ColTypeDuration.cpp index f305686e5..942d69b16 100644 --- a/src/columns/ColTypeDuration.cpp +++ b/src/columns/ColTypeDuration.cpp @@ -32,8 +32,6 @@ #include #include -extern Task* contextTask; - //////////////////////////////////////////////////////////////////////////////// ColumnTypeDuration::ColumnTypeDuration () { @@ -55,9 +53,6 @@ void ColumnTypeDuration::modify (Task& task, const std::string& value) { Eval e; e.addSource (domSource); - if (!task.is_empty ()) { - contextTask = &task; - } e.evaluateInfixExpression (value, evaluatedValue); } diff --git a/src/columns/ColTypeNumeric.cpp b/src/columns/ColTypeNumeric.cpp index ea04891e7..737e991e8 100644 --- a/src/columns/ColTypeNumeric.cpp +++ b/src/columns/ColTypeNumeric.cpp @@ -32,8 +32,6 @@ #include #include -extern Task* contextTask; - //////////////////////////////////////////////////////////////////////////////// ColumnTypeNumeric::ColumnTypeNumeric () { @@ -55,9 +53,6 @@ void ColumnTypeNumeric::modify (Task& task, const std::string& value) { Eval e; e.addSource (domSource); - if (!task.is_empty ()) { - contextTask = &task; - } e.evaluateInfixExpression (value, evaluatedValue); } diff --git a/src/columns/ColTypeString.cpp b/src/columns/ColTypeString.cpp index 8f46abb1f..2d93ca9fc 100644 --- a/src/columns/ColTypeString.cpp +++ b/src/columns/ColTypeString.cpp @@ -34,8 +34,6 @@ #define STRING_INVALID_MOD "The '{1}' attribute does not allow a value of '{2}'." -extern Task* contextTask; - //////////////////////////////////////////////////////////////////////////////// ColumnTypeString::ColumnTypeString () { @@ -67,9 +65,6 @@ void ColumnTypeString::modify (Task& task, const std::string& value) { Eval e; e.addSource (domSource); - if (!task.is_empty ()) { - contextTask = &task; - } Variant v; e.evaluateInfixExpression (value, v); diff --git a/src/commands/CmdAdd.cpp b/src/commands/CmdAdd.cpp index 08f1e34ba..dd3ba23b4 100644 --- a/src/commands/CmdAdd.cpp +++ b/src/commands/CmdAdd.cpp @@ -30,6 +30,8 @@ #include #include +extern Task* contextTask; + //////////////////////////////////////////////////////////////////////////////// CmdAdd::CmdAdd () { @@ -51,6 +53,10 @@ int CmdAdd::execute (std::string& output) { // Apply the command line modifications to the new task. Task task; + + // the task is empty, but DOM references can refer to earlier parts of the + // command line, e.g., `task add due:20110101 wait:due`. + contextTask = &task; task.modify (Task::modReplace, true); Context::getContext ().tdb2.add (task); diff --git a/src/commands/CmdAnnotate.cpp b/src/commands/CmdAnnotate.cpp index 4a3a17a83..9812874a2 100644 --- a/src/commands/CmdAnnotate.cpp +++ b/src/commands/CmdAnnotate.cpp @@ -33,6 +33,8 @@ #include #include +extern Task* contextTask; + //////////////////////////////////////////////////////////////////////////////// CmdAnnotate::CmdAnnotate () { @@ -82,6 +84,7 @@ int CmdAnnotate::execute (std::string&) task.identifier (true), task.get ("description")); + contextTask = &task; task.modify (Task::modAnnotate, true); if (permission (before.diff (task) + question, filtered.size ())) @@ -102,6 +105,7 @@ int CmdAnnotate::execute (std::string&) auto siblings = Context::getContext ().tdb2.siblings (task); for (auto& sibling : siblings) { + contextTask = &sibling; sibling.modify (Task::modAnnotate, true); Context::getContext ().tdb2.modify (sibling); ++count; @@ -111,6 +115,7 @@ int CmdAnnotate::execute (std::string&) // Annotate the parent Task parent; Context::getContext ().tdb2.get (task.get ("parent"), parent); + contextTask = &parent; parent.modify (Task::modAnnotate, true); Context::getContext ().tdb2.modify (parent); } diff --git a/src/commands/CmdAppend.cpp b/src/commands/CmdAppend.cpp index 1ce75447b..39906e789 100644 --- a/src/commands/CmdAppend.cpp +++ b/src/commands/CmdAppend.cpp @@ -33,6 +33,8 @@ #include #include +extern Task* contextTask; + //////////////////////////////////////////////////////////////////////////////// CmdAppend::CmdAppend () { @@ -82,6 +84,7 @@ int CmdAppend::execute (std::string&) task.identifier (true), task.get ("description")); + contextTask = &task; task.modify (Task::modAppend, true); if (permission (before.diff (task) + question, filtered.size ())) @@ -102,6 +105,7 @@ int CmdAppend::execute (std::string&) std::vector siblings = Context::getContext ().tdb2.siblings (task); for (auto& sibling : siblings) { + contextTask = &sibling; sibling.modify (Task::modAppend, true); Context::getContext ().tdb2.modify (sibling); ++count; @@ -111,6 +115,7 @@ int CmdAppend::execute (std::string&) // Append to the parent Task parent; Context::getContext ().tdb2.get (task.get ("parent"), parent); + contextTask = &parent; parent.modify (Task::modAppend, true); Context::getContext ().tdb2.modify (parent); } diff --git a/src/commands/CmdDelete.cpp b/src/commands/CmdDelete.cpp index 8bedab285..4e4f78c29 100644 --- a/src/commands/CmdDelete.cpp +++ b/src/commands/CmdDelete.cpp @@ -36,6 +36,8 @@ #define STRING_CMD_DELETE_TASK_R "Deleting recurring task {1} '{2}'." #define STRING_CMD_DELETE_CONFIRM_R "This is a recurring task. Do you want to delete all pending recurrences of this same task?" +extern Task* contextTask; + //////////////////////////////////////////////////////////////////////////////// CmdDelete::CmdDelete () { @@ -87,6 +89,7 @@ int CmdDelete::execute (std::string&) task.identifier (true), task.get ("description")); + contextTask = &task; task.modify (Task::modAnnotate); task.setStatus (Task::deleted); if (! task.has ("end")) @@ -113,6 +116,7 @@ int CmdDelete::execute (std::string&) std::vector siblings = Context::getContext ().tdb2.siblings (task); for (auto& sibling : siblings) { + contextTask = &sibling; sibling.modify (Task::modAnnotate); sibling.setStatus (Task::deleted); if (! sibling.has ("end")) @@ -147,6 +151,7 @@ int CmdDelete::execute (std::string&) { for (auto& child : children) { + contextTask = &child; child.modify (Task::modAnnotate); child.setStatus (Task::deleted); if (! child.has ("end")) diff --git a/src/commands/CmdDone.cpp b/src/commands/CmdDone.cpp index f579364ac..dd2e64333 100644 --- a/src/commands/CmdDone.cpp +++ b/src/commands/CmdDone.cpp @@ -33,6 +33,8 @@ #include #include +extern Task* contextTask; + //////////////////////////////////////////////////////////////////////////////// CmdDone::CmdDone () { @@ -85,6 +87,7 @@ int CmdDone::execute (std::string&) task.identifier (true), task.get ("description")); + contextTask = &task; task.modify (Task::modAnnotate); task.setStatus (Task::completed); if (! task.has ("end")) diff --git a/src/commands/CmdDuplicate.cpp b/src/commands/CmdDuplicate.cpp index 46f1070e3..8ed3aa5d5 100644 --- a/src/commands/CmdDuplicate.cpp +++ b/src/commands/CmdDuplicate.cpp @@ -33,6 +33,8 @@ #include #include +extern Task* contextTask; + //////////////////////////////////////////////////////////////////////////////// CmdDuplicate::CmdDuplicate () { @@ -100,6 +102,7 @@ int CmdDuplicate::execute (std::string&) dup.setStatus (Task::pending); // Does not inherit status. // Must occur after Task::recurring check. + contextTask = &dup; dup.modify (Task::modAnnotate); if (permission (format ("Duplicate task {1} '{2}'?", diff --git a/src/commands/CmdModify.cpp b/src/commands/CmdModify.cpp index cb407367d..236b45fa8 100644 --- a/src/commands/CmdModify.cpp +++ b/src/commands/CmdModify.cpp @@ -36,6 +36,8 @@ #define STRING_CMD_MODIFY_TASK_R "Modifying recurring task {1} '{2}'." #define STRING_CMD_MODIFY_RECUR "This is a recurring task. Do you want to modify all pending recurrences of this same task?" +extern Task* contextTask; + //////////////////////////////////////////////////////////////////////////////// CmdModify::CmdModify () { @@ -77,6 +79,7 @@ int CmdModify::execute (std::string&) for (auto& task : filtered) { Task before (task); + contextTask = &task; task.modify (Task::modReplace); if (before != task) @@ -174,6 +177,7 @@ int CmdModify::modifyRecurrenceSiblings ( for (auto& sibling : siblings) { Task alternate (sibling); + contextTask = &sibling; sibling.modify (Task::modReplace); updateRecurrenceMask (sibling); ++count; @@ -187,6 +191,7 @@ int CmdModify::modifyRecurrenceSiblings ( // Modify the parent Task parent; Context::getContext ().tdb2.get (task.get ("parent"), parent); + contextTask = &parent; parent.modify (Task::modReplace); Context::getContext ().tdb2.modify (parent); } @@ -210,6 +215,7 @@ int CmdModify::modifyRecurrenceParent ( for (auto& child : children) { Task alternate (child); + contextTask = &child; child.modify (Task::modReplace); updateRecurrenceMask (child); Context::getContext ().tdb2.modify (child); diff --git a/src/commands/CmdPrepend.cpp b/src/commands/CmdPrepend.cpp index 0e59d5a30..847fef5d7 100644 --- a/src/commands/CmdPrepend.cpp +++ b/src/commands/CmdPrepend.cpp @@ -33,6 +33,8 @@ #include #include +extern Task* contextTask; + //////////////////////////////////////////////////////////////////////////////// CmdPrepend::CmdPrepend () { @@ -82,6 +84,7 @@ int CmdPrepend::execute (std::string&) task.identifier (true), task.get ("description")); + contextTask = &task; task.modify (Task::modPrepend, true); if (permission (before.diff (task) + question, filtered.size ())) @@ -102,6 +105,7 @@ int CmdPrepend::execute (std::string&) std::vector siblings = Context::getContext ().tdb2.siblings (task); for (auto& sibling : siblings) { + contextTask = &sibling; sibling.modify (Task::modPrepend, true); Context::getContext ().tdb2.modify (sibling); ++count; @@ -111,6 +115,7 @@ int CmdPrepend::execute (std::string&) // Prepend to the parent Task parent; Context::getContext ().tdb2.get (task.get ("parent"), parent); + contextTask = &parent; parent.modify (Task::modPrepend, true); Context::getContext ().tdb2.modify (parent); } diff --git a/src/commands/CmdStart.cpp b/src/commands/CmdStart.cpp index 6329c8129..b6636dc50 100644 --- a/src/commands/CmdStart.cpp +++ b/src/commands/CmdStart.cpp @@ -33,6 +33,8 @@ #include #include +extern Task* contextTask; + //////////////////////////////////////////////////////////////////////////////// CmdStart::CmdStart () { @@ -83,6 +85,7 @@ int CmdStart::execute (std::string&) std::string question = format ("Start task {1} '{2}'?", task.identifier (true), task.get ("description")); + contextTask = &task; task.modify (Task::modAnnotate); task.setAsNow ("start"); diff --git a/src/commands/CmdStop.cpp b/src/commands/CmdStop.cpp index f9d1cec6d..020757230 100644 --- a/src/commands/CmdStop.cpp +++ b/src/commands/CmdStop.cpp @@ -32,6 +32,8 @@ #include #include +extern Task* contextTask; + //////////////////////////////////////////////////////////////////////////////// CmdStop::CmdStop () { @@ -81,6 +83,7 @@ int CmdStop::execute (std::string&) task.identifier (true), task.get ("description")); + contextTask = &task; task.modify (Task::modAnnotate); task.remove ("start");