From af3bbc21d23411b469b766001a0c660b3e57eef4 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 14 Oct 2011 02:41:26 -0400 Subject: [PATCH] Confirmation - Implemented consistent confirmation. --- src/commands/CmdDone.cpp | 74 +++++++++++++++++----------------------- src/en-US.h | 9 +++-- 2 files changed, 38 insertions(+), 45 deletions(-) diff --git a/src/commands/CmdDone.cpp b/src/commands/CmdDone.cpp index ad2a2a4ed..eca81cb35 100644 --- a/src/commands/CmdDone.cpp +++ b/src/commands/CmdDone.cpp @@ -25,15 +25,14 @@ // //////////////////////////////////////////////////////////////////////////////// - #define L10N // Localization complete. -#include +#include #include -#include -#include +#include #include #include +#include #include extern Context context; @@ -53,7 +52,6 @@ int CmdDone::execute (std::string& output) { int rc = 0; int count = 0; - std::stringstream out; // Apply filter. std::vector filtered; @@ -64,70 +62,62 @@ int CmdDone::execute (std::string& output) return 1; } - // Apply the command line modifications to the completed task. + // Apply the command line modifications to the new task. A3 modifications = context.a3.extract_modifications (); - Permission permission; - if (filtered.size () > (size_t) context.config.getInteger ("bulk")) - permission.bigSequence (); - bool nagged = false; std::vector ::iterator task; for (task = filtered.begin (); task != filtered.end (); ++task) { + Task before (*task); + if (task->getStatus () == Task::pending || task->getStatus () == Task::waiting) { - Task before (*task); + // Complete the specified task. + std::string question = format (STRING_CMD_DONE_CONFIRM, + task->id, + task->get ("description")); + modify_task_annotate (*task, modifications); task->setStatus (Task::completed); + if (! task->has ("end")) + task->setEnd (); // Stop the task, if started. if (task->has ("start") && context.config.getBoolean ("journal.time")) task->addAnnotation (context.config.get ("journal.time.stop.annotation")); - if (taskDiff (before, *task)) + if (permission (*task, taskDifferences (before, *task) + question, filtered.size ())) { - if (permission.confirmed (before, taskDifferences (before, *task) + STRING_CMD_DONE_PROCEED)) - { - context.tdb2.modify (*task); - ++count; - - if (context.verbose ("affected") || - context.config.getBoolean ("echo.command")) // Deprecated 2.0 - out << format (STRING_CMD_DONE_COMPLETED, task->id, task->get ("description")) - << "\n"; - - dependencyChainOnComplete (*task); - context.footnote (onProjectChange (*task, false)); - - } + updateRecurrenceMask (*task); + context.tdb2.modify (*task); + ++count; + feedback_affected (STRING_CMD_DONE_TASK, *task); + if (!nagged) + nagged = nag (*task); + dependencyChainOnComplete (*task); + context.footnote (onProjectChange (*task, false)); + } + else + { + std::cout << STRING_CMD_DONE_NO << "\n"; + rc = 1; } - - updateRecurrenceMask (*task); - if (!nagged) - nagged = nag (*task); } else { - out << format (STRING_CMD_DONE_NOT_PENDING, task->id, task->get ("description")) - << "\n"; + std::cout << format (STRING_CMD_DONE_NOTPEND, + task->id, + task->get ("description")) + << "\n"; rc = 1; } } context.tdb2.commit (); - - if (context.verbose ("affected") || - context.config.getBoolean ("echo.command")) // Deprecated 2.0 - out << format ((count == 1 - ? STRING_CMD_DONE_MARKED - : STRING_CMD_DONE_MARKED_N), - count) - << "\n"; - - output = out.str (); + feedback_affected (count == 1 ? STRING_CMD_DONE_1 : STRING_CMD_DONE_N, count); return rc; } diff --git a/src/en-US.h b/src/en-US.h index d93050d04..b25c1357b 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -262,12 +262,15 @@ #define STRING_CMD_GHISTORY_YEAR "Year" #define STRING_CMD_GHISTORY_MONTH "Month" #define STRING_CMD_GHISTORY_NUMBER "Number Added/Completed/Deleted" + #define STRING_CMD_DONE_USAGE "Marks the specified task as completed" -#define STRING_CMD_DONE_QUESTION "Complete task {1} '{2}'?" -#define STRING_CMD_DONE_NOT "Task not completed." -#define STRING_CMD_DONE_NOT_PENDING "Task {1} '{2}' is neither pending nor waiting." +#define STRING_CMD_DONE_CONFIRM "Complete task {1} '{2}'?" +#define STRING_CMD_DONE_TASK "Completed task {1} '{2}'." +#define STRING_CMD_DONE_NO "Task not completed." +#define STRING_CMD_DONE_NOTPEND "Task {1} '{2}' is neither pending nor waiting." #define STRING_CMD_DONE_1 "Completed {1} task." #define STRING_CMD_DONE_N "Completed {1} tasks." + #define STRING_CMD_PROJECTS_USAGE "Shows a list of all project names used, and how many tasks are in each" #define STRING_CMD_PROJECTS_USAGE_2 "Shows only a list of all project names used" #define STRING_CMD_PROJECTS_NO "No projects."