diff --git a/src/columns/CMakeLists.txt b/src/columns/CMakeLists.txt index 42c98f3ba..8695e4ca5 100644 --- a/src/columns/CMakeLists.txt +++ b/src/columns/CMakeLists.txt @@ -11,6 +11,7 @@ set (columns_SRCS Column.cpp Column.h ColPriority.cpp ColPriority.h ColProject.cpp ColProject.h ColRecur.cpp ColRecur.h + ColStatus.cpp ColStatus.h ColTags.cpp ColTags.h ColUUID.cpp ColUUID.h) diff --git a/src/columns/ColStatus.cpp b/src/columns/ColStatus.cpp new file mode 100644 index 000000000..b6193e12a --- /dev/null +++ b/src/columns/ColStatus.cpp @@ -0,0 +1,115 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +ColumnStatus::ColumnStatus () +{ + _type = "string"; + _style = "default"; + _label = "Status"; +} + +//////////////////////////////////////////////////////////////////////////////// +ColumnStatus::~ColumnStatus () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +// Overriden so that style <----> label are linked. +// Note that you can not determine which gets called first. +void ColumnStatus::setStyle (const std::string& value) +{ + _style = value; + + if (_style == "short" && _label == "Status") + _label = "St"; +} + +//////////////////////////////////////////////////////////////////////////////// +// Set the minimum and maximum widths for the value. +void ColumnStatus::measure (Task& task, int& minimum, int& maximum) +{ + Task::status status = task.getStatus (); + + if (_style == "default") + { + if (status == Task::pending || + status == Task::deleted || + status == Task::waiting) + { + minimum = maximum = 7; + } + else if (status == Task::completed || + status == Task::recurring) + { + minimum = maximum = 9; + } + } + else if (_style == "short") + minimum = maximum = 1; + else + throw std::string ("Unrecognized column format '") + _type + "." + _style + "'"; +} + +//////////////////////////////////////////////////////////////////////////////// +void ColumnStatus::render ( + std::vector & lines, + Task& task, + int width, + Color& color) +{ + Task::status status = task.getStatus (); + std::string value; + + if (_style == "default") + { + if (status == Task::pending) value = "Pending"; + else if (status == Task::completed) value = "Completed"; + else if (status == Task::deleted) value = "Deleted"; + else if (status == Task::waiting) value = "Waiting"; + else if (status == Task::recurring) value = "Recurring"; + } + + else if (_style == "short") + { + if (status == Task::pending) value = "P"; + else if (status == Task::completed) value = "C"; + else if (status == Task::deleted) value = "D"; + else if (status == Task::waiting) value = "W"; + else if (status == Task::recurring) value = "R"; + } + + lines.push_back (color.colorize (leftJustify (value, width))); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColStatus.h b/src/columns/ColStatus.h new file mode 100644 index 000000000..965afb5e8 --- /dev/null +++ b/src/columns/ColStatus.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_COLSTATUS +#define INCLUDED_COLSTATUS + +#include +#include +#include +#include +#include + +class ColumnStatus : public Column +{ +public: + ColumnStatus (); + ~ColumnStatus (); + + 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 ae2ec45ea..055ff36e5 100644 --- a/src/columns/Column.cpp +++ b/src/columns/Column.cpp @@ -37,6 +37,7 @@ #include #include //#include +#include #include //#include #include @@ -78,6 +79,7 @@ Column* Column::factory (const std::string& name) 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 == "uuid") column = new ColumnUUID (); diff --git a/test/view.t.cpp b/test/view.t.cpp index 81e5cfd48..bc77a6173 100644 --- a/test/view.t.cpp +++ b/test/view.t.cpp @@ -48,6 +48,7 @@ int main (int argc, char** argv) // Two sample tasks. Task t1 ("[" + "status:\"pending\" " "uuid:\"2a64f6e0-bf8e-430d-bf71-9ec3f0d9b661\" " "description:\"This is the description text\" " "project:\"Home\" " @@ -56,6 +57,7 @@ int main (int argc, char** argv) "]"); t1.id = 1; Task t2 ("[" + "status:\"pending\" " "uuid:\"f30cb9c3-3fc0-483f-bfb2-3bf134f00694\" " "description:\"This is the description text\" " "project:\"Garden Care\" " @@ -93,7 +95,9 @@ int main (int argc, char** argv) view.add (Column::factory ("depends.indicator")); view.add (Column::factory ("recur")); view.add (Column::factory ("recur.indicator")); - view.width (100); + view.add (Column::factory ("status")); + view.add (Column::factory ("status.short")); + view.width (120); view.leftMargin (4); /* view.extraPadding (1);