mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +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
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)));
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
Loading…
Add table
Add a link
Reference in a new issue