Confirmation

- Implemented consistent confirmation.
This commit is contained in:
Paul Beckingham 2011-10-14 02:53:42 -04:00
parent a36cd3cbd1
commit bebd38c6d8
2 changed files with 16 additions and 43 deletions

View file

@ -28,9 +28,7 @@
#define L10N // Localization complete. #define L10N // Localization complete.
#include <iostream> #include <iostream>
#include <sstream>
#include <Context.h> #include <Context.h>
#include <Permission.h>
#include <main.h> #include <main.h>
#include <text.h> #include <text.h>
#include <util.h> #include <util.h>
@ -54,7 +52,6 @@ int CmdModify::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
int count = 0; int count = 0;
std::stringstream out;
// Apply filter. // Apply filter.
std::vector <Task> filtered; std::vector <Task> filtered;
@ -68,11 +65,7 @@ int CmdModify::execute (std::string& output)
// Apply the command line modifications to the new task. // Apply the command line modifications to the new task.
A3 modifications = context.a3.extract_modifications (); A3 modifications = context.a3.extract_modifications ();
if (!modifications.size ()) if (!modifications.size ())
throw std::string (STRING_CMD_XPEND_NEED_TEXT); throw std::string (STRING_CMD_MODIFY_NEED_TEXT);
Permission permission;
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
permission.bigSequence ();
std::vector <Task>::iterator task; std::vector <Task>::iterator task;
for (task = filtered.begin (); task != filtered.end (); ++task) for (task = filtered.begin (); task != filtered.end (); ++task)
@ -104,25 +97,16 @@ int CmdModify::execute (std::string& output)
throw std::string (STRING_CMD_MODIFY_REC_ALWAYS); throw std::string (STRING_CMD_MODIFY_REC_ALWAYS);
// Delete the specified task. // Delete the specified task.
std::string question = format (STRING_CMD_MODIFY_QUESTION, std::string question = format (STRING_CMD_MODIFY_CONFIRM,
task->id, task->id,
task->get ("description")); task->get ("description"));
if (permission.confirmed (*task, taskDifferences (before, *task) + question)) if (permission (*task, taskDifferences (before, *task) + question, filtered.size ()))
{ {
updateRecurrenceMask (*task); updateRecurrenceMask (*task);
context.tdb2.modify (*task); context.tdb2.modify (*task);
++count; ++count;
feedback_affected (STRING_CMD_MODIFY_TASK, *task);
if (context.verbose ("affected") ||
context.config.getBoolean ("echo.command")) // Deprecated 2.0
out << format (task->has ("parent")
? STRING_CMD_MODIFY_RECURRING
: STRING_CMD_MODIFY_SIMPLE,
task->id,
task->get ("description"))
<< "\n";
dependencyChainOnModify (before, *task); dependencyChainOnModify (before, *task);
context.footnote (onProjectChange (*task, true)); context.footnote (onProjectChange (*task, true));
@ -143,35 +127,20 @@ int CmdModify::execute (std::string& output)
dependencyChainOnModify (alternate, *sibling); dependencyChainOnModify (alternate, *sibling);
context.footnote (onProjectChange (*sibling, true)); context.footnote (onProjectChange (*sibling, true));
++count; ++count;
feedback_affected (STRING_CMD_MODIFY_TASK_R, *sibling);
if (context.verbose ("affected") ||
context.config.getBoolean ("echo.command")) // Deprecated 2.0
out << format (STRING_CMD_MODIFY_RECURRING,
sibling->id,
sibling->get ("description"))
<< "\n";
} }
} }
} }
} }
else else
{ {
out << STRING_CMD_MODIFY_NOT << "\n"; std::cout << STRING_CMD_MODIFY_NO << "\n";
rc = 1; rc = 1;
} }
} }
context.tdb2.commit (); context.tdb2.commit ();
feedback_affected (count == 1 ? STRING_CMD_MODIFY_1 : STRING_CMD_MODIFY_N, count);
if (context.verbose ("affected") ||
context.config.getBoolean ("echo.command")) // Deprecated 2.0
out << format ((count == 1
? STRING_CMD_MODIFY_TASK
: STRING_CMD_MODIFY_TASKS),
count)
<< "\n";
output = out.str ();
return rc; return rc;
} }

View file

@ -412,19 +412,23 @@
#define STRING_CMD_HCOMMANDS_USAGE "Generates a list of all commands, for autocompletion purposes" #define STRING_CMD_HCOMMANDS_USAGE "Generates a list of all commands, for autocompletion purposes"
#define STRING_CMD_ZSHCOMMANDS_USAGE "Generates a list of all commands, for zsh autocompletion purposes" #define STRING_CMD_ZSHCOMMANDS_USAGE "Generates a list of all commands, for zsh autocompletion purposes"
#define STRING_CMD_INSTALL_USAGE "Installs extensions and external scripts" #define STRING_CMD_INSTALL_USAGE "Installs extensions and external scripts"
#define STRING_CMD_MODIFY_USAGE1 "Modifies the existing task with provided arguments." #define STRING_CMD_MODIFY_USAGE1 "Modifies the existing task with provided arguments."
#define STRING_CMD_MODIFY_NO_DUE "You cannot specify a recurring task without a due date." #define STRING_CMD_MODIFY_NO_DUE "You cannot specify a recurring task without a due date."
#define STRING_CMD_MODIFY_UNTIL "You cannot specify an until date for a non-recurring task." #define STRING_CMD_MODIFY_UNTIL "You cannot specify an until date for a non-recurring task."
#define STRING_CMD_MODIFY_REM_DUE "You cannot remove the due date from a recurring task." #define STRING_CMD_MODIFY_REM_DUE "You cannot remove the due date from a recurring task."
#define STRING_CMD_MODIFY_REC_ALWAYS "You cannot remove the recurrence from a recurring task." #define STRING_CMD_MODIFY_REC_ALWAYS "You cannot remove the recurrence from a recurring task."
#define STRING_CMD_MODIFY_TASK "Modified {1} task." #define STRING_CMD_MODIFY_TASK "Modifying task {1} '{2}'."
#define STRING_CMD_MODIFY_TASKS "Modified {1} tasks." #define STRING_CMD_MODIFY_TASK_R "Modifying recurring task {1} '{2}'."
#define STRING_CMD_MODIFY_QUESTION "Modify task {1} '{2}'?" #define STRING_CMD_MODIFY_1 "Modified {1} task."
#define STRING_CMD_MODIFY_RECURRING "Modiying recurring task {1} '{2}'." #define STRING_CMD_MODIFY_N "Modified {1} tasks."
#define STRING_CMD_MODIFY_NO "Task not modified."
#define STRING_CMD_MODIFY_CONFIRM "Modify task {1} '{2}'?"
#define STRING_CMD_MODIFY_SIMPLE "Modiying task {1} '{2}'." #define STRING_CMD_MODIFY_SIMPLE "Modiying task {1} '{2}'."
#define STRING_CMD_MODIFY_NOT "Task not modified."
#define STRING_CMD_MODIFY_RECUR "This is a recurring task. Do you want to modify all pending recurrences of this same task?" #define STRING_CMD_MODIFY_RECUR "This is a recurring task. Do you want to modify all pending recurrences of this same task?"
#define STRING_CMD_MODIFY_NEED_TEXT "Additional text must be provided." #define STRING_CMD_MODIFY_NEED_TEXT "Additional text must be provided."
#define STRING_CMD_COLOR_USAGE "Displays all possible colors, a named sample, or a legend containing all currently defined colors" #define STRING_CMD_COLOR_USAGE "Displays all possible colors, a named sample, or a legend containing all currently defined colors"
#define STRING_CMD_COLOR_HERE "Here are the colors currently in use:" #define STRING_CMD_COLOR_HERE "Here are the colors currently in use:"
#define STRING_CMD_COLOR_COLOR "Color" #define STRING_CMD_COLOR_COLOR "Color"