diff --git a/src/columns/CMakeLists.txt b/src/columns/CMakeLists.txt index 8a230b8f1..42c98f3ba 100644 --- a/src/columns/CMakeLists.txt +++ b/src/columns/CMakeLists.txt @@ -10,6 +10,7 @@ set (columns_SRCS Column.cpp Column.h ColID.cpp ColID.h ColPriority.cpp ColPriority.h ColProject.cpp ColProject.h + ColRecur.cpp ColRecur.h ColTags.cpp ColTags.h ColUUID.cpp ColUUID.h) diff --git a/src/columns/ColRecur.cpp b/src/columns/ColRecur.cpp new file mode 100644 index 000000000..113f168c2 --- /dev/null +++ b/src/columns/ColRecur.cpp @@ -0,0 +1,113 @@ +//////////////////////////////////////////////////////////////////////////////// +// taskwarrior - a command line task list manager. +// +// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez. +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the +// +// Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, +// Boston, MA +// 02110-1301 +// USA +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +ColumnRecur::ColumnRecur () +{ + _type = "string"; + _style = "default"; + _label = "Recur"; +} + +//////////////////////////////////////////////////////////////////////////////// +ColumnRecur::~ColumnRecur () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +// Overriden so that style <----> label are linked. +// Note that you can not determine which gets called first. +void ColumnRecur::setStyle (const std::string& value) +{ + _style = value; + + if (_style == "indicator" && _label == "Recur") + _label = _label.substr (0, context.config.get ("recurrence.indicator").length ()); +} + +//////////////////////////////////////////////////////////////////////////////// +// Set the minimum and maximum widths for the value. +void ColumnRecur::measure (Task& task, int& minimum, int& maximum) +{ + if (_style == "default") + { + minimum = maximum = task.get ("recur").length (); + } + else if (_style == "indicator") + { + if (task.has ("recur")) + minimum = maximum = context.config.get ("recurrence.indicator").length (); + } + else + throw std::string ("Unrecognized column format '") + _type + "." + _style + "'"; +} + +//////////////////////////////////////////////////////////////////////////////// +void ColumnRecur::render ( + std::vector & lines, + Task& task, + int width, + Color& color) +{ + if (_style == "default") + { + lines.push_back (color.colorize (rightJustify (task.get ("recur"), width))); + } + else if (_style == "indicator") + { + if (task.has ("recur")) + lines.push_back ( + color.colorize ( + rightJustify (context.config.get ("recurrence.indicator").length (), width))); + } + +/* + std::string project = task.get ("project"); + if (_style == "parent") + { + std::string::size_type period = project.find ('.'); + if (period != std::string::npos) + project = project.substr (0, period); + } + + std::vector raw; + wrapText (raw, project, 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.h b/src/columns/ColRecur.h new file mode 100644 index 000000000..6ef3187c7 --- /dev/null +++ b/src/columns/ColRecur.h @@ -0,0 +1,50 @@ +//////////////////////////////////////////////////////////////////////////////// +// taskwarrior - a command line task list manager. +// +// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez. +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the +// +// Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, +// Boston, MA +// 02110-1301 +// USA +// +//////////////////////////////////////////////////////////////////////////////// +#ifndef INCLUDED_COLRECUR +#define INCLUDED_COLRECUR + +#include +#include +#include +#include +#include + +class ColumnRecur : public Column +{ +public: + ColumnRecur (); + ~ColumnRecur (); + + void setStyle (const std::string&); + void measure (Task&, int&, int&); + void render (std::vector &, Task&, int, Color&); + +private: +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/Column.cpp b/src/columns/Column.cpp index c2436e660..ae2ec45ea 100644 --- a/src/columns/Column.cpp +++ b/src/columns/Column.cpp @@ -35,10 +35,10 @@ #include #include #include -//#include +#include //#include #include -//#include +//#include #include //#include #include @@ -46,9 +46,9 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// -// TODO Supports the new complete column definition: +// Supports the new complete column definition: // -// [.][.[.][.]] +// [.] // Column* Column::factory (const std::string& name) { @@ -76,7 +76,7 @@ Column* Column::factory (const std::string& name) 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 == "recur") column = new ColumnRecur (); // else if (column_name == "start") column = new ColumnStart (); else if (column_name == "tags") column = new ColumnTags (); // else if (column_name == "until") column = new ColumnUntil (); diff --git a/test/view.t.cpp b/test/view.t.cpp index 043cf25e7..81e5cfd48 100644 --- a/test/view.t.cpp +++ b/test/view.t.cpp @@ -43,6 +43,8 @@ int main (int argc, char** argv) // Set up configuration. context.config.set ("fontunderline", true); context.config.set ("tag.indicator", "+"); + context.config.set ("dependency.indicator", "D"); + context.config.set ("recurrence.indicator", "R"); // Two sample tasks. Task t1 ("[" @@ -57,6 +59,7 @@ int main (int argc, char** argv) "uuid:\"f30cb9c3-3fc0-483f-bfb2-3bf134f00694\" " "description:\"This is the description text\" " "project:\"Garden Care\" " + "recur:\"monthly\" " "depends:\"2a64f6e0-bf8e-430d-bf71-9ec3f0d9b661\"" "]"); t2.id = 11; @@ -86,6 +89,10 @@ int main (int argc, char** argv) view.add (Column::factory ("tags.count")); view.add (Column::factory ("description.truncated")); view.add (Column::factory ("depends")); + view.add (Column::factory ("depends.count")); + view.add (Column::factory ("depends.indicator")); + view.add (Column::factory ("recur")); + view.add (Column::factory ("recur.indicator")); view.width (100); view.leftMargin (4); /*