From f2998aba7417a6fc765bdf6c518781a1967556f6 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 18 Feb 2015 20:53:56 -0800 Subject: [PATCH] TW-1547 - TW-1547 Recur column is always shown even if no recurring task is displayed (thanks to Renato Alves). --- ChangeLog | 8 +++- src/columns/ColIMask.cpp | 16 +++++-- src/columns/ColMask.cpp | 13 +++-- src/columns/ColParent.cpp | 42 +++++++++------- src/columns/ColPriority.cpp | 49 +++++++++++-------- src/columns/ColProject.cpp | 70 +++++++++++++++------------ src/columns/ColRecur.cpp | 28 ++++++----- src/columns/ColString.cpp | 2 + src/columns/ColTags.cpp | 44 +++++++++-------- src/columns/ColUDA.cpp | 95 +++++++++++++++++++------------------ 10 files changed, 209 insertions(+), 158 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19de57eed..50b812e6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,11 @@ 2.4.2 () - -- TW-1546 column type due.remaining breaks colors on due tasks (thanks to Renato - Alves). +- TW-1547 Recur column is always shown even if no recurring task is displayed + (thanks to Renato Alves). +- TW-1545 cc1plus: error: unrecognized command line option '-std=c++11' (thanks + to Petteri). +- TW-1546 column type due.remaining breaks colors on due tasks (thanks to + Renato Alves). - Eliminated some code that is not UTF8-safe. - Removed pthreads linkage. diff --git a/src/columns/ColIMask.cpp b/src/columns/ColIMask.cpp index bfe47990c..880b3c22c 100644 --- a/src/columns/ColIMask.cpp +++ b/src/columns/ColIMask.cpp @@ -62,11 +62,16 @@ bool ColumnIMask::validate (std::string& value) // Set the minimum and maximum widths for the value. void ColumnIMask::measure (Task& task, unsigned int& minimum, unsigned int& maximum) { - minimum = maximum = task.get ("imask").length (); + minimum = maximum = 0; - if (_style != "default" && - _style != "number") - throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); + if (task.has (_name)) + { + minimum = maximum = task.get ("imask").length (); + + if (_style != "default" && + _style != "number") + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); + } } //////////////////////////////////////////////////////////////////////////////// @@ -76,7 +81,8 @@ void ColumnIMask::render ( int width, Color& color) { - lines.push_back (color.colorize (rightJustify (task.get ("imask"), width))); + if (task.has (_name)) + lines.push_back (color.colorize (rightJustify (task.get ("imask"), width))); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColMask.cpp b/src/columns/ColMask.cpp index fa78fb5ff..dbb5af298 100644 --- a/src/columns/ColMask.cpp +++ b/src/columns/ColMask.cpp @@ -62,10 +62,14 @@ bool ColumnMask::validate (std::string& value) // Set the minimum and maximum widths for the value. void ColumnMask::measure (Task& task, unsigned int& minimum, unsigned int& maximum) { - minimum = maximum = task.get ("mask").length (); + minimum = maximum = 0; + if (task.has (_name)) + { + minimum = maximum = task.get ("mask").length (); - if (_style != "default") - throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); + if (_style != "default") + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); + } } //////////////////////////////////////////////////////////////////////////////// @@ -75,7 +79,8 @@ void ColumnMask::render ( int width, Color& color) { - lines.push_back (color.colorize (task.get ("mask"))); + if (task.has (_name)) + lines.push_back (color.colorize (task.get ("mask"))); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColParent.cpp b/src/columns/ColParent.cpp index 843b340ac..efc21582d 100644 --- a/src/columns/ColParent.cpp +++ b/src/columns/ColParent.cpp @@ -62,12 +62,17 @@ bool ColumnParent::validate (std::string& value) //////////////////////////////////////////////////////////////////////////////// // Set the minimum and maximum widths for the value. -void ColumnParent::measure (Task&, unsigned int& minimum, unsigned int& maximum) +void ColumnParent::measure (Task& task, unsigned int& minimum, unsigned int& maximum) { - if (_style == "default" || _style == "long") minimum = maximum = 36; - else if (_style == "short") minimum = maximum = 8; - else - throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); + minimum = maximum = 0; + + if (task.has (_name)) + { + if (_style == "default" || _style == "long") minimum = maximum = 36; + else if (_style == "short") minimum = maximum = 8; + else + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); + } } //////////////////////////////////////////////////////////////////////////////// @@ -77,20 +82,23 @@ void ColumnParent::render ( int width, Color& color) { - // f30cb9c3-3fc0-483f-bfb2-3bf134f00694 default - // 34f00694 short - if (_style == "default" || - _style == "long") + if (task.has (_name)) { - lines.push_back (color.colorize (leftJustify (task.get (_name), width))); - } + // f30cb9c3-3fc0-483f-bfb2-3bf134f00694 default + // 34f00694 short + if (_style == "default" || + _style == "long") + { + lines.push_back (color.colorize (leftJustify (task.get (_name), width))); + } - else if (_style == "short") - { - if (task.has (_name)) - lines.push_back (color.colorize (leftJustify (task.get (_name).substr (28), width))); - else - lines.push_back (color.colorize (leftJustify ("", width))); + else if (_style == "short") + { + if (task.has (_name)) + lines.push_back (color.colorize (leftJustify (task.get (_name).substr (28), width))); + else + lines.push_back (color.colorize (leftJustify ("", width))); + } } } diff --git a/src/columns/ColPriority.cpp b/src/columns/ColPriority.cpp index 381a578ad..faf31084e 100644 --- a/src/columns/ColPriority.cpp +++ b/src/columns/ColPriority.cpp @@ -78,22 +78,26 @@ void ColumnPriority::setStyle (const std::string& value) // Set the minimum and maximum widths for the value. void ColumnPriority::measure (Task& task, unsigned int& minimum, unsigned int& maximum) { - std::string priority = task.get (_name); - - if (priority == "") - minimum = maximum = 0; - else - minimum = maximum = 1; - - if (_style == "long") + minimum = maximum = 0; + if (task.has (_name)) { - if (priority == "H") minimum = maximum = 4; - else if (priority == "M") minimum = maximum = 6; - else if (priority == "L") minimum = maximum = 3; + std::string priority = task.get (_name); + + if (priority == "") + minimum = maximum = 0; + else + minimum = maximum = 1; + + if (_style == "long") + { + if (priority == "H") minimum = maximum = 4; + else if (priority == "M") minimum = maximum = 6; + else if (priority == "L") minimum = maximum = 3; + } + else if (_style != "default" && + _style != "short") + throw format (STRING_COLUMN_BAD_FORMAT, "priority", _style); } - else if (_style != "default" && - _style != "short") - throw format (STRING_COLUMN_BAD_FORMAT, "priority", _style); } //////////////////////////////////////////////////////////////////////////////// @@ -103,15 +107,18 @@ void ColumnPriority::render ( int width, Color& color) { - std::string priority = task.get (_name); - if (_style == "long") + if (task.has (_name)) { - if (priority == "H") priority = "High"; - else if (priority == "M") priority = "Medium"; - else if (priority == "L") priority = "Low"; - } + std::string priority = task.get (_name); + if (_style == "long") + { + if (priority == "H") priority = "High"; + else if (priority == "M") priority = "Medium"; + else if (priority == "L") priority = "Low"; + } - lines.push_back (color.colorize (leftJustify (priority, width))); + lines.push_back (color.colorize (leftJustify (priority, width))); + } } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColProject.cpp b/src/columns/ColProject.cpp index c7fe573d8..829c15716 100644 --- a/src/columns/ColProject.cpp +++ b/src/columns/ColProject.cpp @@ -68,25 +68,30 @@ bool ColumnProject::validate (std::string& value) // Set the minimum and maximum widths for the value. void ColumnProject::measure (Task& task, unsigned int& minimum, unsigned int& maximum) { - std::string project = task.get (_name); + minimum = maximum = 0; - if (_style == "parent") + if (task.has (_name)) { - std::string::size_type period = project.find ('.'); - if (period != std::string::npos) - project = project.substr (0, period); - } - else if (_style == "indented") - { - project = indentProject (project, " ", '.'); - } - else if (_style != "default" && - _style != "full" && - _style != "indented") - throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); + std::string project = task.get (_name); - minimum = longestWord (project); - maximum = utf8_width (project); + if (_style == "parent") + { + std::string::size_type period = project.find ('.'); + if (period != std::string::npos) + project = project.substr (0, period); + } + else if (_style == "indented") + { + project = indentProject (project, " ", '.'); + } + else if (_style != "default" && + _style != "full" && + _style != "indented") + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); + + minimum = longestWord (project); + maximum = utf8_width (project); + } } //////////////////////////////////////////////////////////////////////////////// @@ -96,24 +101,27 @@ void ColumnProject::render ( int width, Color& color) { - std::string project = task.get (_name); - if (_style == "parent") + if (task.has (_name)) { - std::string::size_type period = project.find ('.'); - if (period != std::string::npos) - project = project.substr (0, period); - } - else if (_style == "indented") - { - project = indentProject (project, " ", '.'); - } + std::string project = task.get (_name); + if (_style == "parent") + { + std::string::size_type period = project.find ('.'); + if (period != std::string::npos) + project = project.substr (0, period); + } + else if (_style == "indented") + { + project = indentProject (project, " ", '.'); + } - std::vector raw; - wrapText (raw, project, width, _hyphenate); + std::vector raw; + wrapText (raw, project, width, _hyphenate); - std::vector ::iterator i; - for (i = raw.begin (); i != raw.end (); ++i) - lines.push_back (color.colorize (leftJustify (*i, width))); + std::vector ::iterator i; + for (i = raw.begin (); i != raw.end (); ++i) + lines.push_back (color.colorize (leftJustify (*i, width))); + } } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColRecur.cpp b/src/columns/ColRecur.cpp index 4c8ce7276..d80e4e0d9 100644 --- a/src/columns/ColRecur.cpp +++ b/src/columns/ColRecur.cpp @@ -79,18 +79,23 @@ void ColumnRecur::setStyle (const std::string& value) // Set the minimum and maximum widths for the value. void ColumnRecur::measure (Task& task, unsigned int& minimum, unsigned int& maximum) { - if (_style == "default" || - _style == "duration") + minimum = maximum = 0; + + if (task.has (_name)) { - minimum = maximum = Duration (task.get ("recur")).formatISO ().length (); + if (_style == "default" || + _style == "duration") + { + minimum = maximum = Duration (task.get ("recur")).formatISO ().length (); + } + else if (_style == "indicator") + { + if (task.has (_name)) + minimum = maximum = utf8_width (context.config.get ("recurrence.indicator")); + } + else + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } - else if (_style == "indicator") - { - if (task.has (_name)) - minimum = maximum = utf8_width (context.config.get ("recurrence.indicator")); - } - else - throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } //////////////////////////////////////////////////////////////////////////////// @@ -108,8 +113,7 @@ void ColumnRecur::render ( lines.push_back ( color.colorize ( rightJustify ( - Duration (task.get ("recur")).formatISO (), - width))); + Duration (task.get ("recur")).formatISO (), width))); } else if (_style == "indicator") { diff --git a/src/columns/ColString.cpp b/src/columns/ColString.cpp index 654eaa79d..fb423d5d4 100644 --- a/src/columns/ColString.cpp +++ b/src/columns/ColString.cpp @@ -71,6 +71,8 @@ void ColumnString::setReport (const std::string& value) // void ColumnString::measure (const std::string& value, unsigned int& minimum, unsigned int& maximum) { + minimum = maximum = 0; + if (_style == "left" || _style == "right" || _style == "default") diff --git a/src/columns/ColTags.cpp b/src/columns/ColTags.cpp index d6e6ebcb1..32396f52b 100644 --- a/src/columns/ColTags.cpp +++ b/src/columns/ColTags.cpp @@ -84,30 +84,34 @@ void ColumnTags::setStyle (const std::string& value) // Set the minimum and maximum widths for the value. void ColumnTags::measure (Task& task, unsigned int& minimum, unsigned int& maximum) { - if (_style == "indicator") minimum = maximum = utf8_width (context.config.get ("tag.indicator")); - else if (_style == "count") minimum = maximum = 3; - else if (_style == "default" || - _style == "list") - { - std::string tags = task.get (_name); - minimum = 0; - maximum = utf8_width (tags); + minimum = maximum = 0; - if (maximum) + if (task.has (_name)) + { + if (_style == "indicator") minimum = maximum = utf8_width (context.config.get ("tag.indicator")); + else if (_style == "count") minimum = maximum = 3; + else if (_style == "default" || + _style == "list") { - std::vector all; - split (all, tags, ','); - std::vector ::iterator i; - for (i = all.begin (); i != all.end (); ++i) + std::string tags = task.get (_name); + maximum = utf8_width (tags); + + if (maximum) { - unsigned int length = utf8_width (*i); - if (length > minimum) - minimum = length; + std::vector all; + split (all, tags, ','); + std::vector ::iterator i; + for (i = all.begin (); i != all.end (); ++i) + { + unsigned int length = utf8_width (*i); + if (length > minimum) + minimum = length; + } } } + else + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } - else - throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } //////////////////////////////////////////////////////////////////////////////// @@ -117,9 +121,9 @@ void ColumnTags::render ( int width, Color& color) { - std::string tags = task.get (_name); - if (tags != "") + if (task.has (_name)) { + std::string tags = task.get (_name); if (_style == "default" || _style == "list") { diff --git a/src/columns/ColUDA.cpp b/src/columns/ColUDA.cpp index 5a18e3d56..ede3e8628 100644 --- a/src/columns/ColUDA.cpp +++ b/src/columns/ColUDA.cpp @@ -80,49 +80,52 @@ void ColumnUDA::measure (Task& task, unsigned int& minimum, unsigned int& maximu { minimum = maximum = 0; - if (_style == "default") + if (task.has (_name)) { - std::string value = task.get (_name); - if (value != "") + if (_style == "default") { - if (_type == "date") + std::string value = task.get (_name); + if (value != "") { - // Determine the output date format, which uses a hierarchy of definitions. - // rc.report..dateformat - // rc.dateformat.report - // rc.dateformat - Date date ((time_t) strtol (value.c_str (), NULL, 10)); - std::string format = context.config.get ("report." + _report + ".dateformat"); - if (format == "") - format = context.config.get ("dateformat.report"); - if (format == "") - format = context.config.get ("dateformat"); + if (_type == "date") + { + // Determine the output date format, which uses a hierarchy of definitions. + // rc.report..dateformat + // rc.dateformat.report + // rc.dateformat + Date date ((time_t) strtol (value.c_str (), NULL, 10)); + std::string format = context.config.get ("report." + _report + ".dateformat"); + if (format == "") + format = context.config.get ("dateformat.report"); + if (format == "") + format = context.config.get ("dateformat"); - minimum = maximum = Date::length (format); - } - else if (_type == "duration") - { - minimum = maximum = utf8_width (Duration (value).formatISO ()); - } - else if (_type == "string") - { - std::string stripped = Color::strip (value); - maximum = longestLine (stripped); - minimum = longestWord (stripped); - } - else if (_type == "numeric") - { - minimum = maximum = utf8_width (value); + minimum = maximum = Date::length (format); + } + else if (_type == "duration") + { + minimum = maximum = utf8_width (Duration (value).formatISO ()); + } + else if (_type == "string") + { + std::string stripped = Color::strip (value); + maximum = longestLine (stripped); + minimum = longestWord (stripped); + } + else if (_type == "numeric") + { + minimum = maximum = utf8_width (value); + } } } + else if (_style == "indicator") + { + if (task.has (_name)) + minimum = maximum = utf8_width (context.config.get ("uda." + _name + ".indicator")); + } + else + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } - else if (_style == "indicator") - { - if (task.has (_name)) - minimum = maximum = utf8_width (context.config.get ("uda." + _name + ".indicator")); - } - else - throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } //////////////////////////////////////////////////////////////////////////////// @@ -132,11 +135,11 @@ void ColumnUDA::render ( int width, Color& color) { - if (_style == "default") + if (task.has (_name)) { - std::string value = task.get (_name); - if (value != "") + if (_style == "default") { + std::string value = task.get (_name); if (_type == "date") { // Determine the output date format, which uses a hierarchy of definitions. @@ -177,13 +180,13 @@ void ColumnUDA::render ( lines.push_back (color.colorize (rightJustify (value, width))); } } - } - else if (_style == "indicator") - { - if (task.has (_name)) - lines.push_back ( - color.colorize ( - rightJustify (context.config.get ("uda." + _name + ".indicator"), width))); + else if (_style == "indicator") + { + if (task.has (_name)) + lines.push_back ( + color.colorize ( + rightJustify (context.config.get ("uda." + _name + ".indicator"), width))); + } } }