mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
ColTypeNumeric: Migrated part of Task::modify to ::modify
This commit is contained in:
parent
b7a72c5252
commit
7525d4a921
1 changed files with 35 additions and 1 deletions
|
@ -26,6 +26,16 @@
|
|||
|
||||
#include <cmake.h>
|
||||
#include <ColTypeNumeric.h>
|
||||
#include <Context.h>
|
||||
#include <Eval.h>
|
||||
#include <Variant.h>
|
||||
#include <Filter.h>
|
||||
#include <Dates.h>
|
||||
#include <text.h>
|
||||
#include <i18n.h>
|
||||
|
||||
extern Context context;
|
||||
extern Task& contextTask;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
ColumnTypeNumeric::ColumnTypeNumeric ()
|
||||
|
@ -51,7 +61,31 @@ void ColumnTypeNumeric::render (
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
void ColumnTypeNumeric::modify (Task& task, const std::string& value)
|
||||
{
|
||||
task.set (_name, value);
|
||||
// Try to evaluate 'value'. It might work.
|
||||
Variant evaluatedValue;
|
||||
try
|
||||
{
|
||||
Eval e;
|
||||
e.addSource (domSource);
|
||||
e.addSource (namedDates);
|
||||
contextTask = task;
|
||||
e.evaluateInfixExpression (value, evaluatedValue);
|
||||
}
|
||||
|
||||
catch (...)
|
||||
{
|
||||
evaluatedValue = Variant (value);
|
||||
}
|
||||
|
||||
std::string label = " [1;37;43mMODIFICATION[0m ";
|
||||
context.debug (label + _name + " <-- '" + evaluatedValue.get_string () + "' <-- '" + value + "'");
|
||||
|
||||
// If the result is not readily convertible to a numeric value,
|
||||
// then this is an error.
|
||||
if (evaluatedValue.type () == Variant::type_string)
|
||||
throw format (STRING_UDA_NUMERIC, evaluatedValue.get_string ());
|
||||
|
||||
task.set (_name, evaluatedValue);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue