From e238b94d1b536b9569dbd32da648c67babecdf58 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 12 Aug 2011 23:08:54 -0400 Subject: [PATCH] Urgency - Urgency recalc was not properly set with the task was modified. - Corrected urgency formatting. - Cleaned up some code in A3 and E9. --- src/A3.cpp | 1 - src/E9.cpp | 53 +++++++++++++++++++++++++--------------------------- src/Task.cpp | 36 ++++++++++++++++++++++++++++++----- src/text.cpp | 2 +- 4 files changed, 57 insertions(+), 35 deletions(-) diff --git a/src/A3.cpp b/src/A3.cpp index 14328d12b..b6e49d5a8 100644 --- a/src/A3.cpp +++ b/src/A3.cpp @@ -780,7 +780,6 @@ const A3 A3::tokenize (const A3& input) const } } - // TODO This may be redundant. else if (n.getNumber (d)) { output.push_back (Arg (format (d), "num")); diff --git a/src/E9.cpp b/src/E9.cpp index eb2be8cc7..685621b0f 100644 --- a/src/E9.cpp +++ b/src/E9.cpp @@ -299,10 +299,9 @@ void E9::operator_lt (Term& result, Term& left, Term& right) } else { - if (left._value < right._value) - result._raw = result._value = "true"; - else - result._raw = result._value = "false"; + result._raw = result._value = (left._value < right._value) + ? "true" + : "fasle"; } result._category = "bool"; @@ -323,10 +322,9 @@ void E9::operator_lte (Term& result, Term& left, Term& right) } else { - if (left._value <= right._value) - result._raw = result._value = "true"; - else - result._raw = result._value = "false"; + result._raw = result._value = (left._value <= right._value) + ? "true" + : "fasle"; } result._category = "bool"; @@ -347,10 +345,9 @@ void E9::operator_gte (Term& result, Term& left, Term& right) } else { - if (left._value >= right._value) - result._raw = result._value = "true"; - else - result._raw = result._value = "false"; + result._raw = result._value = (left._value >= right._value) + ? "true" + : "fasle"; } result._category = "bool"; @@ -370,10 +367,9 @@ void E9::operator_gt (Term& result, Term& left, Term& right) } else { - if (left._value > right._value) - result._raw = result._value = "true"; - else - result._raw = result._value = "false"; + result._raw = result._value = (left._value > right._value) + ? "true" + : "fasle"; } result._category = "bool"; @@ -389,10 +385,9 @@ void E9::operator_inequal ( bool case_sensitive) { operator_equal (result, left, right, case_sensitive); - if (result._raw == "false") - result._raw = result._value = "true"; - else - result._raw = result._value = "false"; + result._raw = result._value = result._raw == "false" + ? "true" + : "false"; // std::cout << "# " << left << " != " << right << " --> " << result << "\n"; } @@ -434,6 +429,10 @@ void E9::operator_equal ( // Regular equality matching. else { + result._raw = result._value = left._value == right._value + ? "true" + : "false"; + if (left._value == right._value) { result._raw = result._value = "true"; @@ -453,10 +452,9 @@ void E9::operator_match ( { result._category = "bool"; - if (eval_match (left, right, case_sensitive)) - result._raw = result._value = "true"; - else - result._raw = result._value = "false"; + result._raw = result._value = eval_match (left, right, case_sensitive) + ? "true" + : "false"; // std::cout << "# " << left << " ~ " << right << " --> " << result << "\n"; } @@ -480,10 +478,9 @@ void E9::operator_nomatch ( { result._category = "bool"; - if (!eval_match (left, right, case_sensitive)) - result._raw = result._value = "true"; - else - result._raw = result._value = "false"; + result._raw = result._value = eval_match (left, right, case_sensitive) + ? "false" + : "true"; // std::cout << "# " << left << " !~ " << right << " --> " << result << "\n"; } diff --git a/src/Task.cpp b/src/Task.cpp index 2d232fa0d..e30c4ce4d 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -108,11 +108,11 @@ Task::~Task () //////////////////////////////////////////////////////////////////////////////// Task::status Task::textToStatus (const std::string& input) { - if (input == "pending") return Task::pending; // TODO i18n - else if (input == "completed") return Task::completed; // TODO i18n - else if (input == "deleted") return Task::deleted; // TODO i18n - else if (input == "recurring") return Task::recurring; // TODO i18n - else if (input == "waiting") return Task::waiting; // TODO i18n + if (input == "pending") return Task::pending; + else if (input == "completed") return Task::completed; + else if (input == "deleted") return Task::deleted; + else if (input == "recurring") return Task::recurring; + else if (input == "waiting") return Task::waiting; return Task::pending; } @@ -234,12 +234,16 @@ time_t Task::get_duration (const std::string& name) const void Task::set (const std::string& name, const std::string& value) { (*this)[name] = value; + + recalc_urgency = true; } //////////////////////////////////////////////////////////////////////////////// void Task::set (const std::string& name, int value) { (*this)[name] = format (value); + + recalc_urgency = true; } //////////////////////////////////////////////////////////////////////////////// @@ -248,6 +252,8 @@ void Task::remove (const std::string& name) Task::iterator it; if ((it = this->find (name)) != this->end ()) this->erase (it); + + recalc_urgency = true; } //////////////////////////////////////////////////////////////////////////////// @@ -322,6 +328,8 @@ void Task::parse (const std::string& input) { legacyParse (copy); } + + recalc_urgency = true; } //////////////////////////////////////////////////////////////////////////////// @@ -499,6 +507,8 @@ void Task::legacyParse (const std::string& line) throw std::string (STRING_TASK_PARSE_UNREC_FF); break; } + + recalc_urgency = true; } //////////////////////////////////////////////////////////////////////////////// @@ -758,6 +768,7 @@ void Task::addAnnotation (const std::string& description) s << "annotation_" << time (NULL); (*this)[s.str ()] = description; + recalc_urgency = true; } //////////////////////////////////////////////////////////////////////////////// @@ -772,6 +783,8 @@ void Task::removeAnnotations () else i++; } + + recalc_urgency = true; } //////////////////////////////////////////////////////////////////////////////// @@ -800,6 +813,8 @@ void Task::addDependency (int id) // Prevent circular dependencies. if (dependencyIsCircular (*this)) throw std::string (STRING_TASK_DEPEND_CIRCULAR); + + recalc_urgency = true; } //////////////////////////////////////////////////////////////////////////////// @@ -817,6 +832,8 @@ void Task::removeDependency (const std::string& uuid) join (combined, ",", deps); set ("depends", combined); } + + recalc_urgency = true; } //////////////////////////////////////////////////////////////////////////////// @@ -827,6 +844,8 @@ void Task::removeDependency (int id) removeDependency (uuid); else throw std::string (STRING_TASK_DEPEND_NO_UUID); + + recalc_urgency = true; } //////////////////////////////////////////////////////////////////////////////// @@ -882,6 +901,8 @@ void Task::addTag (const std::string& tag) std::string combined; join (combined, ",", tags); set ("tags", combined); + + recalc_urgency = true; } } @@ -893,6 +914,8 @@ void Task::addTags (const std::vector & tags) std::vector ::const_iterator it; for (it = tags.begin (); it != tags.end (); ++it) addTag (*it); + + recalc_urgency = true; } //////////////////////////////////////////////////////////////////////////////// @@ -916,6 +939,8 @@ void Task::removeTag (const std::string& tag) join (combined, ",", tags); set ("tags", combined); } + + recalc_urgency = true; } //////////////////////////////////////////////////////////////////////////////// @@ -1032,6 +1057,7 @@ void Task::substitute ( { set ("description", description); setAnnotations (annotations); + recalc_urgency = true; } } diff --git a/src/text.cpp b/src/text.cpp index a2b06eb58..ad4febf53 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -905,7 +905,7 @@ const std::string format ( { std::string output = fmt; replace_positional (output, "{1}", format (arg1)); - replace_positional (output, "{2}", format (arg2, 6, 3)); + replace_positional (output, "{2}", trim (format (arg2, 6, 3))); return output; }