diff --git a/src/commands/CmdAnnotate.cpp b/src/commands/CmdAnnotate.cpp index 4c4412db4..57488d2a5 100644 --- a/src/commands/CmdAnnotate.cpp +++ b/src/commands/CmdAnnotate.cpp @@ -25,10 +25,14 @@ // //////////////////////////////////////////////////////////////////////////////// +#define L10N // Localization complete. + #include #include #include #include +#include +#include #include extern Context context; @@ -38,7 +42,7 @@ CmdAnnotate::CmdAnnotate () { _keyword = "annotate"; _usage = "task annotate ID desc..."; - _description = "Adds an annotation to an existing task."; + _description = STRING_CMD_ANNO_USAGE; _read_only = false; _displays_id = false; } @@ -47,63 +51,73 @@ CmdAnnotate::CmdAnnotate () int CmdAnnotate::execute (std::string& output) { int rc = 0; - -/* - if (!context.task.has ("description")) - throw std::string ("Cannot apply a blank annotation."); - - if (context.sequence.size () == 0) - throw std::string ("ID needed to apply an annotation."); - + int count = 0; std::stringstream out; std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); - Filter filter; - context.tdb.loadPending (tasks, filter); + context.tdb.loadPending (tasks); - // Filter sequence. - context.filter.applySequence (tasks, context.sequence); - if (tasks.size () == 0) + // Apply filter. + std::vector filtered; + filter (tasks, filtered); + + if (filtered.size () == 0) { - context.footnote ("No tasks specified."); + context.footnote (STRING_FEEDBACK_NO_TASKS_SP); return 1; } + // Apply the command line modifications to the completed task. + Arguments modifications = context.args.extract_modifications (); + if (!modifications.size ()) + throw std::string (STRING_CMD_XPEND_NEED_TEXT); + Permission permission; - if (context.sequence.size () > (size_t) context.config.getInteger ("bulk")) + if (filtered.size () > (size_t) context.config.getInteger ("bulk")) permission.bigSequence (); std::vector ::iterator task; - for (task = tasks.begin (); task != tasks.end (); ++task) + for (task = filtered.begin (); task != filtered.end (); ++task) { Task before (*task); - task->addAnnotation (context.task.get ("description")); + modify_task_annotate (*task, modifications); + apply_defaults (*task); + + // Only allow valid tasks. + task->validate (); if (taskDiff (before, *task)) { - // Only allow valid tasks. - task->validate (); - - if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?")) + if (permission.confirmed (before, + taskDifferences (before, *task) + + STRING_CMD_DONE_PROCEED)) { context.tdb.update (*task); + ++count; if (context.config.getBoolean ("echo.command")) - out << "Annotated " - << task->id - << " with '" - << context.task.get ("description") - << "'.\n"; + out << format (STRING_CMD_ANNO_DONE, + task->id, + task->get ("description")) + << "\n"; } } } - context.tdb.commit (); + if (count) + context.tdb.commit (); + context.tdb.unlock (); + if (context.config.getBoolean ("echo.command")) + out << format ((count == 1 + ? STRING_CMD_ANNO_SUMMARY + : STRING_CMD_ANNO_SUMMARY_N), + count) + << "\n"; + output = out.str (); -*/ return rc; } diff --git a/src/commands/CmdDone.cpp b/src/commands/CmdDone.cpp index 5e5ed0805..93c218124 100644 --- a/src/commands/CmdDone.cpp +++ b/src/commands/CmdDone.cpp @@ -103,6 +103,7 @@ int CmdDone::execute (std::string& output) if (permission.confirmed (before, taskDifferences (before, *task) + STRING_CMD_DONE_PROCEED)) { context.tdb.update (*task); + ++count; if (context.config.getBoolean ("echo.command")) out << format (STRING_CMD_DONE_COMPLETED, task->id, task->get ("description")) @@ -111,7 +112,6 @@ int CmdDone::execute (std::string& output) dependencyChainOnComplete (*task); context.footnote (onProjectChange (*task, false)); - ++count; } } diff --git a/src/en-US.h b/src/en-US.h index 6dc9f8a75..6cd0668bb 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -283,6 +283,10 @@ #define STRING_CMD_PREPEND_SUMMARY "Prepended {1} task." #define STRING_CMD_PREPEND_SUMMARY_N "Prepended {1} tasks." #define STRING_CMD_XPEND_NEED_TEXT "Additional text must be provided." +#define STRING_CMD_ANNO_USAGE "Adds an annotation to an existing task." +#define STRING_CMD_ANNO_DONE "Annotated {1} '{2}'" +#define STRING_CMD_ANNO_SUMMARY "Prepended {1} task." +#define STRING_CMD_ANNO_SUMMARY_N "Prepended {1} tasks." // Config #define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake."