diff --git a/src/commands/CmdAppend.cpp b/src/commands/CmdAppend.cpp index c09d607c4..988ee6e75 100644 --- a/src/commands/CmdAppend.cpp +++ b/src/commands/CmdAppend.cpp @@ -25,10 +25,14 @@ // //////////////////////////////////////////////////////////////////////////////// +#define L10N // Localization complete. + #include #include #include #include +#include +#include #include extern Context context; @@ -37,8 +41,8 @@ extern Context context; CmdAppend::CmdAppend () { _keyword = "append"; - _usage = "task append [tags] [attrs] desc..."; - _description = "Append more description to an existing task."; + _usage = "task append "; + _description = STRING_CMD_APPEND_USAGE; _read_only = false; _displays_id = false; } @@ -46,39 +50,41 @@ CmdAppend::CmdAppend () //////////////////////////////////////////////////////////////////////////////// int CmdAppend::execute (std::string& output) { -/* - if (!context.task.has ("description")) - throw std::string ("Additional text must be provided."); -*/ - int rc = 0; -/* 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. - std::vector all = tasks; - 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 started 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) { + modify_task_description_append (*task, modifications); + apply_defaults (*task); + std::vector ::iterator other; - for (other = all.begin (); other != all.end (); ++other) + for (other = tasks.begin (); other != tasks.end (); ++other) { if (other->id == task->id || // Self (task->has ("parent") && @@ -91,10 +97,9 @@ int CmdAppend::execute (std::string& output) int changes = 0; // Apply other deltas. - changes += deltaAppend (*other); - changes += deltaTags (*other); - changes += deltaAttributes (*other); - changes += deltaSubstitutions (*other); + modify_task_description_append (*other, modifications); + apply_defaults (*other); + ++changes; if (taskDiff (before, *other)) { @@ -106,11 +111,8 @@ int CmdAppend::execute (std::string& output) context.tdb.update (*other); if (context.config.getBoolean ("echo.command")) - out << "Appended '" - << context.task.get ("description") - << "' to task " - << other->id - << ".\n"; + out << format (STRING_CMD_APPEND_DONE, other->id) + << "\n"; if (before.get ("project") != other->get ("project")) context.footnote (onProjectChange (before, *other)); @@ -126,10 +128,13 @@ int CmdAppend::execute (std::string& output) context.tdb.unlock (); if (context.config.getBoolean ("echo.command")) - out << "Appended " << count << " task" << (count == 1 ? ".\n" : "s.\n"); + out << format ((count == 1 + ? STRING_CMD_APPEND_SUMMARY + : STRING_CMD_APPEND_SUMMARY_N), + count) + << "\n"; output = out.str (); -*/ return rc; } diff --git a/src/commands/CmdDelete.cpp b/src/commands/CmdDelete.cpp index 6161c1f63..dcae03c30 100644 --- a/src/commands/CmdDelete.cpp +++ b/src/commands/CmdDelete.cpp @@ -72,10 +72,6 @@ int CmdDelete::execute (std::string& output) // Apply the command line modifications to the new task. Arguments modifications = context.args.extract_modifications (); - // Determine the end date. - char endTime[16]; - sprintf (endTime, "%u", (unsigned int) time (NULL)); - std::vector ::iterator task; for (task = filtered.begin (); task != filtered.end (); ++task) { diff --git a/src/commands/CmdPrepend.cpp b/src/commands/CmdPrepend.cpp index 06b8301c8..c4e204b58 100644 --- a/src/commands/CmdPrepend.cpp +++ b/src/commands/CmdPrepend.cpp @@ -25,10 +25,14 @@ // //////////////////////////////////////////////////////////////////////////////// +#define L10N // Localization complete. + #include #include #include #include +#include +#include #include extern Context context; @@ -37,8 +41,8 @@ extern Context context; CmdPrepend::CmdPrepend () { _keyword = "prepend"; - _usage = "task prepend [tags] [attrs] desc..."; - _description = "Prepends more description to an existing task."; + _usage = "task prepend "; + _description = STRING_CMD_PREPEND_USAGE; _read_only = false; _displays_id = false; } @@ -46,39 +50,41 @@ CmdPrepend::CmdPrepend () //////////////////////////////////////////////////////////////////////////////// int CmdPrepend::execute (std::string& output) { -/* - if (!context.task.has ("description")) - throw std::string ("Additional text must be provided."); -*/ - int rc = 0; -/* 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. - std::vector all = tasks; - 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 started 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) { + modify_task_description_prepend (*task, modifications); + apply_defaults (*task); + std::vector ::iterator other; - for (other = all.begin (); other != all.end (); ++other) + for (other = tasks.begin (); other != tasks.end (); ++other) { if (other->id == task->id || // Self (task->has ("parent") && @@ -91,26 +97,22 @@ int CmdPrepend::execute (std::string& output) int changes = 0; // Apply other deltas. - changes += deltaPrepend (*other); - changes += deltaTags (*other); - changes += deltaAttributes (*other); - changes += deltaSubstitutions (*other); + modify_task_description_prepend (*other, modifications); + apply_defaults (*other); + ++changes; if (taskDiff (before, *other)) { // Only allow valid tasks. other->validate (); - if (changes && permission.confirmed (before, taskDifferences (before, *other) + "Are you sure?")) + if (changes && permission.confirmed (before, taskDifferences (before, *other) + "Proceed with change?")) { context.tdb.update (*other); if (context.config.getBoolean ("echo.command")) - out << "Prepended '" - << context.task.get ("description") - << "' to task " - << other->id - << ".\n"; + out << format (STRING_CMD_PREPEND_DONE, other->id) + << "\n"; if (before.get ("project") != other->get ("project")) context.footnote (onProjectChange (before, *other)); @@ -126,10 +128,13 @@ int CmdPrepend::execute (std::string& output) context.tdb.unlock (); if (context.config.getBoolean ("echo.command")) - out << "Prepended " << count << " task" << (count == 1 ? ".\n" : "s.\n"); + out << format ((count == 1 + ? STRING_CMD_PREPEND_SUMMARY + : STRING_CMD_PREPEND_SUMMARY_N), + count) + << "\n"; output = out.str (); -*/ return rc; } diff --git a/src/en-US.h b/src/en-US.h index 4916548eb..6dc9f8a75 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -274,6 +274,15 @@ #define STRING_CMD_STOP_USAGE "Removes the 'start' time from a task." #define STRING_CMD_STOP_NOT "Task {1} '{2}' not started." #define STRING_CMD_STOP_DONE "Stopped {1} '{2}'." +#define STRING_CMD_APPEND_USAGE "Appends text to an existing task description." +#define STRING_CMD_APPEND_DONE "Appended to task {1}." +#define STRING_CMD_APPEND_SUMMARY "Appended {1} task." +#define STRING_CMD_APPEND_SUMMARY_N "Appended {1} tasks." +#define STRING_CMD_PREPEND_USAGE "Prepends text to an existing task description." +#define STRING_CMD_PREPEND_DONE "Prepended to task {1}." +#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." // Config #define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake."