ColTemplate: New recurrence attribute
This commit is contained in:
@@ -24,6 +24,7 @@ set (columns_SRCS Column.cpp Column.h
|
||||
ColStatus.cpp ColStatus.h
|
||||
ColString.cpp ColString.h
|
||||
ColTags.cpp ColTags.h
|
||||
ColTemplate.cpp ColTemplate.h
|
||||
ColTypeDate.cpp ColTypeDate.h
|
||||
ColTypeDuration.cpp ColTypeDuration.h
|
||||
ColTypeNumeric.cpp ColTypeNumeric.h
|
||||
|
||||
78
src/columns/ColTemplate.cpp
Normal file
78
src/columns/ColTemplate.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2006 - 2016, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// http://www.opensource.org/licenses/mit-license.php
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cmake.h>
|
||||
#include <ColTemplate.h>
|
||||
#include <format.h>
|
||||
#include <i18n.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
ColumnTemplate::ColumnTemplate ()
|
||||
{
|
||||
_name = "template";
|
||||
_style = "long";
|
||||
_label = STRING_COLUMN_LABEL_TEMPLATE;
|
||||
_modifiable = false;
|
||||
_styles = {"long", "short"};
|
||||
_examples = {"f30cb9c3-3fc0-483f-bfb2-3bf134f00694", "f30cb9c3"};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Set the minimum and maximum widths for the value.
|
||||
void ColumnTemplate::measure (Task& task, unsigned int& minimum, unsigned int& maximum)
|
||||
{
|
||||
minimum = maximum = 0;
|
||||
|
||||
if (task.has (_name))
|
||||
{
|
||||
if (_style == "default" || _style == "long") minimum = maximum = 36;
|
||||
else if (_style == "short") minimum = maximum = 8;
|
||||
else
|
||||
throw format (STRING_COLUMN_BAD_FORMAT, _name, _style);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void ColumnTemplate::render (
|
||||
std::vector <std::string>& lines,
|
||||
Task& task,
|
||||
int width,
|
||||
Color& color)
|
||||
{
|
||||
if (task.has (_name))
|
||||
{
|
||||
// f30cb9c3-3fc0-483f-bfb2-3bf134f00694 default
|
||||
// f30cb9c3 short
|
||||
if (_style == "default" ||
|
||||
_style == "long")
|
||||
renderStringLeft (lines, width, color, task.get(_name));
|
||||
|
||||
else if (_style == "short")
|
||||
renderStringLeft (lines, width, color, task.get (_name).substr (0, 8));
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
43
src/columns/ColTemplate.h
Normal file
43
src/columns/ColTemplate.h
Normal file
@@ -0,0 +1,43 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2006 - 2016, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// http://www.opensource.org/licenses/mit-license.php
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDED_COLTEMPLATE
|
||||
#define INCLUDED_COLTEMPLATE
|
||||
|
||||
#include <ColTypeString.h>
|
||||
|
||||
class ColumnTemplate : public ColumnTypeString
|
||||
{
|
||||
public:
|
||||
ColumnTemplate ();
|
||||
void measure (Task&, unsigned int&, unsigned int&);
|
||||
void render (std::vector <std::string>&, Task&, int, Color&);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <ColStatus.h>
|
||||
#include <ColString.h>
|
||||
#include <ColTags.h>
|
||||
#include <ColTemplate.h>
|
||||
#include <ColUntil.h>
|
||||
#include <ColUrgency.h>
|
||||
#include <ColUUID.h>
|
||||
@@ -96,6 +97,7 @@ Column* Column::factory (const std::string& name, const std::string& report)
|
||||
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 == "template") c = new ColumnTemplate ();
|
||||
else if (column_name == "until") c = new ColumnUntil ();
|
||||
else if (column_name == "urgency") c = new ColumnUrgency ();
|
||||
else if (column_name == "uuid") c = new ColumnUUID ();
|
||||
@@ -138,6 +140,7 @@ void Column::factory (std::map <std::string, Column*>& all)
|
||||
c = new ColumnStart (); all[c->_name] = c;
|
||||
c = new ColumnStatus (); all[c->_name] = c;
|
||||
c = new ColumnTags (); all[c->_name] = c;
|
||||
c = new ColumnTemplate (); 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;
|
||||
|
||||
Reference in New Issue
Block a user