- Created legacy checking function to determine whether deprecated or obsolete
  attributes are being used.
This commit is contained in:
Paul Beckingham 2011-09-12 22:45:58 -04:00
parent fa22b98dc4
commit 02047a6e99
3 changed files with 62 additions and 42 deletions

View file

@ -36,6 +36,7 @@
#include <i18n.h> #include <i18n.h>
#include <Command.h> #include <Command.h>
#include <cmake.h> #include <cmake.h>
#include <main.h>
#include <CmdAdd.h> #include <CmdAdd.h>
#include <CmdAnnotate.h> #include <CmdAnnotate.h>
@ -431,56 +432,62 @@ void Command::modify_task (
Column* column = context.columns[name]; Column* column = context.columns[name];
// All values must be eval'd first. // All values must be eval'd first.
A3 fragment; A3 value_tokens;
fragment.capture (value); value_tokens.capture (value);
fragment = fragment.postfix (fragment.tokenize (fragment)); value_tokens = value_tokens.postfix (value_tokens.tokenize (value_tokens));
E9 e (fragment); E9 e (value_tokens);
std::string result = e.evalExpression (task); std::string result = e.evalExpression (task);
context.debug (std::string ("Eval '") + value + "' --> '" + result + "'"); context.debug (std::string ("Eval '") + value + "' --> '" + result + "'");
// Dependencies must be resolved to UUIDs. if (result == "")
if (name == "depends")
{ {
// Convert ID to UUID. task.remove (name);
std::vector <std::string> deps;
split (deps, result, ',');
// Apply or remove dendencies in turn.
std::vector <std::string>::iterator i;
for (i = deps.begin (); i != deps.end (); i++)
{
int id = strtol (i->c_str (), NULL, 10);
if (id < 0)
task.removeDependency (-id);
else
task.addDependency (id);
}
} }
// Dates are special, maybe.
else if (column->type () == "date")
{
// If the date value is less than 5 years, it is a duration, not a
// date, therefore add 'now'.
long l = strtol (result.c_str (), NULL, 10);
if (labs (l) < 5 * 365 * 86400)
{
Date now;
now += l;
task.set (name, now.toEpochString ());
}
else
task.set (name, result);
}
// By default, just add it.
else else
task.set (name, result); {
// Dependencies must be resolved to UUIDs.
if (name == "depends")
{
// Convert ID to UUID.
std::vector <std::string> deps;
split (deps, result, ',');
// Legacy checks. // Apply or remove dendencies in turn.
if (name == "fg" || name == "bg") std::vector <std::string>::iterator i;
context.footnote (format (STRING_LEGACY_FEATURE, name)); for (i = deps.begin (); i != deps.end (); i++)
{
int id = strtol (i->c_str (), NULL, 10);
if (id < 0)
task.removeDependency (-id);
else
task.addDependency (id);
}
}
// Dates are special, maybe.
else if (column->type () == "date")
{
// If the date value is less than 5 years, it is a duration, not a
// date, therefore add 'now'.
long l = strtol (result.c_str (), NULL, 10);
if (labs (l) < 5 * 365 * 86400)
{
Date now;
now += l;
task.set (name, now.toEpochString ());
}
else
task.set (name, result);
}
// By default, just add/remove it.
else
task.set (name, result);
// Warn about deprecated/obsolete attribute usage.
legacyAttributeCheck (name);
}
} }
else else
throw format (STRING_CMD_ADD_BAD_ATTRIBUTE, name); throw format (STRING_CMD_ADD_BAD_ATTRIBUTE, name);

View file

@ -25,11 +25,21 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#define L10N // Localization complete.
#include <Context.h> #include <Context.h>
#include <text.h>
#include <i18n.h>
extern Context context; extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void legacyAttributeCheck (const std::string& name)
{
// Legacy checks.
if (name == "fg" || name == "bg")
context.footnote (format (STRING_LEGACY_FEATURE, name));
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -78,6 +78,9 @@ std::string feedback (const Task&, const Task&);
// sort.cpp // sort.cpp
void sort_tasks (std::vector <Task>&, std::vector <int>&, const std::string&); void sort_tasks (std::vector <Task>&, std::vector <int>&, const std::string&);
// legacy.cpp
void legacyAttributeCheck (const std::string&);
// list template // list template
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <class T> bool listDiff (const T& left, const T& right) template <class T> bool listDiff (const T& left, const T& right)