Task Refactoring
- Task is no longer a map of string to Att. Att is itself a name/ value pair, so the name was redundant. Task is now a map of string to string. This brings the obsoletion of Att much closer.
This commit is contained in:
@@ -86,19 +86,18 @@ int CmdDenotate::execute (std::string& output)
|
||||
{
|
||||
Task before (*task);
|
||||
|
||||
std::vector <Att> annotations;
|
||||
std::map <std::string, std::string> annotations;
|
||||
task->getAnnotations (annotations);
|
||||
|
||||
if (annotations.size () == 0)
|
||||
throw std::string (STRING_CMD_DENO_NONE);
|
||||
|
||||
std::vector <Att>::iterator i;
|
||||
std::map <std::string, std::string>::iterator i;
|
||||
std::string anno;
|
||||
bool match = false;
|
||||
for (i = annotations.begin (); i != annotations.end (); ++i)
|
||||
{
|
||||
anno = i->value ();
|
||||
if (anno == pattern)
|
||||
if (i->second == pattern)
|
||||
{
|
||||
match = true;
|
||||
annotations.erase (i);
|
||||
@@ -110,9 +109,7 @@ int CmdDenotate::execute (std::string& output)
|
||||
{
|
||||
for (i = annotations.begin (); i != annotations.end (); ++i)
|
||||
{
|
||||
anno = i->value ();
|
||||
std::string::size_type loc = find (anno, pattern, sensitive);
|
||||
|
||||
std::string::size_type loc = find (i->second, pattern, sensitive);
|
||||
if (loc != std::string::npos)
|
||||
{
|
||||
annotations.erase (i);
|
||||
|
||||
@@ -199,14 +199,14 @@ std::string CmdEdit::formatTask (Task task)
|
||||
<< "# The ' -- ' separator between the date and text field should not be removed.\n"
|
||||
<< "# A \"blank slot\" for adding an annotation follows for your convenience.\n";
|
||||
|
||||
std::vector <Att> annotations;
|
||||
std::map <std::string, std::string> annotations;
|
||||
task.getAnnotations (annotations);
|
||||
std::vector <Att>::iterator anno;
|
||||
std::map <std::string, std::string>::iterator anno;
|
||||
for (anno = annotations.begin (); anno != annotations.end (); ++anno)
|
||||
{
|
||||
Date dt (strtol (anno->name ().substr (11).c_str (), NULL, 10));
|
||||
Date dt (strtol (anno->first.substr (11).c_str (), NULL, 10));
|
||||
before << " Annotation: " << dt.toString (context.config.get ("dateformat.annotation"))
|
||||
<< " -- " << anno->value () << "\n";
|
||||
<< " -- " << anno->second << "\n";
|
||||
}
|
||||
|
||||
Date now;
|
||||
@@ -252,7 +252,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
|
||||
{
|
||||
if (value != "")
|
||||
{
|
||||
if (Att::validNameValue ("priority", "", value))
|
||||
if (context.columns["priority"]->validate (value))
|
||||
{
|
||||
context.footnote ("Priority modified.");
|
||||
task.set ("priority", value);
|
||||
@@ -541,7 +541,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
|
||||
}
|
||||
|
||||
// Annotations
|
||||
std::vector <Att> annotations;
|
||||
std::map <std::string, std::string> annotations;
|
||||
std::string::size_type found = 0;
|
||||
while ((found = after.find ("\n Annotation:", found)) != std::string::npos)
|
||||
{
|
||||
@@ -567,7 +567,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
|
||||
std::stringstream name;
|
||||
name << "annotation_" << when.toEpoch ();
|
||||
std::string text = trim (value.substr (gap + 4), "\t ");
|
||||
annotations.push_back (Att (name.str (), text));
|
||||
annotations.insert (std::make_pair (name.str (), text));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ int CmdImport::execute (std::string& output)
|
||||
// 'description' values and must be converted.
|
||||
if (i->first == "annotations")
|
||||
{
|
||||
std::vector <Att> annos;
|
||||
std::map <std::string, std::string> annos;
|
||||
|
||||
json::array* atts = (json::array*)i->second;
|
||||
json_array_iter annotations;
|
||||
@@ -151,7 +151,7 @@ int CmdImport::execute (std::string& output)
|
||||
|
||||
std::string name = "annotation_" + Date (when->_data).toEpochString ();
|
||||
|
||||
annos.push_back (Att (name, what->_data));
|
||||
annos.insert (std::make_pair (name, what->_data));
|
||||
}
|
||||
|
||||
task.setAnnotations (annos);
|
||||
@@ -336,14 +336,14 @@ void CmdImport::decorateTask (Task& task)
|
||||
std::string defaultPriority = context.config.get ("default.priority");
|
||||
if (!task.has ("priority") &&
|
||||
defaultPriority != "" &&
|
||||
Att::validNameValue ("priority", "", defaultPriority))
|
||||
context.columns["priority"]->validate (defaultPriority))
|
||||
task.set ("priority", defaultPriority);
|
||||
|
||||
// Override with default.due, if not specified.
|
||||
std::string defaultDue = context.config.get ("default.due");
|
||||
if (!task.has ("due") &&
|
||||
defaultDue != "" &&
|
||||
Att::validNameValue ("due", "", defaultDue))
|
||||
context.columns["due"]->validate (defaultDue))
|
||||
task.set ("due", defaultDue);
|
||||
}
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ int CmdStatistics::execute (std::string& output)
|
||||
|
||||
descLength += task->get ("description").length ();
|
||||
|
||||
std::vector <Att> annotations;
|
||||
std::map <std::string, std::string> annotations;
|
||||
task->getAnnotations (annotations);
|
||||
annotationsT += annotations.size ();
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
#include <E9.h>
|
||||
#include <Att.h>
|
||||
#include <Timer.h>
|
||||
#include <text.h>
|
||||
#include <i18n.h>
|
||||
|
||||
Reference in New Issue
Block a user