mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Task: Improved method signature
This commit is contained in:
parent
cfc3e098c1
commit
5193f7d03e
10 changed files with 21 additions and 49 deletions
|
@ -300,8 +300,7 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
|
||||||
|
|
||||||
if (ref.data.size () && size == 3 && elements[0] == "annotations")
|
if (ref.data.size () && size == 3 && elements[0] == "annotations")
|
||||||
{
|
{
|
||||||
std::map <std::string, std::string> annos;
|
auto annos = ref.getAnnotations ();
|
||||||
ref.getAnnotations (annos);
|
|
||||||
|
|
||||||
int a = strtol (elements[1].c_str (), NULL, 10);
|
int a = strtol (elements[1].c_str (), NULL, 10);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
@ -329,8 +328,7 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
|
||||||
|
|
||||||
if (ref.data.size () && size == 4 && elements[0] == "annotations" && elements[2] == "entry")
|
if (ref.data.size () && size == 4 && elements[0] == "annotations" && elements[2] == "entry")
|
||||||
{
|
{
|
||||||
std::map <std::string, std::string> annos;
|
auto annos = ref.getAnnotations ();
|
||||||
ref.getAnnotations (annos);
|
|
||||||
|
|
||||||
int a = strtol (elements[1].c_str (), NULL, 10);
|
int a = strtol (elements[1].c_str (), NULL, 10);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
12
src/Task.cpp
12
src/Task.cpp
|
@ -1081,13 +1081,14 @@ void Task::removeAnnotations ()
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Task::getAnnotations (std::map <std::string, std::string>& annotations) const
|
std::map <std::string, std::string> Task::getAnnotations () const
|
||||||
{
|
{
|
||||||
annotations.clear ();
|
std::map <std::string, std::string> a;
|
||||||
|
|
||||||
for (auto& ann : data)
|
for (auto& ann : data)
|
||||||
if (! ann.first.compare (0, 11, "annotation_", 11))
|
if (! ann.first.compare (0, 11, "annotation_", 11))
|
||||||
annotations.insert (ann);
|
a.insert (ann);
|
||||||
|
|
||||||
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1357,8 +1358,7 @@ void Task::substitute (
|
||||||
|
|
||||||
// Get the data to modify.
|
// Get the data to modify.
|
||||||
std::string description = get ("description");
|
std::string description = get ("description");
|
||||||
std::map <std::string, std::string> annotations;
|
auto annotations = getAnnotations ();
|
||||||
getAnnotations (annotations);
|
|
||||||
|
|
||||||
// Count the changes, so we know whether to proceed to annotations, after
|
// Count the changes, so we know whether to proceed to annotations, after
|
||||||
// modifying description.
|
// modifying description.
|
||||||
|
|
|
@ -129,7 +129,7 @@ public:
|
||||||
void removeTag (const std::string&);
|
void removeTag (const std::string&);
|
||||||
|
|
||||||
bool hasAnnotations () const;
|
bool hasAnnotations () const;
|
||||||
void getAnnotations (std::map <std::string, std::string>&) const;
|
std::map <std::string, std::string> getAnnotations () const;
|
||||||
void setAnnotations (const std::map <std::string, std::string>&);
|
void setAnnotations (const std::map <std::string, std::string>&);
|
||||||
void addAnnotation (const std::string&);
|
void addAnnotation (const std::string&);
|
||||||
void removeAnnotations ();
|
void removeAnnotations ();
|
||||||
|
|
|
@ -874,10 +874,7 @@ bool Variant::operator_match (const Variant& other, const Task& task) const
|
||||||
// in the annotations.
|
// in the annotations.
|
||||||
if (left.source () == "description")
|
if (left.source () == "description")
|
||||||
{
|
{
|
||||||
std::map <std::string, std::string> annotations;
|
for (auto& a : task.getAnnotations ())
|
||||||
task.getAnnotations (annotations);
|
|
||||||
|
|
||||||
for (auto& a : annotations)
|
|
||||||
if (r.match (a.second))
|
if (r.match (a.second))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -909,10 +906,7 @@ bool Variant::operator_match (const Variant& other, const Task& task) const
|
||||||
// in the annotations.
|
// in the annotations.
|
||||||
if (left.source () == "description")
|
if (left.source () == "description")
|
||||||
{
|
{
|
||||||
std::map <std::string, std::string> annotations;
|
for (auto& a : task.getAnnotations ())
|
||||||
task.getAnnotations (annotations);
|
|
||||||
|
|
||||||
for (auto& a : annotations)
|
|
||||||
if (find (a.second, pattern, searchCaseSensitive) != std::string::npos)
|
if (find (a.second, pattern, searchCaseSensitive) != std::string::npos)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,9 +102,7 @@ void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int
|
||||||
if (min_anno > minimum)
|
if (min_anno > minimum)
|
||||||
minimum = min_anno;
|
minimum = min_anno;
|
||||||
|
|
||||||
std::map <std::string, std::string> annos;
|
for (auto& i : task.getAnnotations ())
|
||||||
task.getAnnotations (annos);
|
|
||||||
for (auto& i : annos)
|
|
||||||
{
|
{
|
||||||
unsigned int len = min_anno + 1 + utf8_width (i.second);
|
unsigned int len = min_anno + 1 + utf8_width (i.second);
|
||||||
if (len > maximum)
|
if (len > maximum)
|
||||||
|
@ -129,9 +127,7 @@ void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int
|
||||||
if (task.annotation_count)
|
if (task.annotation_count)
|
||||||
{
|
{
|
||||||
auto min_anno = Datetime::length (_dateformat);
|
auto min_anno = Datetime::length (_dateformat);
|
||||||
std::map <std::string, std::string> annos;
|
for (auto& i : task.getAnnotations ())
|
||||||
task.getAnnotations (annos);
|
|
||||||
for (auto& i : annos)
|
|
||||||
maximum += min_anno + 1 + utf8_width (i.second);
|
maximum += min_anno + 1 + utf8_width (i.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,9 +175,7 @@ void ColumnDescription::render (
|
||||||
{
|
{
|
||||||
if (task.annotation_count)
|
if (task.annotation_count)
|
||||||
{
|
{
|
||||||
std::map <std::string, std::string> annos;
|
for (const auto& i : task.getAnnotations ())
|
||||||
task.getAnnotations (annos);
|
|
||||||
for (const auto& i : annos)
|
|
||||||
{
|
{
|
||||||
Datetime dt (strtol (i.first.substr (11).c_str (), NULL, 10));
|
Datetime dt (strtol (i.first.substr (11).c_str (), NULL, 10));
|
||||||
description += '\n' + std::string (_indent, ' ') + dt.toString (_dateformat) + ' ' + i.second;
|
description += '\n' + std::string (_indent, ' ') + dt.toString (_dateformat) + ' ' + i.second;
|
||||||
|
@ -210,9 +204,7 @@ void ColumnDescription::render (
|
||||||
{
|
{
|
||||||
if (task.annotation_count)
|
if (task.annotation_count)
|
||||||
{
|
{
|
||||||
std::map <std::string, std::string> annos;
|
for (const auto& i : task.getAnnotations ())
|
||||||
task.getAnnotations (annos);
|
|
||||||
for (const auto& i : annos)
|
|
||||||
{
|
{
|
||||||
Datetime dt (strtol (i.first.substr (11).c_str (), NULL, 10));
|
Datetime dt (strtol (i.first.substr (11).c_str (), NULL, 10));
|
||||||
description += ' ' + dt.toString (_dateformat) + ' ' + i.second;
|
description += ' ' + dt.toString (_dateformat) + ' ' + i.second;
|
||||||
|
|
|
@ -90,8 +90,7 @@ int CmdDenotate::execute (std::string&)
|
||||||
{
|
{
|
||||||
Task before (task);
|
Task before (task);
|
||||||
|
|
||||||
std::map <std::string, std::string> annotations;
|
auto annotations = task.getAnnotations ();
|
||||||
task.getAnnotations (annotations);
|
|
||||||
|
|
||||||
if (annotations.size () == 0)
|
if (annotations.size () == 0)
|
||||||
throw std::string (STRING_CMD_DENO_NONE);
|
throw std::string (STRING_CMD_DENO_NONE);
|
||||||
|
|
|
@ -245,9 +245,7 @@ std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
|
||||||
<< "# " << STRING_EDIT_HEADER_14 << '\n'
|
<< "# " << STRING_EDIT_HEADER_14 << '\n'
|
||||||
<< "# " << STRING_EDIT_HEADER_15 << '\n';
|
<< "# " << STRING_EDIT_HEADER_15 << '\n';
|
||||||
|
|
||||||
std::map <std::string, std::string> annotations;
|
for (auto& anno : task.getAnnotations ())
|
||||||
task.getAnnotations (annotations);
|
|
||||||
for (auto& anno : annotations)
|
|
||||||
{
|
{
|
||||||
Datetime dt (strtol (anno.first.substr (11).c_str (), NULL, 10));
|
Datetime dt (strtol (anno.first.substr (11).c_str (), NULL, 10));
|
||||||
before << " Annotation: " << dt.toString (dateformat)
|
before << " Annotation: " << dt.toString (dateformat)
|
||||||
|
|
|
@ -134,9 +134,7 @@ int CmdInfo::execute (std::string& output)
|
||||||
std::string description = task.get ("description");
|
std::string description = task.get ("description");
|
||||||
int indent = context.config.getInteger ("indent.annotation");
|
int indent = context.config.getInteger ("indent.annotation");
|
||||||
|
|
||||||
std::map <std::string, std::string> annotations;
|
for (auto& anno : task.getAnnotations ())
|
||||||
task.getAnnotations (annotations);
|
|
||||||
for (auto& anno : annotations)
|
|
||||||
description += '\n'
|
description += '\n'
|
||||||
+ std::string (indent, ' ')
|
+ std::string (indent, ' ')
|
||||||
+ Datetime (anno.first.substr (11)).toString (dateformatanno)
|
+ Datetime (anno.first.substr (11)).toString (dateformatanno)
|
||||||
|
|
|
@ -140,10 +140,7 @@ int CmdStats::execute (std::string& output)
|
||||||
daysPending += (now.toEpoch () - entry) / 86400.0;
|
daysPending += (now.toEpoch () - entry) / 86400.0;
|
||||||
|
|
||||||
descLength += task.get ("description").length ();
|
descLength += task.get ("description").length ();
|
||||||
|
annotationsT += task.getAnnotations ().size ();
|
||||||
std::map <std::string, std::string> annotations;
|
|
||||||
task.getAnnotations (annotations);
|
|
||||||
annotationsT += annotations.size ();
|
|
||||||
|
|
||||||
auto tags = task.getTags ();
|
auto tags = task.getTags ();
|
||||||
if (tags.size ())
|
if (tags.size ())
|
||||||
|
|
|
@ -142,9 +142,7 @@ int CmdTimesheet::execute (std::string& output)
|
||||||
std::string description = task.get ("description");
|
std::string description = task.get ("description");
|
||||||
int indent = context.config.getInteger ("indent.annotation");
|
int indent = context.config.getInteger ("indent.annotation");
|
||||||
|
|
||||||
std::map <std::string, std::string> annotations;
|
for (auto& ann : task.getAnnotations ())
|
||||||
task.getAnnotations (annotations);
|
|
||||||
for (auto& ann : annotations)
|
|
||||||
description += '\n'
|
description += '\n'
|
||||||
+ std::string (indent, ' ')
|
+ std::string (indent, ' ')
|
||||||
+ Datetime (ann.first.substr (11)).toString (context.config.get ("dateformat"))
|
+ Datetime (ann.first.substr (11)).toString (context.config.get ("dateformat"))
|
||||||
|
@ -198,9 +196,7 @@ int CmdTimesheet::execute (std::string& output)
|
||||||
std::string description = task.get ("description");
|
std::string description = task.get ("description");
|
||||||
int indent = context.config.getInteger ("indent.annotation");
|
int indent = context.config.getInteger ("indent.annotation");
|
||||||
|
|
||||||
std::map <std::string, std::string> annotations;
|
for (auto& ann : task.getAnnotations ())
|
||||||
task.getAnnotations (annotations);
|
|
||||||
for (auto& ann : annotations)
|
|
||||||
description += '\n'
|
description += '\n'
|
||||||
+ std::string (indent, ' ')
|
+ std::string (indent, ' ')
|
||||||
+ Datetime (ann.first.substr (11)).toString (context.config.get ("dateformat"))
|
+ Datetime (ann.first.substr (11)).toString (context.config.get ("dateformat"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue