From ca4bae558db14a5dc682155c54efae3ee00b1da2 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 4 Jul 2009 10:28:55 -0400 Subject: [PATCH] Enhancement - Added new _ids command to support tab completion scripts. --- src/Cmd.cpp | 2 ++ src/Context.cpp | 1 + src/command.cpp | 26 ++++++++++++++++++++++++++ src/main.h | 1 + 4 files changed, 30 insertions(+) diff --git a/src/Cmd.cpp b/src/Cmd.cpp index abadc60e1..9e7d13d03 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -109,6 +109,7 @@ void Cmd::load () commands.push_back ("_projects"); commands.push_back ("_tags"); commands.push_back ("_commands"); + commands.push_back ("_ids"); commands.push_back (context.stringtable.get (CMD_ADD, "add")); commands.push_back (context.stringtable.get (CMD_APPEND, "append")); commands.push_back (context.stringtable.get (CMD_ANNOTATE, "annotate")); @@ -197,6 +198,7 @@ bool Cmd::isReadOnlyCommand () if (command == "_projects" || command == "_tags" || command == "_commands" || + command == "_ids" || command == context.stringtable.get (CMD_CALENDAR, "calendar") || command == context.stringtable.get (CMD_COLORS, "colors") || command == context.stringtable.get (CMD_EXPORT, "export") || diff --git a/src/Context.cpp b/src/Context.cpp index a779ba8ec..4ea02a7ea 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -199,6 +199,7 @@ std::string Context::dispatch () else if (cmd.command == "_projects") { out = handleCompletionProjects (); } else if (cmd.command == "_tags") { out = handleCompletionTags (); } else if (cmd.command == "_commands") { out = handleCompletionCommands (); } + else if (cmd.command == "_ids") { out = handleCompletionIDs (); } else if (cmd.command == "" && sequence.size ()) { out = handleModify (); } diff --git a/src/command.cpp b/src/command.cpp index ae21ba633..23210c28d 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -330,6 +330,32 @@ std::string handleCompletionCommands () return out.str (); } +//////////////////////////////////////////////////////////////////////////////// +std::string handleCompletionIDs () +{ + std::vector tasks; + context.tdb.lock (context.config.get ("locking", true)); + handleRecurrence (); + Filter filter; + context.tdb.loadPending (tasks, filter); + context.tdb.commit (); + context.tdb.unlock (); + + std::vector ids; + foreach (task, tasks) + if (task->getStatus () != Task::deleted && + task->getStatus () != Task::completed) + ids.push_back (task->id); + + std::sort (ids.begin (), ids.end ()); + + std::stringstream out; + foreach (id, ids) + out << *id << std::endl; + + return out.str (); +} + //////////////////////////////////////////////////////////////////////////////// void handleUndo () { diff --git a/src/main.h b/src/main.h index 95a98a710..a5374a460 100644 --- a/src/main.h +++ b/src/main.h @@ -64,6 +64,7 @@ std::string handleCompletionProjects (); std::string handleTags (); std::string handleCompletionTags (); std::string handleCompletionCommands (); +std::string handleCompletionIDs (); std::string handleVersion (); std::string handleDelete (); std::string handleStart ();