move use of contextTask out of columns, into commands

This commit is contained in:
Dustin J. Mitchell
2021-12-18 01:49:48 +00:00
committed by Tomas Babej
parent e98b61f2b5
commit 6e9ad1048d
17 changed files with 44 additions and 35 deletions

View File

@@ -36,8 +36,6 @@
#include <utf8.h> #include <utf8.h>
#include <util.h> #include <util.h>
extern Task* contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ColumnProject::ColumnProject () ColumnProject::ColumnProject ()
{ {
@@ -121,9 +119,6 @@ void ColumnProject::modify (Task& task, const std::string& value)
{ {
Eval e; Eval e;
e.addSource (domSource); e.addSource (domSource);
if (!task.is_empty ()) {
contextTask = &task;
}
Variant v; Variant v;
e.evaluateInfixExpression (value, v); e.evaluateInfixExpression (value, v);

View File

@@ -36,8 +36,6 @@
#include <format.h> #include <format.h>
#include <utf8.h> #include <utf8.h>
extern Task* contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ColumnRecur::ColumnRecur () ColumnRecur::ColumnRecur ()
{ {
@@ -108,9 +106,6 @@ void ColumnRecur::modify (Task& task, const std::string& value)
{ {
Eval e; Eval e;
e.addSource (domSource); e.addSource (domSource);
if (!task.is_empty ()) {
contextTask = &task;
}
e.evaluateInfixExpression (value, evaluatedValue); e.evaluateInfixExpression (value, evaluatedValue);
} }

View File

@@ -36,8 +36,6 @@
#include <utf8.h> #include <utf8.h>
#include <main.h> #include <main.h>
extern Task* contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ColumnTags::ColumnTags () ColumnTags::ColumnTags ()
{ {
@@ -162,9 +160,6 @@ void ColumnTags::modify (Task& task, const std::string& value)
{ {
Eval e; Eval e;
e.addSource (domSource); e.addSource (domSource);
if (!task.is_empty ()) {
contextTask = &task;
}
Variant v; Variant v;
e.evaluateInfixExpression (value, v); e.evaluateInfixExpression (value, v);

View File

@@ -34,8 +34,6 @@
#include <Filter.h> #include <Filter.h>
#include <format.h> #include <format.h>
extern Task* contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ColumnTypeDate::ColumnTypeDate () ColumnTypeDate::ColumnTypeDate ()
{ {
@@ -213,9 +211,6 @@ void ColumnTypeDate::modify (Task& task, const std::string& value)
{ {
Eval e; Eval e;
e.addSource (domSource); e.addSource (domSource);
if (!task.is_empty ()) {
contextTask = &task;
}
e.evaluateInfixExpression (value, evaluatedValue); e.evaluateInfixExpression (value, evaluatedValue);
} }

View File

@@ -32,8 +32,6 @@
#include <Filter.h> #include <Filter.h>
#include <format.h> #include <format.h>
extern Task* contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ColumnTypeDuration::ColumnTypeDuration () ColumnTypeDuration::ColumnTypeDuration ()
{ {
@@ -55,9 +53,6 @@ void ColumnTypeDuration::modify (Task& task, const std::string& value)
{ {
Eval e; Eval e;
e.addSource (domSource); e.addSource (domSource);
if (!task.is_empty ()) {
contextTask = &task;
}
e.evaluateInfixExpression (value, evaluatedValue); e.evaluateInfixExpression (value, evaluatedValue);
} }

View File

@@ -32,8 +32,6 @@
#include <Filter.h> #include <Filter.h>
#include <format.h> #include <format.h>
extern Task* contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ColumnTypeNumeric::ColumnTypeNumeric () ColumnTypeNumeric::ColumnTypeNumeric ()
{ {
@@ -55,9 +53,6 @@ void ColumnTypeNumeric::modify (Task& task, const std::string& value)
{ {
Eval e; Eval e;
e.addSource (domSource); e.addSource (domSource);
if (!task.is_empty ()) {
contextTask = &task;
}
e.evaluateInfixExpression (value, evaluatedValue); e.evaluateInfixExpression (value, evaluatedValue);
} }

View File

@@ -34,8 +34,6 @@
#define STRING_INVALID_MOD "The '{1}' attribute does not allow a value of '{2}'." #define STRING_INVALID_MOD "The '{1}' attribute does not allow a value of '{2}'."
extern Task* contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ColumnTypeString::ColumnTypeString () ColumnTypeString::ColumnTypeString ()
{ {
@@ -67,9 +65,6 @@ void ColumnTypeString::modify (Task& task, const std::string& value)
{ {
Eval e; Eval e;
e.addSource (domSource); e.addSource (domSource);
if (!task.is_empty ()) {
contextTask = &task;
}
Variant v; Variant v;
e.evaluateInfixExpression (value, v); e.evaluateInfixExpression (value, v);

View File

@@ -30,6 +30,8 @@
#include <format.h> #include <format.h>
#include <main.h> #include <main.h>
extern Task* contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdAdd::CmdAdd () CmdAdd::CmdAdd ()
{ {
@@ -51,6 +53,10 @@ int CmdAdd::execute (std::string& output)
{ {
// Apply the command line modifications to the new task. // Apply the command line modifications to the new task.
Task 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); task.modify (Task::modReplace, true);
Context::getContext ().tdb2.add (task); Context::getContext ().tdb2.add (task);

View File

@@ -33,6 +33,8 @@
#include <shared.h> #include <shared.h>
#include <format.h> #include <format.h>
extern Task* contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdAnnotate::CmdAnnotate () CmdAnnotate::CmdAnnotate ()
{ {
@@ -82,6 +84,7 @@ int CmdAnnotate::execute (std::string&)
task.identifier (true), task.identifier (true),
task.get ("description")); task.get ("description"));
contextTask = &task;
task.modify (Task::modAnnotate, true); task.modify (Task::modAnnotate, true);
if (permission (before.diff (task) + question, filtered.size ())) if (permission (before.diff (task) + question, filtered.size ()))
@@ -102,6 +105,7 @@ int CmdAnnotate::execute (std::string&)
auto siblings = Context::getContext ().tdb2.siblings (task); auto siblings = Context::getContext ().tdb2.siblings (task);
for (auto& sibling : siblings) for (auto& sibling : siblings)
{ {
contextTask = &sibling;
sibling.modify (Task::modAnnotate, true); sibling.modify (Task::modAnnotate, true);
Context::getContext ().tdb2.modify (sibling); Context::getContext ().tdb2.modify (sibling);
++count; ++count;
@@ -111,6 +115,7 @@ int CmdAnnotate::execute (std::string&)
// Annotate the parent // Annotate the parent
Task parent; Task parent;
Context::getContext ().tdb2.get (task.get ("parent"), parent); Context::getContext ().tdb2.get (task.get ("parent"), parent);
contextTask = &parent;
parent.modify (Task::modAnnotate, true); parent.modify (Task::modAnnotate, true);
Context::getContext ().tdb2.modify (parent); Context::getContext ().tdb2.modify (parent);
} }

View File

@@ -33,6 +33,8 @@
#include <format.h> #include <format.h>
#include <main.h> #include <main.h>
extern Task* contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdAppend::CmdAppend () CmdAppend::CmdAppend ()
{ {
@@ -82,6 +84,7 @@ int CmdAppend::execute (std::string&)
task.identifier (true), task.identifier (true),
task.get ("description")); task.get ("description"));
contextTask = &task;
task.modify (Task::modAppend, true); task.modify (Task::modAppend, true);
if (permission (before.diff (task) + question, filtered.size ())) if (permission (before.diff (task) + question, filtered.size ()))
@@ -102,6 +105,7 @@ int CmdAppend::execute (std::string&)
std::vector <Task> siblings = Context::getContext ().tdb2.siblings (task); std::vector <Task> siblings = Context::getContext ().tdb2.siblings (task);
for (auto& sibling : siblings) for (auto& sibling : siblings)
{ {
contextTask = &sibling;
sibling.modify (Task::modAppend, true); sibling.modify (Task::modAppend, true);
Context::getContext ().tdb2.modify (sibling); Context::getContext ().tdb2.modify (sibling);
++count; ++count;
@@ -111,6 +115,7 @@ int CmdAppend::execute (std::string&)
// Append to the parent // Append to the parent
Task parent; Task parent;
Context::getContext ().tdb2.get (task.get ("parent"), parent); Context::getContext ().tdb2.get (task.get ("parent"), parent);
contextTask = &parent;
parent.modify (Task::modAppend, true); parent.modify (Task::modAppend, true);
Context::getContext ().tdb2.modify (parent); Context::getContext ().tdb2.modify (parent);
} }

View File

@@ -36,6 +36,8 @@
#define STRING_CMD_DELETE_TASK_R "Deleting recurring task {1} '{2}'." #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?" #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 () CmdDelete::CmdDelete ()
{ {
@@ -87,6 +89,7 @@ int CmdDelete::execute (std::string&)
task.identifier (true), task.identifier (true),
task.get ("description")); task.get ("description"));
contextTask = &task;
task.modify (Task::modAnnotate); task.modify (Task::modAnnotate);
task.setStatus (Task::deleted); task.setStatus (Task::deleted);
if (! task.has ("end")) if (! task.has ("end"))
@@ -113,6 +116,7 @@ int CmdDelete::execute (std::string&)
std::vector <Task> siblings = Context::getContext ().tdb2.siblings (task); std::vector <Task> siblings = Context::getContext ().tdb2.siblings (task);
for (auto& sibling : siblings) for (auto& sibling : siblings)
{ {
contextTask = &sibling;
sibling.modify (Task::modAnnotate); sibling.modify (Task::modAnnotate);
sibling.setStatus (Task::deleted); sibling.setStatus (Task::deleted);
if (! sibling.has ("end")) if (! sibling.has ("end"))
@@ -147,6 +151,7 @@ int CmdDelete::execute (std::string&)
{ {
for (auto& child : children) for (auto& child : children)
{ {
contextTask = &child;
child.modify (Task::modAnnotate); child.modify (Task::modAnnotate);
child.setStatus (Task::deleted); child.setStatus (Task::deleted);
if (! child.has ("end")) if (! child.has ("end"))

View File

@@ -33,6 +33,8 @@
#include <format.h> #include <format.h>
#include <main.h> #include <main.h>
extern Task* contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdDone::CmdDone () CmdDone::CmdDone ()
{ {
@@ -85,6 +87,7 @@ int CmdDone::execute (std::string&)
task.identifier (true), task.identifier (true),
task.get ("description")); task.get ("description"));
contextTask = &task;
task.modify (Task::modAnnotate); task.modify (Task::modAnnotate);
task.setStatus (Task::completed); task.setStatus (Task::completed);
if (! task.has ("end")) if (! task.has ("end"))

View File

@@ -33,6 +33,8 @@
#include <util.h> #include <util.h>
#include <main.h> #include <main.h>
extern Task* contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdDuplicate::CmdDuplicate () CmdDuplicate::CmdDuplicate ()
{ {
@@ -100,6 +102,7 @@ int CmdDuplicate::execute (std::string&)
dup.setStatus (Task::pending); // Does not inherit status. dup.setStatus (Task::pending); // Does not inherit status.
// Must occur after Task::recurring check. // Must occur after Task::recurring check.
contextTask = &dup;
dup.modify (Task::modAnnotate); dup.modify (Task::modAnnotate);
if (permission (format ("Duplicate task {1} '{2}'?", if (permission (format ("Duplicate task {1} '{2}'?",

View File

@@ -36,6 +36,8 @@
#define STRING_CMD_MODIFY_TASK_R "Modifying recurring task {1} '{2}'." #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?" #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 () CmdModify::CmdModify ()
{ {
@@ -77,6 +79,7 @@ int CmdModify::execute (std::string&)
for (auto& task : filtered) for (auto& task : filtered)
{ {
Task before (task); Task before (task);
contextTask = &task;
task.modify (Task::modReplace); task.modify (Task::modReplace);
if (before != task) if (before != task)
@@ -174,6 +177,7 @@ int CmdModify::modifyRecurrenceSiblings (
for (auto& sibling : siblings) for (auto& sibling : siblings)
{ {
Task alternate (sibling); Task alternate (sibling);
contextTask = &sibling;
sibling.modify (Task::modReplace); sibling.modify (Task::modReplace);
updateRecurrenceMask (sibling); updateRecurrenceMask (sibling);
++count; ++count;
@@ -187,6 +191,7 @@ int CmdModify::modifyRecurrenceSiblings (
// Modify the parent // Modify the parent
Task parent; Task parent;
Context::getContext ().tdb2.get (task.get ("parent"), parent); Context::getContext ().tdb2.get (task.get ("parent"), parent);
contextTask = &parent;
parent.modify (Task::modReplace); parent.modify (Task::modReplace);
Context::getContext ().tdb2.modify (parent); Context::getContext ().tdb2.modify (parent);
} }
@@ -210,6 +215,7 @@ int CmdModify::modifyRecurrenceParent (
for (auto& child : children) for (auto& child : children)
{ {
Task alternate (child); Task alternate (child);
contextTask = &child;
child.modify (Task::modReplace); child.modify (Task::modReplace);
updateRecurrenceMask (child); updateRecurrenceMask (child);
Context::getContext ().tdb2.modify (child); Context::getContext ().tdb2.modify (child);

View File

@@ -33,6 +33,8 @@
#include <format.h> #include <format.h>
#include <main.h> #include <main.h>
extern Task* contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdPrepend::CmdPrepend () CmdPrepend::CmdPrepend ()
{ {
@@ -82,6 +84,7 @@ int CmdPrepend::execute (std::string&)
task.identifier (true), task.identifier (true),
task.get ("description")); task.get ("description"));
contextTask = &task;
task.modify (Task::modPrepend, true); task.modify (Task::modPrepend, true);
if (permission (before.diff (task) + question, filtered.size ())) if (permission (before.diff (task) + question, filtered.size ()))
@@ -102,6 +105,7 @@ int CmdPrepend::execute (std::string&)
std::vector <Task> siblings = Context::getContext ().tdb2.siblings (task); std::vector <Task> siblings = Context::getContext ().tdb2.siblings (task);
for (auto& sibling : siblings) for (auto& sibling : siblings)
{ {
contextTask = &sibling;
sibling.modify (Task::modPrepend, true); sibling.modify (Task::modPrepend, true);
Context::getContext ().tdb2.modify (sibling); Context::getContext ().tdb2.modify (sibling);
++count; ++count;
@@ -111,6 +115,7 @@ int CmdPrepend::execute (std::string&)
// Prepend to the parent // Prepend to the parent
Task parent; Task parent;
Context::getContext ().tdb2.get (task.get ("parent"), parent); Context::getContext ().tdb2.get (task.get ("parent"), parent);
contextTask = &parent;
parent.modify (Task::modPrepend, true); parent.modify (Task::modPrepend, true);
Context::getContext ().tdb2.modify (parent); Context::getContext ().tdb2.modify (parent);
} }

View File

@@ -33,6 +33,8 @@
#include <format.h> #include <format.h>
#include <util.h> #include <util.h>
extern Task* contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdStart::CmdStart () CmdStart::CmdStart ()
{ {
@@ -83,6 +85,7 @@ int CmdStart::execute (std::string&)
std::string question = format ("Start task {1} '{2}'?", std::string question = format ("Start task {1} '{2}'?",
task.identifier (true), task.identifier (true),
task.get ("description")); task.get ("description"));
contextTask = &task;
task.modify (Task::modAnnotate); task.modify (Task::modAnnotate);
task.setAsNow ("start"); task.setAsNow ("start");

View File

@@ -32,6 +32,8 @@
#include <main.h> #include <main.h>
#include <format.h> #include <format.h>
extern Task* contextTask;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdStop::CmdStop () CmdStop::CmdStop ()
{ {
@@ -81,6 +83,7 @@ int CmdStop::execute (std::string&)
task.identifier (true), task.identifier (true),
task.get ("description")); task.get ("description"));
contextTask = &task;
task.modify (Task::modAnnotate); task.modify (Task::modAnnotate);
task.remove ("start"); task.remove ("start");