mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-20 22:33:08 +02:00
Enhancement - filter on annotation
- Description filters now automatically apply to annotations.
This commit is contained in:
parent
245339e7fc
commit
343c43a010
3 changed files with 57 additions and 15 deletions
14
src/Att.cpp
14
src/Att.cpp
|
@ -478,6 +478,13 @@ bool Att::match (const Att& other) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// has = contains as a substring.
|
||||||
|
else if (mMod == "has" || mMod == "contains") // TODO i18n
|
||||||
|
{
|
||||||
|
if (other.mValue.find (mValue) == std::string::npos)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// is = equal. Nop.
|
// is = equal. Nop.
|
||||||
else if (mMod == "is" || mMod == "equals") // TODO i18n
|
else if (mMod == "is" || mMod == "equals") // TODO i18n
|
||||||
{
|
{
|
||||||
|
@ -528,13 +535,6 @@ bool Att::match (const Att& other) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// has = contains as a substring.
|
|
||||||
else if (mMod == "has" || mMod == "contains") // TODO i18n
|
|
||||||
{
|
|
||||||
if (other.mValue.find (mValue) == std::string::npos)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// hasnt = does not contain as a substring.
|
// hasnt = does not contain as a substring.
|
||||||
else if (mMod == "hasnt") // TODO i18n
|
else if (mMod == "hasnt") // TODO i18n
|
||||||
{
|
{
|
||||||
|
|
|
@ -573,6 +573,11 @@ void Context::autoFilter (Task& t, Filter& f)
|
||||||
{
|
{
|
||||||
f.push_back (Att ("description", "has", *word));
|
f.push_back (Att ("description", "has", *word));
|
||||||
debug ("auto filter: " + att->first + ".has:" + *word);
|
debug ("auto filter: " + att->first + ".has:" + *word);
|
||||||
|
|
||||||
|
/*
|
||||||
|
f.push_back (Att ("annotation_*", "has", *word));
|
||||||
|
debug ("auto filter: annotation_*.has:" + *word);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,19 +38,56 @@ bool Filter::pass (const Record& record) const
|
||||||
{
|
{
|
||||||
Record::const_iterator r;
|
Record::const_iterator r;
|
||||||
|
|
||||||
// If record doesn't have the attribute, fail. If it does have the attribute
|
// First do description/annotation matches.
|
||||||
// but it doesn't match, fail.
|
|
||||||
foreach (att, (*this))
|
foreach (att, (*this))
|
||||||
{
|
{
|
||||||
// If the record doesn't have the attribute, match against a default one.
|
// Descriptions have special handling.
|
||||||
// This is because "att" may contain a modifier like "name.not:X".
|
if (att->name () == "description")
|
||||||
if ((r = record.find (att->name ())) == record.end ())
|
|
||||||
{
|
{
|
||||||
if (! att->match (Att ()))
|
if ((r = record.find (att->name ())) != record.end ())
|
||||||
|
{
|
||||||
|
// A description match failure can be salvaged by an annotation match.
|
||||||
|
if (! att->match (r->second))
|
||||||
|
{
|
||||||
|
bool annoMatch = false;
|
||||||
|
foreach (ra, record)
|
||||||
|
{
|
||||||
|
if (ra->first.length () > 11 &&
|
||||||
|
ra->first.substr (0, 11) == "annotation_")
|
||||||
|
{
|
||||||
|
if (att->match (ra->second))
|
||||||
|
{
|
||||||
|
annoMatch = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!annoMatch)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (! att->match (Att ()))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Annotations are skipped.
|
||||||
|
else if (att->name ().length () > 11 &&
|
||||||
|
att->name ().substr (0, 11) == "annotation_")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// An individual attribute match failure is enough to fail the filter.
|
||||||
|
if ((r = record.find (att->name ())) != record.end ())
|
||||||
|
{
|
||||||
|
if (! att->match (r->second))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (! att->match (Att ()))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (! att->match (r->second))
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue