From e73c2556123ae419ca9808252c7bbe43ae63678a Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 14 Oct 2011 02:35:24 -0400 Subject: [PATCH] Confirmation - Implemented consistent confirmation. --- src/commands/CmdStart.cpp | 48 ++++++++++----------------------------- src/commands/CmdStop.cpp | 46 +++++++++---------------------------- src/en-US.h | 18 ++++++++------- 3 files changed, 33 insertions(+), 79 deletions(-) diff --git a/src/commands/CmdStart.cpp b/src/commands/CmdStart.cpp index 4423c89e6..95540c99e 100644 --- a/src/commands/CmdStart.cpp +++ b/src/commands/CmdStart.cpp @@ -27,9 +27,8 @@ #define L10N // Localization complete. -#include +#include #include -#include #include #include #include @@ -53,7 +52,6 @@ int CmdStart::execute (std::string& output) { int rc = 0; int count = 0; - std::stringstream out; // Apply filter. std::vector filtered; @@ -67,10 +65,6 @@ int CmdStart::execute (std::string& output) // 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) @@ -79,8 +73,8 @@ int CmdStart::execute (std::string& output) { Task before (*task); - // Complete the specified task. - std::string question = format (STRING_CMD_START_QUESTION, + // Start the specified task. + std::string question = format (STRING_CMD_START_CONFIRM, task->id, task->get ("description")); @@ -90,53 +84,35 @@ int CmdStart::execute (std::string& output) if (context.config.getBoolean ("journal.time")) task->addAnnotation (context.config.get ("journal.time.start.annotation")); - if (permission.confirmed (*task, taskDifferences (before, *task) + question)) + if (permission (*task, taskDifferences (before, *task) + question, filtered.size ())) { updateRecurrenceMask (*task); context.tdb2.modify (*task); + ++count; + feedback_affected (STRING_CMD_START_TASK, *task); if (!nagged) nagged = nag (*task); - ++count; - - if (context.verbose ("affected") || - context.config.getBoolean ("echo.command")) // Deprecated 2.0 - out << format (task->has ("parent") - ? STRING_CMD_START_RECURRING - : STRING_CMD_START_TASK, - task->id, - task->get ("description")) - << "\n"; - dependencyChainOnStart (*task); context.footnote (onProjectChange (*task, false)); } else { - out << format (STRING_CMD_START_NOT, task->id) << "\n"; + std::cout << STRING_CMD_START_NO << "\n"; rc = 1; } } else { - out << format (STRING_CMD_START_ALREADY, - task->id, - task->get ("description")) - << "\n"; + std::cout << format (STRING_CMD_START_ALREADY, + 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_START_STARTED - : STRING_CMD_START_STARTED_N), - count) - << "\n"; - - output = out.str (); + feedback_affected (count == 1 ? STRING_CMD_START_1 : STRING_CMD_START_N, count); return rc; } diff --git a/src/commands/CmdStop.cpp b/src/commands/CmdStop.cpp index 8e0468a59..429009d8a 100644 --- a/src/commands/CmdStop.cpp +++ b/src/commands/CmdStop.cpp @@ -27,9 +27,8 @@ #define L10N // Localization complete. -#include +#include #include -#include #include #include #include @@ -52,7 +51,6 @@ int CmdStop::execute (std::string& output) { int rc = 0; int count = 0; - std::stringstream out; // Apply filter. std::vector filtered; @@ -66,10 +64,6 @@ int CmdStop::execute (std::string& output) // 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 (); - std::vector ::iterator task; for (task = filtered.begin (); task != filtered.end (); ++task) { @@ -77,8 +71,8 @@ int CmdStop::execute (std::string& output) { Task before (*task); - // Complete the specified task. - std::string question = format (STRING_CMD_STOP_QUESTION, + // Stop the specified task. + std::string question = format (STRING_CMD_STOP_CONFIRM, task->id, task->get ("description")); @@ -88,51 +82,33 @@ int CmdStop::execute (std::string& output) if (context.config.getBoolean ("journal.time")) task->addAnnotation (context.config.get ("journal.time.stop.annotation")); - if (permission.confirmed (*task, taskDifferences (before, *task) + question)) + if (permission (*task, taskDifferences (before, *task) + question, filtered.size ())) { updateRecurrenceMask (*task); context.tdb2.modify (*task); ++count; - - if (context.verbose ("affected") || - context.config.getBoolean ("echo.command")) // Deprecated 2.0 - out << format (task->has ("parent") - ? STRING_CMD_STOP_RECURRING - : STRING_CMD_STOP_TASK, - task->id, - task->get ("description")) - << "\n"; - + feedback_affected (STRING_CMD_STOP_TASK, *task); dependencyChainOnStart (*task); context.footnote (onProjectChange (*task, false)); } else { - out << format (STRING_CMD_STOP_NOT, task->id) << "\n"; + std::cout << STRING_CMD_STOP_NO << "\n"; rc = 1; } } else { - out << format (STRING_CMD_STOP_ALREADY, - task->id, - task->get ("description")) - << "\n"; + std::cout << format (STRING_CMD_STOP_ALREADY, + 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_STOP_STOPPED - : STRING_CMD_STOP_STOPPED_N), - count) - << "\n"; - - output = out.str (); + feedback_affected (count == 1 ? STRING_CMD_STOP_1 : STRING_CMD_STOP_N, count); return rc; } diff --git a/src/en-US.h b/src/en-US.h index 5daffffbb..d93050d04 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -303,22 +303,24 @@ #define STRING_CMD_DUPLICATE_NOT "Task not duplicated." #define STRING_CMD_DUPLICATE_DUP_1 "Duplicated {1} task." #define STRING_CMD_DUPLICATE_DUP_N "Duplicated {1} tasks." -#define STRING_CMD_START_NOT "Task {1} not started." + #define STRING_CMD_START_USAGE "Marks specified task as started" +#define STRING_CMD_START_NO "Task not started." #define STRING_CMD_START_ALREADY "Task {1} '{2}' already started." #define STRING_CMD_START_RECURRING "Starting recurring task {1} '{2}'." #define STRING_CMD_START_TASK "Starting task {1} '{2}'." -#define STRING_CMD_START_QUESTION "Start task {1} '{2}'?" -#define STRING_CMD_START_STARTED "Started {1} task." -#define STRING_CMD_START_STARTED_N "Started {1} tasks." +#define STRING_CMD_START_CONFIRM "Start task {1} '{2}'?" +#define STRING_CMD_START_1 "Started {1} task." +#define STRING_CMD_START_N "Started {1} tasks." + #define STRING_CMD_STOP_USAGE "Removes the 'start' time from a task" -#define STRING_CMD_STOP_NOT "Task {1} not stopped." +#define STRING_CMD_STOP_NO "Task not stopped." #define STRING_CMD_STOP_ALREADY "Task {1} '{2}' not started." #define STRING_CMD_STOP_RECURRING "Stopping recurring task {1} '{2}'." #define STRING_CMD_STOP_TASK "Stopping task {1} '{2}'." -#define STRING_CMD_STOP_QUESTION "Stop task {1} '{2}'?" -#define STRING_CMD_STOP_STOPPED "Stopped {1} task." -#define STRING_CMD_STOP_STOPPED_N "Stopped {1} tasks." +#define STRING_CMD_STOP_CONFIRM "Stop task {1} '{2}'?" +#define STRING_CMD_STOP_1 "Stopped {1} task." +#define STRING_CMD_STOP_N "Stopped {1} tasks." #define STRING_CMD_APPEND_USAGE "Appends text to an existing task description" #define STRING_CMD_APPEND_1 "Appended {1} task."