Enhancement - completion

- Implemented _projects and _tags reports to assist with tab
  completion scripts.
This commit is contained in:
Paul Beckingham 2009-07-02 20:10:36 -04:00
parent 8145b7b28e
commit 73378dd67e
4 changed files with 90 additions and 27 deletions

View file

@ -106,6 +106,8 @@ void Cmd::load ()
{
if (commands.size () == 0)
{
commands.push_back ("_projects");
commands.push_back ("_tags");
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"));
@ -182,7 +184,9 @@ void Cmd::allCustomReports (std::vector <std::string>& all) const
// Commands that do not directly modify the data files.
bool Cmd::isReadOnlyCommand ()
{
if (command == context.stringtable.get (CMD_CALENDAR, "calendar") ||
if (command == "_projects" ||
command == "_tags" ||
command == context.stringtable.get (CMD_CALENDAR, "calendar") ||
command == context.stringtable.get (CMD_COLORS, "colors") ||
command == context.stringtable.get (CMD_EXPORT, "export") ||
command == context.stringtable.get (CMD_HELP, "help") ||

View file

@ -196,6 +196,8 @@ std::string Context::dispatch ()
else if (cmd.command == "shell") { handleShell (); }
#endif
else if (cmd.command == "undo") { handleUndo (); }
else if (cmd.command == "_projects") { out = handleCompletionProjects (); }
else if (cmd.command == "_tags") { out = handleCompletionTags (); }
else if (cmd.command == "" &&
sequence.size ()) { out = handleModify (); }

View file

@ -193,6 +193,31 @@ std::string handleProjects ()
return out.str ();
}
////////////////////////////////////////////////////////////////////////////////
std::string handleCompletionProjects ()
{
std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true));
handleRecurrence ();
Filter filter;
context.tdb.loadPending (tasks, filter);
context.tdb.commit ();
context.tdb.unlock ();
// Scan all the tasks for their project name, building a map using project
// names as keys.
std::map <std::string, int> unique;
foreach (t, tasks)
unique[t->get ("project")] = 0;
std::stringstream out;
foreach (project, unique)
if (project->first.length ())
out << project->first << std::endl;
return out.str ();
}
////////////////////////////////////////////////////////////////////////////////
std::string handleTags ()
{
@ -260,6 +285,36 @@ std::string handleTags ()
return out.str ();
}
////////////////////////////////////////////////////////////////////////////////
std::string handleCompletionTags ()
{
std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true));
handleRecurrence ();
Filter filter;
context.tdb.loadPending (tasks, filter);
context.tdb.commit ();
context.tdb.unlock ();
// Scan all the tasks for their project name, building a map using project
// 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;
}
std::stringstream out;
foreach (tag, unique)
out << tag->first << std::endl;
return out.str ();
}
////////////////////////////////////////////////////////////////////////////////
void handleUndo ()
{

View file

@ -60,7 +60,9 @@ std::string handleExport ();
std::string handleDone ();
std::string handleModify ();
std::string handleProjects ();
std::string handleCompletionProjects ();
std::string handleTags ();
std::string handleCompletionTags ();
std::string handleVersion ();
std::string handleDelete ();
std::string handleStart ();