Just set contextTask in Task::modify

Based on the observation that every command was setting contextTask
immediately before calling `task.modify(..)`.
This commit is contained in:
Dustin J. Mitchell 2021-12-18 02:10:15 +00:00 committed by Tomas Babej
parent db26a28bf9
commit 2ea6dd627e
11 changed files with 5 additions and 42 deletions

View file

@ -60,7 +60,7 @@
#define APPROACHING_INFINITY 1000 // Close enough. This isn't rocket surgery.
extern Task& contextTask;
extern Task* contextTask;
static const float epsilon = 0.000001;
#endif
@ -2271,6 +2271,10 @@ void Task::modify (modType type, bool text_required /* = false */)
{
std::string label = " MODIFICATION ";
// while reading the parse tree, consider DOM references in the context of
// this task
contextTask = this;
// Need this for later comparison.
auto originalStatus = getStatus ();

View file

@ -30,8 +30,6 @@
#include <format.h>
#include <main.h>
extern Task* contextTask;
////////////////////////////////////////////////////////////////////////////////
CmdAdd::CmdAdd ()
{
@ -56,7 +54,6 @@ int CmdAdd::execute (std::string& output)
// 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);

View file

@ -33,8 +33,6 @@
#include <shared.h>
#include <format.h>
extern Task* contextTask;
////////////////////////////////////////////////////////////////////////////////
CmdAnnotate::CmdAnnotate ()
{
@ -84,7 +82,6 @@ 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 ()))
@ -105,7 +102,6 @@ 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;
@ -115,7 +111,6 @@ 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);
}

View file

@ -33,8 +33,6 @@
#include <format.h>
#include <main.h>
extern Task* contextTask;
////////////////////////////////////////////////////////////////////////////////
CmdAppend::CmdAppend ()
{
@ -84,7 +82,6 @@ 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 ()))
@ -105,7 +102,6 @@ int CmdAppend::execute (std::string&)
std::vector <Task> siblings = Context::getContext ().tdb2.siblings (task);
for (auto& sibling : siblings)
{
contextTask = &sibling;
sibling.modify (Task::modAppend, true);
Context::getContext ().tdb2.modify (sibling);
++count;
@ -115,7 +111,6 @@ 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);
}

View file

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

View file

@ -33,8 +33,6 @@
#include <format.h>
#include <main.h>
extern Task* contextTask;
////////////////////////////////////////////////////////////////////////////////
CmdDone::CmdDone ()
{
@ -87,7 +85,6 @@ 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"))

View file

@ -33,8 +33,6 @@
#include <util.h>
#include <main.h>
extern Task* contextTask;
////////////////////////////////////////////////////////////////////////////////
CmdDuplicate::CmdDuplicate ()
{
@ -102,7 +100,6 @@ 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}'?",

View file

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

View file

@ -33,8 +33,6 @@
#include <format.h>
#include <main.h>
extern Task* contextTask;
////////////////////////////////////////////////////////////////////////////////
CmdPrepend::CmdPrepend ()
{
@ -84,7 +82,6 @@ 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 ()))
@ -105,7 +102,6 @@ int CmdPrepend::execute (std::string&)
std::vector <Task> siblings = Context::getContext ().tdb2.siblings (task);
for (auto& sibling : siblings)
{
contextTask = &sibling;
sibling.modify (Task::modPrepend, true);
Context::getContext ().tdb2.modify (sibling);
++count;
@ -115,7 +111,6 @@ 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);
}

View file

@ -33,8 +33,6 @@
#include <format.h>
#include <util.h>
extern Task* contextTask;
////////////////////////////////////////////////////////////////////////////////
CmdStart::CmdStart ()
{
@ -85,7 +83,6 @@ 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");

View file

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