mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Code Reorganization
- Changed the ::measure and ::render methods from pure virtual to virtual. - Fixed bug where recur.indicator used the length of the indicator instead of the indicator. - Implemented ColString.{h,cpp} to support generic Views based on strings, not tasks. - Implemented newly virtual Column:: methods.
This commit is contained in:
parent
00125c19d1
commit
590273d4e8
6 changed files with 181 additions and 4 deletions
|
@ -17,6 +17,7 @@ set (columns_SRCS Column.cpp Column.h
|
|||
ColRecur.cpp ColRecur.h
|
||||
ColStart.cpp ColStart.h
|
||||
ColStatus.cpp ColStatus.h
|
||||
ColString.cpp ColString.h
|
||||
ColTags.cpp ColTags.h
|
||||
ColUntil.cpp ColUntil.h
|
||||
ColUrgency.cpp ColUrgency.h
|
||||
|
|
|
@ -89,7 +89,7 @@ void ColumnRecur::render (
|
|||
if (task.has ("recur"))
|
||||
lines.push_back (
|
||||
color.colorize (
|
||||
rightJustify (context.config.get ("recurrence.indicator").length (), width)));
|
||||
rightJustify (context.config.get ("recurrence.indicator"), width)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
96
src/columns/ColString.cpp
Normal file
96
src/columns/ColString.cpp
Normal file
|
@ -0,0 +1,96 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <Context.h>
|
||||
#include <ColString.h>
|
||||
#include <text.h>
|
||||
|
||||
extern Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
ColumnString::ColumnString ()
|
||||
{
|
||||
_type = "string";
|
||||
_style = "default";
|
||||
_label = "";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
ColumnString::~ColumnString ()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ColumnString is unique - it copies the report name into the label. This is
|
||||
// a kludgy reuse of an otherwise unused member.
|
||||
void ColumnString::setReport (const std::string& value)
|
||||
{
|
||||
_report = _label = value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Set the minimum and maximum widths for the value.
|
||||
void ColumnString::measure (const std::string& value, int& minimum, int& maximum)
|
||||
{
|
||||
maximum = value.length ();
|
||||
|
||||
if (_style == "fixed")
|
||||
{
|
||||
minimum = maximum;
|
||||
}
|
||||
else if (_style == "default")
|
||||
{
|
||||
minimum = longestWord (value);
|
||||
}
|
||||
else
|
||||
throw std::string ("Unrecognized column format '") + _type + "." + _style + "'";
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void ColumnString::render (
|
||||
std::vector <std::string>& lines,
|
||||
const std::string& value,
|
||||
int width,
|
||||
Color& color)
|
||||
{
|
||||
if (_style == "fixed")
|
||||
{
|
||||
lines.push_back (value);
|
||||
}
|
||||
else if (_style == "default")
|
||||
{
|
||||
std::vector <std::string> raw;
|
||||
wrapText (raw, value, width);
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = raw.begin (); i != raw.end (); ++i)
|
||||
lines.push_back (color.colorize (leftJustify (*i, width)));
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
50
src/columns/ColString.h
Normal file
50
src/columns/ColString.h
Normal file
|
@ -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_COLSTRING
|
||||
#define INCLUDED_COLSTRING
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <Column.h>
|
||||
#include <Color.h>
|
||||
#include <Task.h>
|
||||
|
||||
class ColumnString : public Column
|
||||
{
|
||||
public:
|
||||
ColumnString ();
|
||||
~ColumnString ();
|
||||
|
||||
void setReport (const std::string&);
|
||||
void measure (const std::string&, int&, int&);
|
||||
void render (std::vector <std::string>&, const std::string&, int, Color&);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
|
@ -38,6 +38,7 @@
|
|||
#include <ColRecur.h>
|
||||
#include <ColStart.h>
|
||||
#include <ColStatus.h>
|
||||
#include <ColString.h>
|
||||
#include <ColTags.h>
|
||||
#include <ColUntil.h>
|
||||
#include <ColUrgency.h>
|
||||
|
@ -86,8 +87,11 @@ Column* Column::factory (const std::string& name, const std::string& report)
|
|||
else if (column_name == "urgency") column = new ColumnUrgency ();
|
||||
else if (column_name == "uuid") column = new ColumnUUID ();
|
||||
else if (column_name == "wait") column = new ColumnWait ();
|
||||
|
||||
// Special non-task column
|
||||
else if (column_name == "string") column = new ColumnString ();
|
||||
else
|
||||
throw std::string ("Unrecognized column name '") + column_name + "'";
|
||||
throw std::string ("Unrecognized column name '") + column_name + "'.";
|
||||
|
||||
column->setReport (report);
|
||||
column->setStyle (column_style);
|
||||
|
@ -165,3 +169,27 @@ void Column::renderHeader (
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Column::measure (const std::string& value, int& minimum, int& maximum)
|
||||
{
|
||||
throw std::string ("Virtual method Column::measure not overriden.");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Column::measure (Task& task, int& minimum, int& maximum)
|
||||
{
|
||||
throw std::string ("Virtual method Column::measure not overriden.");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Column::render (std::vector <std::string>& lines, const std::string& value, int width, Color& color)
|
||||
{
|
||||
throw std::string ("Virtual method Column::render not overriden.");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Column::render (std::vector <std::string>& lines, Task& task, int width, Color& color)
|
||||
{
|
||||
throw std::string ("Virtual method Column::render not overriden.");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -51,9 +51,11 @@ public:
|
|||
virtual void setLabel (const std::string& value) { _label = value; }
|
||||
virtual void setReport (const std::string& value) { _report = value; }
|
||||
|
||||
virtual void measure (Task&, int&, int&) = 0;
|
||||
virtual void measure (const std::string&, int&, int&);
|
||||
virtual void measure (Task&, int&, int&);
|
||||
virtual void renderHeader (std::vector <std::string>&, int, Color&);
|
||||
virtual void render (std::vector <std::string>&, Task&, int, Color&) = 0;
|
||||
virtual void render (std::vector <std::string>&, const std::string&, int, Color&);
|
||||
virtual void render (std::vector <std::string>&, Task&, int, Color&);
|
||||
|
||||
protected:
|
||||
std::string _type;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue