mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
ColRecur: Added ::modify
This commit is contained in:
parent
f0b9ceb17b
commit
fec65a0f24
2 changed files with 39 additions and 0 deletions
|
@ -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 = " [1;37;43mMODIFICATION[0m ";
|
||||
context.debug (label + _name + " <-- '" + value + "'");
|
||||
task.set (_name, value);
|
||||
}
|
||||
else
|
||||
throw format (STRING_TASK_INVALID_DUR, value);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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:
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue