mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-29 17:07:19 +02:00
UDAs - User Defined Attributes
- Added support for named allowable values.
This commit is contained in:
parent
0d3f6f990d
commit
7f1d8c3682
5 changed files with 34 additions and 2 deletions
|
@ -57,6 +57,23 @@ ColumnUDA::~ColumnUDA ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool ColumnUDA::validate (std::string& value)
|
||||||
|
{
|
||||||
|
// No restrictions.
|
||||||
|
if (_values.size () == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Look for exact match value.
|
||||||
|
std::vector <std::string>::iterator i;
|
||||||
|
for (i = _values.begin (); i != _values.end (); ++i)
|
||||||
|
if (*i == value)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Fail if not found.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Set the minimum and maximum widths for the value.
|
// Set the minimum and maximum widths for the value.
|
||||||
//
|
//
|
||||||
|
|
|
@ -41,9 +41,13 @@ public:
|
||||||
ColumnUDA ();
|
ColumnUDA ();
|
||||||
~ColumnUDA ();
|
~ColumnUDA ();
|
||||||
|
|
||||||
|
bool validate (std::string&);
|
||||||
void measure (Task&, int&, int&);
|
void measure (Task&, int&, int&);
|
||||||
void render (std::vector <std::string>&, Task&, int, Color&);
|
void render (std::vector <std::string>&, Task&, int, Color&);
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::vector <std::string> _values;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _hyphenate;
|
bool _hyphenate;
|
||||||
};
|
};
|
||||||
|
|
|
@ -181,7 +181,7 @@ void Column::uda (std::map <std::string, Column*>& all)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Column* Column::uda (const std::string& name)
|
Column* Column::uda (const std::string& name)
|
||||||
{
|
{
|
||||||
Column* c = new ColumnUDA ();
|
ColumnUDA* c = new ColumnUDA ();
|
||||||
c->_name = name;
|
c->_name = name;
|
||||||
|
|
||||||
std::string key = "uda." + name + ".type";
|
std::string key = "uda." + name + ".type";
|
||||||
|
@ -195,6 +195,11 @@ Column* Column::uda (const std::string& name)
|
||||||
key = "uda." + name + ".label";
|
key = "uda." + name + ".label";
|
||||||
if (context.config.get (key) != "")
|
if (context.config.get (key) != "")
|
||||||
c->_label = context.config.get (key);
|
c->_label = context.config.get (key);
|
||||||
|
|
||||||
|
key = "uda." + name + ".values";
|
||||||
|
if (context.config.get (key) != "")
|
||||||
|
split (c->_values, context.config.get (key), ',');
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -596,7 +596,12 @@ void Command::modify_task (
|
||||||
|
|
||||||
// By default, just add/remove it.
|
// By default, just add/remove it.
|
||||||
else
|
else
|
||||||
task.set (name, value);
|
{
|
||||||
|
if (column->validate (value))
|
||||||
|
task.set (name, value);
|
||||||
|
else
|
||||||
|
throw format (STRING_INVALID_MOD, name, value);
|
||||||
|
}
|
||||||
|
|
||||||
// Warn about deprecated/obsolete attribute usage.
|
// Warn about deprecated/obsolete attribute usage.
|
||||||
legacyAttributeCheck (name);
|
legacyAttributeCheck (name);
|
||||||
|
|
|
@ -683,6 +683,7 @@
|
||||||
#define STRING_INFINITE_LOOP "Terminated substitution because more than {1} changes were made - infinite loop protection."
|
#define STRING_INFINITE_LOOP "Terminated substitution because more than {1} changes were made - infinite loop protection."
|
||||||
#define STRING_UDA_TYPE "User defined attributes may only be of type 'string', 'date', 'duration' or 'numeric'."
|
#define STRING_UDA_TYPE "User defined attributes may only be of type 'string', 'date', 'duration' or 'numeric'."
|
||||||
#define STRING_UDA_NUMERIC "The value '{1}' is not a valid numeric value."
|
#define STRING_UDA_NUMERIC "The value '{1}' is not a valid numeric value."
|
||||||
|
#define STRING_INVALID_MOD "The '{1}' attribute does not allow a value of '{2}'."
|
||||||
|
|
||||||
// Feedback
|
// Feedback
|
||||||
#define STRING_FEEDBACK_NO_TASKS "No tasks."
|
#define STRING_FEEDBACK_NO_TASKS "No tasks."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue