- TW-1547 Recur column is always shown even if no recurring task is displayed
          (thanks to Renato Alves).
This commit is contained in:
Paul Beckingham 2015-02-18 20:53:56 -08:00
parent d2b2631db7
commit f2998aba74
10 changed files with 209 additions and 158 deletions

View file

@ -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)));
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -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")));
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -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)));
}
}
}

View file

@ -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)));
}
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -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 <std::string> raw;
wrapText (raw, project, width, _hyphenate);
std::vector <std::string> raw;
wrapText (raw, project, width, _hyphenate);
std::vector <std::string>::iterator i;
for (i = raw.begin (); i != raw.end (); ++i)
lines.push_back (color.colorize (leftJustify (*i, width)));
std::vector <std::string>::iterator i;
for (i = raw.begin (); i != raw.end (); ++i)
lines.push_back (color.colorize (leftJustify (*i, width)));
}
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -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")
{

View file

@ -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")

View file

@ -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 <std::string> all;
split (all, tags, ',');
std::vector <std::string>::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 <std::string> all;
split (all, tags, ',');
std::vector <std::string>::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")
{

View file

@ -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.<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.<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)));
}
}
}