Commands - _tags

- Migrated handleCompletionTags to CmdTags.
This commit is contained in:
Paul Beckingham 2011-05-28 14:34:06 -04:00
parent b075f1252c
commit 330b148ca9
7 changed files with 64 additions and 47 deletions

View file

@ -130,7 +130,6 @@ void Cmd::load ()
if (commands.size () == 0)
{
commands.push_back ("_projects");
commands.push_back ("_tags");
commands.push_back ("_commands");
commands.push_back ("_ids");
commands.push_back ("_config");
@ -230,7 +229,6 @@ void Cmd::allCommands (std::vector <std::string>& all) const
bool Cmd::isReadOnlyCommand ()
{
if (command == "_projects" ||
command == "_tags" ||
command == "_commands" ||
command == "_ids" ||
command == "_config" ||

View file

@ -284,7 +284,6 @@ int Context::dispatch (std::string &out)
else if (cmd.command == "count") { rc = handleCount (out); }
else if (cmd.command == "ids") { rc = handleIds (out); }
else if (cmd.command == "_projects") { rc = handleCompletionProjects (out); }
else if (cmd.command == "_tags") { rc = handleCompletionTags (out); }
else if (cmd.command == "_commands") { rc = handleCompletionCommands (out); }
else if (cmd.command == "_ids") { rc = handleCompletionIDs (out); }
else if (cmd.command == "_config") { rc = handleCompletionConfig (out); }

View file

@ -331,49 +331,6 @@ int handleCompletionProjects (std::string& outs)
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int handleCompletionTags (std::string& outs)
{
std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter;
if (context.config.getBoolean ("complete.all.tags"))
context.tdb.load (tasks, filter);
else
context.tdb.loadPending (tasks, filter);
context.tdb.commit ();
context.tdb.unlock ();
// Scan all the tasks for their tags, building a map using tag
// names as keys.
std::map <std::string, int> unique;
foreach (t, tasks)
{
std::vector <std::string> tags;
t->getTags (tags);
foreach (tag, tags)
unique[*tag] = 0;
}
// add built-in tags to map
unique["nocolor"] = 0;
unique["nonag"] = 0;
unique["nocal"] = 0;
unique["next"] = 0;
unique["stall"] = 0;
unique["someday"] = 0;
std::stringstream out;
foreach (tag, unique)
out << tag->first << "\n";
outs = out.str ();
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int handleCompletionCommands (std::string& outs)
{

View file

@ -121,3 +121,59 @@ int CmdTags::execute (const std::string& command_line, std::string& output)
}
////////////////////////////////////////////////////////////////////////////////
CmdCompletionTags::CmdCompletionTags ()
{
_keyword = "_tags";
_usage = "task _tags";
_description = "Shows only a list of all tags used.";
_read_only = true;
_displays_id = false;
}
////////////////////////////////////////////////////////////////////////////////
int CmdCompletionTags::execute (const std::string& command_line, std::string& output)
{
std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter;
if (context.config.getBoolean ("complete.all.tags"))
context.tdb.load (tasks, filter);
else
context.tdb.loadPending (tasks, filter);
context.tdb.commit ();
context.tdb.unlock ();
// Scan all the tasks for their tags, building a map using tag
// names as keys.
std::map <std::string, int> unique;
std::vector <Task>::iterator task;
for (task = tasks.begin (); task != tasks.end (); ++task)
{
std::vector <std::string> tags;
task->getTags (tags);
std::vector <std::string>::iterator tag;
for (tag = tags.begin (); tag != tags.end (); ++tag)
unique[*tag] = 0;
}
// add built-in tags to map
unique["nocolor"] = 0;
unique["nonag"] = 0;
unique["nocal"] = 0;
unique["next"] = 0;
unique["stall"] = 0;
unique["someday"] = 0;
std::stringstream out;
std::map <std::string, int>::iterator it;
for (it = unique.begin (); it != unique.end (); ++it)
out << it->first << "\n";
output = out.str ();
return 0;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -38,5 +38,12 @@ public:
int execute (const std::string&, std::string&);
};
class CmdCompletionTags : public Command
{
public:
CmdCompletionTags ();
int execute (const std::string&, std::string&);
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -51,6 +51,7 @@ void Command::factory (std::map <std::string, Command*>& all)
{
Command* c;
c = new CmdCompletionTags (); all[c->keyword ()] = c;
c = new CmdCompletionVersion (); all[c->keyword ()] = c;
c = new CmdDiagnostics (); all[c->keyword ()] = c;
c = new CmdEdit (); all[c->keyword ()] = c;

View file

@ -58,7 +58,6 @@ int handleDone (std::string&);
int handleModify (std::string&);
int handleProjects (std::string&);
int handleCompletionProjects (std::string&);
int handleCompletionTags (std::string&);
int handleCompletionCommands (std::string&);
int handleCompletionIDs (std::string&);
int handleCompletionConfig (std::string&);