diff --git a/src/Context.cpp b/src/Context.cpp index 57a687a5d..c21af7f61 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -113,12 +113,17 @@ void Context::initialize (int argc, const char** argv) // Instantiate built-in command objects. Command::factory (commands); + // Instantiate built-in column objects. + Column::factory (columns); + // Finally categorize all arguments. args.categorize (); // TODO Instantiate extension command objects. // TODO Instantiate default command object. + // TODO Instantiate extension column objects. + // TODO Instantiate extension UDA objects. // TODO Instantiate extension format objects. diff --git a/src/Context.h b/src/Context.h index b3e08518c..def6ba196 100644 --- a/src/Context.h +++ b/src/Context.h @@ -106,6 +106,7 @@ public: */ std::map commands; + std::map columns; int terminal_width; int terminal_height; diff --git a/src/columns/ColDate.cpp b/src/columns/ColDate.cpp index 4884dc887..86cca1425 100644 --- a/src/columns/ColDate.cpp +++ b/src/columns/ColDate.cpp @@ -41,10 +41,10 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnDate::ColumnDate () { + _name = ""; _type = "date"; _style = "default"; _label = ""; - _attribute = ""; } //////////////////////////////////////////////////////////////////////////////// @@ -52,15 +52,21 @@ ColumnDate::~ColumnDate () { } +//////////////////////////////////////////////////////////////////////////////// +bool ColumnDate::validate (std::string& value) +{ + return true; +} + //////////////////////////////////////////////////////////////////////////////// // Set the minimum and maximum widths for the value. void ColumnDate::measure (Task& task, int& minimum, int& maximum) { minimum = maximum = 0; - if (task.has (_attribute)) + if (task.has (_name)) { - Date date ((time_t) strtol (task.get (_attribute).c_str (), NULL, 10)); + Date date ((time_t) strtol (task.get (_name).c_str (), NULL, 10)); if (_style == "default") { @@ -96,7 +102,7 @@ void ColumnDate::measure (Task& task, int& minimum, int& maximum) minimum = maximum = Duration (now - date).formatCompact ().length (); } else - throw format (STRING_COLUMN_BAD_FORMAT, _attribute, _style); + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } } @@ -107,7 +113,7 @@ void ColumnDate::render ( int width, Color& color) { - if (task.has (_attribute)) + if (task.has (_name)) { if (_style == "default") { @@ -124,12 +130,12 @@ void ColumnDate::render ( lines.push_back ( color.colorize ( leftJustify ( - Date ((time_t) strtol (task.get (_attribute).c_str (), NULL, 10)) + Date ((time_t) strtol (task.get (_name).c_str (), NULL, 10)) .toString (format), width))); } else if (_style == "julian") { - double julian = (Date ((time_t) strtol (task.get (_attribute).c_str (), NULL, 10)) + double julian = (Date ((time_t) strtol (task.get (_name).c_str (), NULL, 10)) .toEpoch () / 86400.0) + 2440587.5; lines.push_back ( @@ -142,7 +148,7 @@ void ColumnDate::render ( lines.push_back ( color.colorize ( rightJustify ( - Date ((time_t) strtol (task.get (_attribute).c_str (), NULL, 10)) + Date ((time_t) strtol (task.get (_name).c_str (), NULL, 10)) .toEpochString (), width))); } else if (_style == "iso") @@ -150,12 +156,12 @@ void ColumnDate::render ( lines.push_back ( color.colorize ( leftJustify ( - Date ((time_t) strtol (task.get (_attribute).c_str (), NULL, 10)) + Date ((time_t) strtol (task.get (_name).c_str (), NULL, 10)) .toISO (), width))); } else if (_style == "age") { - Date date ((time_t) strtol (task.get (_attribute).c_str (), NULL, 10)); + Date date ((time_t) strtol (task.get (_name).c_str (), NULL, 10)); Date now; lines.push_back ( diff --git a/src/columns/ColDate.h b/src/columns/ColDate.h index 7a943d3ca..dafc2b897 100644 --- a/src/columns/ColDate.h +++ b/src/columns/ColDate.h @@ -40,11 +40,9 @@ public: ColumnDate (); ~ColumnDate (); + virtual bool validate (std::string&); virtual void measure (Task&, int&, int&); virtual void render (std::vector &, Task&, int, Color&); - -protected: - std::string _attribute; }; #endif diff --git a/src/columns/ColDepends.cpp b/src/columns/ColDepends.cpp index d35eea841..7d589d538 100644 --- a/src/columns/ColDepends.cpp +++ b/src/columns/ColDepends.cpp @@ -39,6 +39,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnDepends::ColumnDepends () { + _name = "depends"; _type = "string"; _style = "default"; _label = STRING_COLUMN_LABEL_DEP; @@ -49,6 +50,12 @@ ColumnDepends::~ColumnDepends () { } +//////////////////////////////////////////////////////////////////////////////// +bool ColumnDepends::validate (std::string& value) +{ + return true; +} + //////////////////////////////////////////////////////////////////////////////// // Overriden so that style <----> label are linked. // Note that you can not determine which gets called first. @@ -93,7 +100,7 @@ void ColumnDepends::measure (Task& task, int& minimum, int& maximum) } } else - throw format (STRING_COLUMN_BAD_FORMAT, "depends", _style); + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } //////////////////////////////////////////////////////////////////////////////// @@ -103,7 +110,7 @@ void ColumnDepends::render ( int width, Color& color) { - if (task.has ("depends")) + if (task.has (_name)) { if (_style == "indicator") { diff --git a/src/columns/ColDepends.h b/src/columns/ColDepends.h index d70a3389a..925ae218b 100644 --- a/src/columns/ColDepends.h +++ b/src/columns/ColDepends.h @@ -40,6 +40,7 @@ public: ColumnDepends (); ~ColumnDepends (); + bool validate (std::string&); void setStyle (const std::string&); void measure (Task&, int&, int&); void render (std::vector &, Task&, int, Color&); diff --git a/src/columns/ColDescription.cpp b/src/columns/ColDescription.cpp index a88d1cfca..519d66cc8 100644 --- a/src/columns/ColDescription.cpp +++ b/src/columns/ColDescription.cpp @@ -40,6 +40,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnDescription::ColumnDescription () { + _name = "description"; _type = "string"; _style = "default"; _label = STRING_COLUMN_LABEL_DESC; @@ -50,11 +51,17 @@ ColumnDescription::~ColumnDescription () { } +//////////////////////////////////////////////////////////////////////////////// +bool ColumnDescription::validate (std::string& value) +{ + return true; +} + //////////////////////////////////////////////////////////////////////////////// // Set the minimum and maximum widths for the value. void ColumnDescription::measure (Task& task, int& minimum, int& maximum) { - std::string description = task.get ("description"); + std::string description = task.get (_name); // The text // @@ -127,7 +134,7 @@ void ColumnDescription::measure (Task& task, int& minimum, int& maximum) } else - throw format (STRING_COLUMN_BAD_FORMAT, "description.", _style); + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } //////////////////////////////////////////////////////////////////////////////// @@ -137,7 +144,7 @@ void ColumnDescription::render ( int width, Color& color) { - std::string description = task.get ("description"); + std::string description = task.get (_name); // This is a description // diff --git a/src/columns/ColDescription.h b/src/columns/ColDescription.h index c6c5f5795..bd68c7a5f 100644 --- a/src/columns/ColDescription.h +++ b/src/columns/ColDescription.h @@ -40,6 +40,7 @@ public: ColumnDescription (); ~ColumnDescription (); + bool validate (std::string&); void measure (Task&, int&, int&); void render (std::vector &, Task&, int, Color&); diff --git a/src/columns/ColDue.cpp b/src/columns/ColDue.cpp index 46a2dade1..943bbfcea 100644 --- a/src/columns/ColDue.cpp +++ b/src/columns/ColDue.cpp @@ -40,8 +40,8 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnDue::ColumnDue () { + _name = "due"; _label = STRING_COLUMN_LABEL_DUE; - _attribute = "due"; } //////////////////////////////////////////////////////////////////////////////// @@ -49,6 +49,12 @@ ColumnDue::~ColumnDue () { } +//////////////////////////////////////////////////////////////////////////////// +bool ColumnDue::validate (std::string& value) +{ + return ColumnDate::validate (value); +} + //////////////////////////////////////////////////////////////////////////////// // Overriden so that style <----> label are linked. // Note that you can not determine which gets called first. @@ -66,11 +72,11 @@ void ColumnDue::measure (Task& task, int& minimum, int& maximum) { minimum = maximum = 0; - if (task.has (_attribute)) + if (task.has (_name)) { if (_style == "countdown") { - Date date ((time_t) strtol (task.get (_attribute).c_str (), NULL, 10)); + Date date ((time_t) strtol (task.get (_name).c_str (), NULL, 10)); Date now; minimum = maximum = Duration (now - date).format ().length (); } @@ -86,11 +92,11 @@ void ColumnDue::render ( int width, Color& color) { - if (task.has (_attribute)) + if (task.has (_name)) { if (_style == "countdown") { - Date date ((time_t) strtol (task.get (_attribute).c_str (), NULL, 10)); + Date date ((time_t) strtol (task.get (_name).c_str (), NULL, 10)); Date now; lines.push_back ( diff --git a/src/columns/ColDue.h b/src/columns/ColDue.h index 508d2db45..9c4b5b995 100644 --- a/src/columns/ColDue.h +++ b/src/columns/ColDue.h @@ -36,6 +36,7 @@ public: ColumnDue (); ~ColumnDue (); + bool validate (std::string&); void setStyle (const std::string&); void measure (Task&, int&, int&); void render (std::vector &, Task&, int, Color&); diff --git a/src/columns/ColEnd.cpp b/src/columns/ColEnd.cpp index cd9bcde5c..388847b9f 100644 --- a/src/columns/ColEnd.cpp +++ b/src/columns/ColEnd.cpp @@ -33,8 +33,8 @@ //////////////////////////////////////////////////////////////////////////////// ColumnEnd::ColumnEnd () { + _name = "end"; _label = STRING_COLUMN_LABEL_COMPLETE; - _attribute = "end"; } //////////////////////////////////////////////////////////////////////////////// @@ -43,3 +43,9 @@ ColumnEnd::~ColumnEnd () } //////////////////////////////////////////////////////////////////////////////// +bool ColumnEnd::validate (std::string& value) +{ + return ColumnDate::validate (value); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColEnd.h b/src/columns/ColEnd.h index c360b2a51..146a2570b 100644 --- a/src/columns/ColEnd.h +++ b/src/columns/ColEnd.h @@ -35,6 +35,8 @@ class ColumnEnd : public ColumnDate public: ColumnEnd (); ~ColumnEnd (); + + bool validate (std::string&); }; #endif diff --git a/src/columns/ColEntry.cpp b/src/columns/ColEntry.cpp index 166c1a2dd..04f8f8712 100644 --- a/src/columns/ColEntry.cpp +++ b/src/columns/ColEntry.cpp @@ -33,8 +33,8 @@ //////////////////////////////////////////////////////////////////////////////// ColumnEntry::ColumnEntry () { + _name = "entry"; _label = STRING_COLUMN_LABEL_ADDED; - _attribute = "entry"; } //////////////////////////////////////////////////////////////////////////////// @@ -42,6 +42,12 @@ ColumnEntry::~ColumnEntry () { } +//////////////////////////////////////////////////////////////////////////////// +bool ColumnEntry::validate (std::string& value) +{ + return ColumnDate::validate (value); +} + //////////////////////////////////////////////////////////////////////////////// // Overriden so that style <----> label are linked. // Note that you can not determine which gets called first. diff --git a/src/columns/ColEntry.h b/src/columns/ColEntry.h index 1f3382822..3545a9d5c 100644 --- a/src/columns/ColEntry.h +++ b/src/columns/ColEntry.h @@ -36,6 +36,7 @@ public: ColumnEntry (); ~ColumnEntry (); + bool validate (std::string&); void setStyle (const std::string&); }; diff --git a/src/columns/ColID.cpp b/src/columns/ColID.cpp index e8186686d..f9790c443 100644 --- a/src/columns/ColID.cpp +++ b/src/columns/ColID.cpp @@ -38,6 +38,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnID::ColumnID () { + _name = "id"; _type = "number"; _style = "default"; _label = STRING_COLUMN_LABEL_ID; @@ -48,6 +49,12 @@ ColumnID::~ColumnID () { } +//////////////////////////////////////////////////////////////////////////////// +bool ColumnID::validate (std::string& value) +{ + return true; +} + //////////////////////////////////////////////////////////////////////////////// // Set the minimum and maximum widths for the value. void ColumnID::measure (Task& task, int& minimum, int& maximum) @@ -63,7 +70,7 @@ void ColumnID::measure (Task& task, int& minimum, int& maximum) minimum = maximum = length; if (_style != "default") - throw format (STRING_COLUMN_BAD_FORMAT, "id", _style); + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColID.h b/src/columns/ColID.h index ab42eb920..d6a4ca9f2 100644 --- a/src/columns/ColID.h +++ b/src/columns/ColID.h @@ -40,6 +40,7 @@ public: ColumnID (); ~ColumnID (); + bool validate (std::string&); void measure (Task&, int&, int&); void render (std::vector &, Task&, int, Color&); diff --git a/src/columns/ColPriority.cpp b/src/columns/ColPriority.cpp index 07fc91da1..44236b49d 100644 --- a/src/columns/ColPriority.cpp +++ b/src/columns/ColPriority.cpp @@ -37,6 +37,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnPriority::ColumnPriority () { + _name = "priority"; _type = "string"; _style = "default"; _label = STRING_COLUMN_LABEL_PRI; @@ -47,6 +48,20 @@ ColumnPriority::~ColumnPriority () { } +//////////////////////////////////////////////////////////////////////////////// +bool ColumnPriority::validate (std::string& value) +{ + value = upperCase (value); + + if (value == "H" || + value == "M" || + value == "L" || + value == "") + return true; + + return false; +} + //////////////////////////////////////////////////////////////////////////////// // Overriden so that style <----> label are linked. // Note that you can not determine which gets called first. @@ -62,7 +77,7 @@ void ColumnPriority::setStyle (const std::string& value) // Set the minimum and maximum widths for the value. void ColumnPriority::measure (Task& task, int& minimum, int& maximum) { - std::string priority = task.get ("priority"); + std::string priority = task.get (_name); minimum = maximum = 1; if (_style == "long") @@ -82,7 +97,7 @@ void ColumnPriority::render ( int width, Color& color) { - std::string priority = task.get ("priority"); + std::string priority = task.get (_name); if (_style == "long") { if (priority == "H") priority = "High"; diff --git a/src/columns/ColPriority.h b/src/columns/ColPriority.h index f5ecfd1bd..a0a0f288f 100644 --- a/src/columns/ColPriority.h +++ b/src/columns/ColPriority.h @@ -40,6 +40,7 @@ public: ColumnPriority (); ~ColumnPriority (); + bool validate (std::string&); void setStyle (const std::string&); void measure (Task&, int&, int&); void render (std::vector &, Task&, int, Color&); diff --git a/src/columns/ColProject.cpp b/src/columns/ColProject.cpp index a73e75d7f..1a479909d 100644 --- a/src/columns/ColProject.cpp +++ b/src/columns/ColProject.cpp @@ -37,6 +37,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnProject::ColumnProject () { + _name = "project"; _type = "string"; _style = "default"; _label = STRING_COLUMN_LABEL_PROJECT; @@ -47,11 +48,17 @@ ColumnProject::~ColumnProject () { } +//////////////////////////////////////////////////////////////////////////////// +bool ColumnProject::validate (std::string& value) +{ + return true; +} + //////////////////////////////////////////////////////////////////////////////// // Set the minimum and maximum widths for the value. void ColumnProject::measure (Task& task, int& minimum, int& maximum) { - std::string project = task.get ("project"); + std::string project = task.get (_name); if (_style == "parent") { @@ -60,7 +67,7 @@ void ColumnProject::measure (Task& task, int& minimum, int& maximum) project = project.substr (0, period); } else if (_style != "default") - throw format (STRING_COLUMN_BAD_FORMAT, "project.", _style); + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); minimum = longestWord (project); maximum = project.length (); @@ -73,7 +80,7 @@ void ColumnProject::render ( int width, Color& color) { - std::string project = task.get ("project"); + std::string project = task.get (_name); if (_style == "parent") { std::string::size_type period = project.find ('.'); diff --git a/src/columns/ColProject.h b/src/columns/ColProject.h index fb08fbb81..461b12a5c 100644 --- a/src/columns/ColProject.h +++ b/src/columns/ColProject.h @@ -40,6 +40,7 @@ public: ColumnProject (); ~ColumnProject (); + bool validate (std::string&); void measure (Task&, int&, int&); void render (std::vector &, Task&, int, Color&); diff --git a/src/columns/ColRecur.cpp b/src/columns/ColRecur.cpp index a473af3cd..f1edffaf9 100644 --- a/src/columns/ColRecur.cpp +++ b/src/columns/ColRecur.cpp @@ -37,6 +37,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnRecur::ColumnRecur () { + _name = "recur"; _type = "string"; _style = "default"; _label = STRING_COLUMN_LABEL_RECUR; @@ -47,6 +48,12 @@ ColumnRecur::~ColumnRecur () { } +//////////////////////////////////////////////////////////////////////////////// +bool ColumnRecur::validate (std::string& value) +{ + return true; +} + //////////////////////////////////////////////////////////////////////////////// // Overriden so that style <----> label are linked. // Note that you can not determine which gets called first. @@ -68,11 +75,11 @@ void ColumnRecur::measure (Task& task, int& minimum, int& maximum) } else if (_style == "indicator") { - if (task.has ("recur")) + if (task.has (_name)) minimum = maximum = context.config.get ("recurrence.indicator").length (); } else - throw format (STRING_COLUMN_BAD_FORMAT, "recur.", _style); + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } //////////////////////////////////////////////////////////////////////////////// @@ -88,7 +95,7 @@ void ColumnRecur::render ( } else if (_style == "indicator") { - if (task.has ("recur")) + if (task.has (_name)) lines.push_back ( color.colorize ( rightJustify (context.config.get ("recurrence.indicator"), width))); diff --git a/src/columns/ColRecur.h b/src/columns/ColRecur.h index 7f3c7fd70..12de48373 100644 --- a/src/columns/ColRecur.h +++ b/src/columns/ColRecur.h @@ -40,6 +40,7 @@ public: ColumnRecur (); ~ColumnRecur (); + bool validate (std::string&); void setStyle (const std::string&); void measure (Task&, int&, int&); void render (std::vector &, Task&, int, Color&); diff --git a/src/columns/ColStart.cpp b/src/columns/ColStart.cpp index c82628095..d6f1ba702 100644 --- a/src/columns/ColStart.cpp +++ b/src/columns/ColStart.cpp @@ -37,8 +37,8 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnStart::ColumnStart () { - _label = STRING_COLUMN_LABEL_STARTED; - _attribute = "start"; + _name = "start"; + _label = STRING_COLUMN_LABEL_STARTED; } //////////////////////////////////////////////////////////////////////////////// @@ -46,6 +46,12 @@ ColumnStart::~ColumnStart () { } +//////////////////////////////////////////////////////////////////////////////// +bool ColumnStart::validate (std::string& value) +{ + return ColumnDate::validate (value); +} + //////////////////////////////////////////////////////////////////////////////// // Overriden so that style <----> label are linked. // Note that you can not determine which gets called first. @@ -63,7 +69,7 @@ void ColumnStart::measure (Task& task, int& minimum, int& maximum) { minimum = maximum = 0; - if (task.has (_attribute)) + if (task.has (_name)) { if (_style == "active") { @@ -82,7 +88,7 @@ void ColumnStart::render ( int width, Color& color) { - if (task.has (_attribute)) + if (task.has (_name)) { if (_style == "active") { diff --git a/src/columns/ColStart.h b/src/columns/ColStart.h index 9e59a111a..98903cf01 100644 --- a/src/columns/ColStart.h +++ b/src/columns/ColStart.h @@ -36,6 +36,7 @@ public: ColumnStart (); ~ColumnStart (); + bool validate (std::string&); void setStyle (const std::string&); void measure (Task&, int&, int&); void render (std::vector &, Task&, int, Color&); diff --git a/src/columns/ColStatus.cpp b/src/columns/ColStatus.cpp index 3a0e46bb5..af97cd01c 100644 --- a/src/columns/ColStatus.cpp +++ b/src/columns/ColStatus.cpp @@ -37,6 +37,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnStatus::ColumnStatus () { + _name = "status"; _type = "string"; _style = "default"; _label = STRING_COLUMN_LABEL_STATUS; @@ -47,6 +48,12 @@ ColumnStatus::~ColumnStatus () { } +//////////////////////////////////////////////////////////////////////////////// +bool ColumnStatus::validate (std::string& value) +{ + return true; +} + //////////////////////////////////////////////////////////////////////////////// // Overriden so that style <----> label are linked. // Note that you can not determine which gets called first. @@ -81,7 +88,7 @@ void ColumnStatus::measure (Task& task, int& minimum, int& maximum) else if (_style == "short") minimum = maximum = 1; else - throw format (STRING_COLUMN_BAD_FORMAT, "status.", _style); + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColStatus.h b/src/columns/ColStatus.h index cc2368870..82207faf6 100644 --- a/src/columns/ColStatus.h +++ b/src/columns/ColStatus.h @@ -40,6 +40,7 @@ public: ColumnStatus (); ~ColumnStatus (); + bool validate (std::string&); void setStyle (const std::string&); void measure (Task&, int&, int&); void render (std::vector &, Task&, int, Color&); diff --git a/src/columns/ColString.cpp b/src/columns/ColString.cpp index adb264d95..ea8166a04 100644 --- a/src/columns/ColString.cpp +++ b/src/columns/ColString.cpp @@ -1,4 +1,4 @@ -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // taskwarrior - a command line task list manager. // // Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez. @@ -37,6 +37,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnString::ColumnString () { + _name = "string"; _type = "string"; _style = "default"; _label = ""; @@ -72,7 +73,7 @@ void ColumnString::measure (const std::string& value, int& minimum, int& maximum _style == "right_fixed") minimum = maximum = strippedLength (value); else - throw format (STRING_COLUMN_BAD_FORMAT, "string.", _style); + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColTags.cpp b/src/columns/ColTags.cpp index c7aa97024..7f4405007 100644 --- a/src/columns/ColTags.cpp +++ b/src/columns/ColTags.cpp @@ -38,6 +38,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnTags::ColumnTags () { + _name = "tags"; _type = "string"; _style = "default"; _label = STRING_COLUMN_LABEL_TAGS; @@ -48,6 +49,12 @@ ColumnTags::~ColumnTags () { } +//////////////////////////////////////////////////////////////////////////////// +bool ColumnTags::validate (std::string& value) +{ + return true; +} + //////////////////////////////////////////////////////////////////////////////// // Overriden so that style <----> label are linked. // Note that you can not determine which gets called first. @@ -73,7 +80,7 @@ void ColumnTags::measure (Task& task, int& minimum, int& maximum) else if (_style == "count") minimum = maximum = 3; else if (_style == "default") { - std::string tags = task.get ("tags"); + std::string tags = task.get (_name); minimum = 0; maximum = tags.length (); @@ -88,7 +95,7 @@ void ColumnTags::measure (Task& task, int& minimum, int& maximum) } } else - throw format (STRING_COLUMN_BAD_FORMAT, "tags.", _style); + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } //////////////////////////////////////////////////////////////////////////////// @@ -98,7 +105,7 @@ void ColumnTags::render ( int width, Color& color) { - std::string tags = task.get ("tags"); + std::string tags = task.get (_name); if (tags != "") { if (_style == "indicator") diff --git a/src/columns/ColTags.h b/src/columns/ColTags.h index 9b83ab976..7c4180b0e 100644 --- a/src/columns/ColTags.h +++ b/src/columns/ColTags.h @@ -40,6 +40,7 @@ public: ColumnTags (); ~ColumnTags (); + bool validate (std::string&); void setStyle (const std::string&); void measure (Task&, int&, int&); void render (std::vector &, Task&, int, Color&); diff --git a/src/columns/ColUUID.cpp b/src/columns/ColUUID.cpp index 35e8dacd2..bd3c1a7a2 100644 --- a/src/columns/ColUUID.cpp +++ b/src/columns/ColUUID.cpp @@ -38,6 +38,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnUUID::ColumnUUID () { + _name = "uuid"; _type = "string"; _style = "default"; _label = STRING_COLUMN_LABEL_UUID; @@ -48,6 +49,12 @@ ColumnUUID::~ColumnUUID () { } +//////////////////////////////////////////////////////////////////////////////// +bool ColumnUUID::validate (std::string& value) +{ + return true; +} + //////////////////////////////////////////////////////////////////////////////// // Set the minimum and maximum widths for the value. void ColumnUUID::measure (Task&, int& minimum, int& maximum) @@ -55,7 +62,7 @@ void ColumnUUID::measure (Task&, int& minimum, int& maximum) if (_style == "default") minimum = maximum = 36; else if (_style == "short") minimum = maximum = 8; else - throw format (STRING_COLUMN_BAD_FORMAT, "uuid.", _style); + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } //////////////////////////////////////////////////////////////////////////////// @@ -68,10 +75,10 @@ void ColumnUUID::render ( // f30cb9c3-3fc0-483f-bfb2-3bf134f00694 default // 34f00694 short if (_style == "default") - lines.push_back (color.colorize (leftJustify (task.get ("uuid"), width))); + lines.push_back (color.colorize (leftJustify (task.get (_name), width))); else if (_style == "short") - lines.push_back (color.colorize (leftJustify (task.get ("uuid").substr (28), width))); + lines.push_back (color.colorize (leftJustify (task.get (_name).substr (28), width))); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColUUID.h b/src/columns/ColUUID.h index 2d6934f25..5507e49e1 100644 --- a/src/columns/ColUUID.h +++ b/src/columns/ColUUID.h @@ -40,6 +40,7 @@ public: ColumnUUID (); ~ColumnUUID (); + bool validate (std::string&); void measure (Task&, int&, int&); void render (std::vector &, Task&, int, Color&); diff --git a/src/columns/ColUntil.cpp b/src/columns/ColUntil.cpp index 177ead8c1..743f1d327 100644 --- a/src/columns/ColUntil.cpp +++ b/src/columns/ColUntil.cpp @@ -33,8 +33,8 @@ //////////////////////////////////////////////////////////////////////////////// ColumnUntil::ColumnUntil () { + _name = "until"; _label = STRING_COLUMN_LABEL_UNTIL; - _attribute = "until"; } //////////////////////////////////////////////////////////////////////////////// @@ -43,3 +43,9 @@ ColumnUntil::~ColumnUntil () } //////////////////////////////////////////////////////////////////////////////// +bool ColumnUntil::validate (std::string& value) +{ + return ColumnDate::validate (value); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColUntil.h b/src/columns/ColUntil.h index fcb06c062..56065ed9f 100644 --- a/src/columns/ColUntil.h +++ b/src/columns/ColUntil.h @@ -35,6 +35,8 @@ class ColumnUntil : public ColumnDate public: ColumnUntil (); ~ColumnUntil (); + + bool validate (std::string&); }; #endif diff --git a/src/columns/ColUrgency.cpp b/src/columns/ColUrgency.cpp index 64b2337f0..8d0870416 100644 --- a/src/columns/ColUrgency.cpp +++ b/src/columns/ColUrgency.cpp @@ -37,6 +37,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnUrgency::ColumnUrgency () { + _name = "urgency"; _type = "number"; _style = "default"; _label = STRING_COLUMN_LABEL_URGENCY; @@ -54,7 +55,7 @@ void ColumnUrgency::measure (Task& task, int& minimum, int& maximum) minimum = maximum = format (task.urgency (), 4, 3).length (); if (_style != "default") - throw format (STRING_COLUMN_BAD_FORMAT, "urgency.", _style); + throw format (STRING_COLUMN_BAD_FORMAT, _name, _style); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColWait.cpp b/src/columns/ColWait.cpp index 44460bf13..e7f915519 100644 --- a/src/columns/ColWait.cpp +++ b/src/columns/ColWait.cpp @@ -33,8 +33,8 @@ //////////////////////////////////////////////////////////////////////////////// ColumnWait::ColumnWait () { + _name = "wait"; _label = STRING_COLUMN_LABEL_WAIT; - _attribute = "wait"; } //////////////////////////////////////////////////////////////////////////////// @@ -43,3 +43,9 @@ ColumnWait::~ColumnWait () } //////////////////////////////////////////////////////////////////////////////// +bool ColumnWait::validate (std::string& value) +{ + return ColumnDate::validate (value); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColWait.h b/src/columns/ColWait.h index 93510b6fe..b1a9ecdf2 100644 --- a/src/columns/ColWait.h +++ b/src/columns/ColWait.h @@ -35,6 +35,8 @@ class ColumnWait : public ColumnDate public: ColumnWait (); ~ColumnWait (); + + bool validate (std::string&); }; #endif diff --git a/src/columns/Column.cpp b/src/columns/Column.cpp index c26b49e4e..2acfa1beb 100644 --- a/src/columns/Column.cpp +++ b/src/columns/Column.cpp @@ -52,7 +52,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// -// Supports the new complete column definition: +// Supports the complete column definition: // // [.] // @@ -73,37 +73,62 @@ Column* Column::factory (const std::string& name, const std::string& report) column_style = "default"; } - Column* column; - if (column_name == "depends") column = new ColumnDepends (); - else if (column_name == "description") column = new ColumnDescription (); - else if (column_name == "due") column = new ColumnDue (); - else if (column_name == "end") column = new ColumnEnd (); - else if (column_name == "entry") column = new ColumnEntry (); - else if (column_name == "id") column = new ColumnID (); - else if (column_name == "priority") column = new ColumnPriority (); - else if (column_name == "project") column = new ColumnProject (); - else if (column_name == "recur") column = new ColumnRecur (); - else if (column_name == "start") column = new ColumnStart (); - else if (column_name == "status") column = new ColumnStatus (); - else if (column_name == "tags") column = new ColumnTags (); - else if (column_name == "until") column = new ColumnUntil (); - else if (column_name == "urgency") column = new ColumnUrgency (); - else if (column_name == "uuid") column = new ColumnUUID (); - else if (column_name == "wait") column = new ColumnWait (); + Column* c; + if (column_name == "depends") c = new ColumnDepends (); + else if (column_name == "description") c = new ColumnDescription (); + else if (column_name == "due") c = new ColumnDue (); + else if (column_name == "end") c = new ColumnEnd (); + else if (column_name == "entry") c = new ColumnEntry (); + else if (column_name == "id") c = new ColumnID (); + else if (column_name == "priority") c = new ColumnPriority (); + else if (column_name == "project") c = new ColumnProject (); + else if (column_name == "recur") c = new ColumnRecur (); + else if (column_name == "start") c = new ColumnStart (); + else if (column_name == "status") c = new ColumnStatus (); + else if (column_name == "tags") c = new ColumnTags (); + else if (column_name == "until") c = new ColumnUntil (); + else if (column_name == "urgency") c = new ColumnUrgency (); + else if (column_name == "uuid") c = new ColumnUUID (); + else if (column_name == "wait") c = new ColumnWait (); - // Special non-task column - else if (column_name == "string") column = new ColumnString (); + // Special non-task column. + else if (column_name == "string") c = new ColumnString (); else throw format (STRING_COLUMN_BAD_NAME, column_name); - column->setReport (report); - column->setStyle (column_style); - return column; + c->setReport (report); + c->setStyle (column_style); + return c; +} + +//////////////////////////////////////////////////////////////////////////////// +// Bulk column instantiation. +void Column::factory (std::map & all) +{ + Column* c; + + c = new ColumnDepends (); all[c->_name] = c; + c = new ColumnDescription (); all[c->_name] = c; + c = new ColumnDue (); all[c->_name] = c; + c = new ColumnEnd (); all[c->_name] = c; + c = new ColumnEntry (); all[c->_name] = c; + c = new ColumnID (); all[c->_name] = c; + c = new ColumnPriority (); all[c->_name] = c; + c = new ColumnProject (); all[c->_name] = c; + c = new ColumnRecur (); all[c->_name] = c; + c = new ColumnStart (); all[c->_name] = c; + c = new ColumnStatus (); all[c->_name] = c; + c = new ColumnTags (); all[c->_name] = c; + c = new ColumnUntil (); all[c->_name] = c; + c = new ColumnUrgency (); all[c->_name] = c; + c = new ColumnUUID (); all[c->_name] = c; + c = new ColumnWait (); all[c->_name] = c; } //////////////////////////////////////////////////////////////////////////////// Column::Column () -: _type ("string") +: _name ("") +, _type ("string") , _style ("default") , _label ("") , _report ("") @@ -113,9 +138,11 @@ Column::Column () //////////////////////////////////////////////////////////////////////////////// Column::Column (const Column& other) { + _name = other._name; _type = other._type; _style = other._style; _label = other._label; + _label = other._report; } //////////////////////////////////////////////////////////////////////////////// @@ -123,9 +150,11 @@ Column& Column::operator= (const Column& other) { if (this != &other) { + _name = other._name; _type = other._type; _style = other._style; _label = other._label; + _report = other._report; } return *this; @@ -134,8 +163,9 @@ Column& Column::operator= (const Column& other) //////////////////////////////////////////////////////////////////////////////// bool Column::operator== (const Column& other) const { - return _type == other._type && - _style == other._style && + return _name == other._name && + _type == other._type && + _style == other._style && _label == other._label; } @@ -176,6 +206,12 @@ void Column::renderHeader ( } } +//////////////////////////////////////////////////////////////////////////////// +bool Column::validate (std::string& input) +{ + return input.length () ? true : false; +} + //////////////////////////////////////////////////////////////////////////////// // No L10N. void Column::measure (const std::string&, int&, int&) diff --git a/src/columns/Column.h b/src/columns/Column.h index 692a6f48c..832fba0d7 100644 --- a/src/columns/Column.h +++ b/src/columns/Column.h @@ -37,6 +37,7 @@ class Column { public: static Column* factory (const std::string&, const std::string&); + static void factory (std::map &); Column (); Column (const Column&); @@ -52,6 +53,7 @@ public: virtual void setLabel (const std::string& value) { _label = value; } virtual void setReport (const std::string& value) { _report = value; } + virtual bool validate (std::string&); virtual void measure (const std::string&, int&, int&); virtual void measure (Task&, int&, int&); virtual void renderHeader (std::vector &, int, Color&); @@ -59,6 +61,7 @@ public: virtual void render (std::vector &, Task&, int, Color&); protected: + std::string _name; std::string _type; std::string _style; std::string _label;