ColRecur: Added ::modify

This commit is contained in:
Paul Beckingham 2016-01-31 19:27:54 -05:00
parent f0b9ceb17b
commit fec65a0f24
2 changed files with 39 additions and 0 deletions

View file

@ -28,11 +28,17 @@
#include <ColRecur.h>
#include <Context.h>
#include <ISO8601.h>
#include <Eval.h>
#include <Variant.h>
#include <Lexer.h>
#include <Filter.h>
#include <Dates.h>
#include <text.h>
#include <utf8.h>
#include <i18n.h>
extern Context context;
extern Task& contextTask;
////////////////////////////////////////////////////////////////////////////////
ColumnRecur::ColumnRecur ()
@ -99,3 +105,35 @@ void ColumnRecur::render (
}
////////////////////////////////////////////////////////////////////////////////
// The duration is stored in raw form, but it must still be valid,
// and therefore is parsed first.
void ColumnRecur::modify (Task& task, const std::string& 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);
}
if (evaluatedValue.type () == Variant::type_duration)
{
// Store the raw value, for 'recur'.
std::string label = " MODIFICATION ";
context.debug (label + _name + " <-- '" + value + "'");
task.set (_name, value);
}
else
throw format (STRING_TASK_INVALID_DUR, value);
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -38,6 +38,7 @@ public:
void setStyle (const std::string&);
void measure (Task&, unsigned int&, unsigned int&);
void render (std::vector <std::string>&, Task&, int, Color&);
void modify (Task&, const std::string&);
private:
};