From 330b148ca9d6b3df166939b65e4d477afd9518a5 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 28 May 2011 14:34:06 -0400 Subject: [PATCH] Commands - _tags - Migrated handleCompletionTags to CmdTags. --- src/Cmd.cpp | 2 -- src/Context.cpp | 1 - src/command.cpp | 43 ------------------------------ src/commands/CmdTags.cpp | 56 ++++++++++++++++++++++++++++++++++++++++ src/commands/CmdTags.h | 7 +++++ src/commands/Command.cpp | 1 + src/main.h | 1 - 7 files changed, 64 insertions(+), 47 deletions(-) diff --git a/src/Cmd.cpp b/src/Cmd.cpp index eba754455..b59bbdddc 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -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 & all) const bool Cmd::isReadOnlyCommand () { if (command == "_projects" || - command == "_tags" || command == "_commands" || command == "_ids" || command == "_config" || diff --git a/src/Context.cpp b/src/Context.cpp index 6df27fcb5..c6b46dbe9 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -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); } diff --git a/src/command.cpp b/src/command.cpp index 372f81c1d..f6b41cc59 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -331,49 +331,6 @@ int handleCompletionProjects (std::string& outs) return 0; } -//////////////////////////////////////////////////////////////////////////////// -int handleCompletionTags (std::string& outs) -{ - std::vector 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 unique; - foreach (t, tasks) - { - std::vector 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) { diff --git a/src/commands/CmdTags.cpp b/src/commands/CmdTags.cpp index a600849e7..06dd0a428 100644 --- a/src/commands/CmdTags.cpp +++ b/src/commands/CmdTags.cpp @@ -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 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 unique; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + { + std::vector tags; + task->getTags (tags); + + std::vector ::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 ::iterator it; + for (it = unique.begin (); it != unique.end (); ++it) + out << it->first << "\n"; + + output = out.str (); + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdTags.h b/src/commands/CmdTags.h index e7b7fe276..e2f8953ed 100644 --- a/src/commands/CmdTags.h +++ b/src/commands/CmdTags.h @@ -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 //////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 8d011cfe5..ca207051c 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -51,6 +51,7 @@ void Command::factory (std::map & 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; diff --git a/src/main.h b/src/main.h index 4aefcdc44..1bbd1f97a 100644 --- a/src/main.h +++ b/src/main.h @@ -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&);