Columns - mask, imask, parent

- Implemented column objects for the mask, imask and parent attributes.
  Why not.
This commit is contained in:
Paul Beckingham 2011-08-07 02:58:43 -04:00
parent cdda791c84
commit 6140f4af9d
9 changed files with 424 additions and 8 deletions

View file

@ -13,6 +13,9 @@ set (columns_SRCS Column.cpp Column.h
ColEnd.cpp ColEnd.h
ColEntry.cpp ColEntry.h
ColID.cpp ColID.h
ColIMask.cpp ColIMask.h
ColMask.cpp ColMask.h
ColParent.cpp ColParent.h
ColPriority.cpp ColPriority.h
ColProject.cpp ColProject.h
ColRecur.cpp ColRecur.h

84
src/columns/ColIMask.cpp Normal file
View file

@ -0,0 +1,84 @@
////////////////////////////////////////////////////////////////////////////////
// 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
//
////////////////////////////////////////////////////////////////////////////////
#define L10N // Localization complete.
#include <math.h>
#include <Context.h>
#include <ColIMask.h>
#include <text.h>
#include <i18n.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
ColumnIMask::ColumnIMask ()
{
_name = "imask";
_type = "number";
_style = "number";
_label = STRING_COLUMN_LABEL_MASK_IDX;
_modifiable = false;
_styles.push_back ("number");
_examples.push_back ("12");
}
////////////////////////////////////////////////////////////////////////////////
ColumnIMask::~ColumnIMask ()
{
}
////////////////////////////////////////////////////////////////////////////////
bool ColumnIMask::validate (std::string& value)
{
return true;
}
////////////////////////////////////////////////////////////////////////////////
// Set the minimum and maximum widths for the value.
void ColumnIMask::measure (Task& task, int& minimum, int& maximum)
{
minimum = maximum = task.get ("imask").length ();
if (_style != "default" &&
_style != "number")
throw format (STRING_COLUMN_BAD_FORMAT, _name, _style);
}
////////////////////////////////////////////////////////////////////////////////
void ColumnIMask::render (
std::vector <std::string>& lines,
Task& task,
int width,
Color& color)
{
lines.push_back (color.colorize (rightJustify (task.get ("imask"), width)));
}
////////////////////////////////////////////////////////////////////////////////

51
src/columns/ColIMask.h Normal file
View file

@ -0,0 +1,51 @@
////////////////////////////////////////////////////////////////////////////////
// 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_COLIMASK
#define INCLUDED_COLIMASK
#define L10N // Localization complete.
#include <vector>
#include <string>
#include <Column.h>
#include <Color.h>
#include <Task.h>
class ColumnIMask : public Column
{
public:
ColumnIMask ();
~ColumnIMask ();
bool validate (std::string&);
void measure (Task&, int&, int&);
void render (std::vector <std::string>&, Task&, int, Color&);
private:
};
#endif
////////////////////////////////////////////////////////////////////////////////

83
src/columns/ColMask.cpp Normal file
View file

@ -0,0 +1,83 @@
////////////////////////////////////////////////////////////////////////////////
// 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
//
////////////////////////////////////////////////////////////////////////////////
#define L10N // Localization complete.
#include <math.h>
#include <Context.h>
#include <ColMask.h>
#include <text.h>
#include <i18n.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
ColumnMask::ColumnMask ()
{
_name = "mask";
_type = "string";
_style = "default";
_label = STRING_COLUMN_LABEL_MASK;
_modifiable = false;
_styles.push_back ("default");
_examples.push_back ("++++---");
}
////////////////////////////////////////////////////////////////////////////////
ColumnMask::~ColumnMask ()
{
}
////////////////////////////////////////////////////////////////////////////////
bool ColumnMask::validate (std::string& value)
{
return true;
}
////////////////////////////////////////////////////////////////////////////////
// Set the minimum and maximum widths for the value.
void ColumnMask::measure (Task& task, int& minimum, int& maximum)
{
minimum = maximum = task.get ("mask").length ();
if (_style != "default")
throw format (STRING_COLUMN_BAD_FORMAT, _name, _style);
}
////////////////////////////////////////////////////////////////////////////////
void ColumnMask::render (
std::vector <std::string>& lines,
Task& task,
int width,
Color& color)
{
lines.push_back (color.colorize (task.get ("mask")));
}
////////////////////////////////////////////////////////////////////////////////

51
src/columns/ColMask.h Normal file
View file

@ -0,0 +1,51 @@
////////////////////////////////////////////////////////////////////////////////
// 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_COLMASK
#define INCLUDED_COLMASK
#define L10N // Localization complete.
#include <vector>
#include <string>
#include <Column.h>
#include <Color.h>
#include <Task.h>
class ColumnMask : public Column
{
public:
ColumnMask ();
~ColumnMask ();
bool validate (std::string&);
void measure (Task&, int&, int&);
void render (std::vector <std::string>&, Task&, int, Color&);
private:
};
#endif
////////////////////////////////////////////////////////////////////////////////

92
src/columns/ColParent.cpp Normal file
View file

@ -0,0 +1,92 @@
////////////////////////////////////////////////////////////////////////////////
// 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
//
////////////////////////////////////////////////////////////////////////////////
#define L10N // Localization complete.
#include <math.h>
#include <Context.h>
#include <ColParent.h>
#include <text.h>
#include <i18n.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
ColumnParent::ColumnParent ()
{
_name = "parent";
_type = "string";
_style = "long";
_label = STRING_COLUMN_LABEL_PARENT;
_modifiable = false;
_styles.push_back ("long");
_styles.push_back ("short");
_examples.push_back ("f30cb9c3-3fc0-483f-bfb2-3bf134f00694");
_examples.push_back ("34f00694");
}
////////////////////////////////////////////////////////////////////////////////
ColumnParent::~ColumnParent ()
{
}
////////////////////////////////////////////////////////////////////////////////
bool ColumnParent::validate (std::string& value)
{
return true;
}
////////////////////////////////////////////////////////////////////////////////
// Set the minimum and maximum widths for the value.
void ColumnParent::measure (Task&, int& minimum, int& maximum)
{
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 ColumnParent::render (
std::vector <std::string>& lines,
Task& task,
int width,
Color& color)
{
// f30cb9c3-3fc0-483f-bfb2-3bf134f00694 default
// 34f00694 short
if (_style == "default" ||
_style == "long")
lines.push_back (color.colorize (leftJustify (task.get (_name), width)));
else if (_style == "short")
lines.push_back (color.colorize (leftJustify (task.get (_name).substr (28), width)));
}
////////////////////////////////////////////////////////////////////////////////

51
src/columns/ColParent.h Normal file
View file

@ -0,0 +1,51 @@
////////////////////////////////////////////////////////////////////////////////
// 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_COLPARENT
#define INCLUDED_COLPARENT
#define L10N // Localization complete.
#include <vector>
#include <string>
#include <Column.h>
#include <Color.h>
#include <Task.h>
class ColumnParent : public Column
{
public:
ColumnParent ();
~ColumnParent ();
bool validate (std::string&);
void measure (Task&, int&, int&);
void render (std::vector <std::string>&, Task&, int, Color&);
private:
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -35,6 +35,9 @@
#include <ColEnd.h>
#include <ColEntry.h>
#include <ColID.h>
#include <ColIMask.h>
#include <ColMask.h>
#include <ColParent.h>
#include <ColPriority.h>
#include <ColProject.h>
#include <ColRecur.h>
@ -80,6 +83,9 @@ Column* Column::factory (const std::string& name, const std::string& report)
else if (column_name == "end") c = new ColumnEnd ();
else if (column_name == "entry") c = new ColumnEntry ();
else if (column_name == "id") c = new ColumnID ();
else if (column_name == "imask") c = new ColumnIMask ();
else if (column_name == "mask") c = new ColumnMask ();
else if (column_name == "parent") c = new ColumnParent ();
else if (column_name == "priority") c = new ColumnPriority ();
else if (column_name == "project") c = new ColumnProject ();
else if (column_name == "recur") c = new ColumnRecur ();
@ -113,6 +119,9 @@ void Column::factory (std::map <std::string, Column*>& all)
c = new ColumnEnd (); all[c->_name] = c;
c = new ColumnEntry (); all[c->_name] = c;
c = new ColumnID (); all[c->_name] = c;
c = new ColumnIMask (); all[c->_name] = c;
c = new ColumnMask (); all[c->_name] = c;
c = new ColumnParent (); all[c->_name] = c;
c = new ColumnPriority (); all[c->_name] = c;
c = new ColumnProject (); all[c->_name] = c;
c = new ColumnRecur (); all[c->_name] = c;

View file

@ -157,14 +157,6 @@ int CmdImport::execute (std::string& output)
task.setAnnotations (annos);
}
// These must be imported, but are not represented by Column
// objects.
else if (i->first == "mask" ||
i->first == "imask" ||
i->first == "parent")
{
task.set (i->first, unquoteText (i->second->dump ()));
}
else
throw std::string ("Unrecognized attribute '") + i->first + "'";
}