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.
#include <iostream>
#include <sstream>
#include <Context.h>
#include <Permission.h>
#include <main.h>
#include <text.h>
#include <util.h>
@ -54,7 +52,6 @@ int CmdModify::execute (std::string& output)
{
int rc = 0;
int count = 0;
std::stringstream out;
// Apply filter.
std::vector <Task> filtered;
@ -68,11 +65,7 @@ int CmdModify::execute (std::string& output)
// Apply the command line modifications to the new task.
A3 modifications = context.a3.extract_modifications ();
if (!modifications.size ())
throw std::string (STRING_CMD_XPEND_NEED_TEXT);
Permission permission;
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
permission.bigSequence ();
throw std::string (STRING_CMD_MODIFY_NEED_TEXT);
std::vector <Task>::iterator 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);
// Delete the specified task.
std::string question = format (STRING_CMD_MODIFY_QUESTION,
std::string question = format (STRING_CMD_MODIFY_CONFIRM,
task->id,
task->get ("description"));
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_MODIFY_RECURRING
: STRING_CMD_MODIFY_SIMPLE,
task->id,
task->get ("description"))
<< "\n";
feedback_affected (STRING_CMD_MODIFY_TASK, *task);
dependencyChainOnModify (before, *task);
context.footnote (onProjectChange (*task, true));
@ -143,35 +127,20 @@ int CmdModify::execute (std::string& output)
dependencyChainOnModify (alternate, *sibling);
context.footnote (onProjectChange (*sibling, true));
++count;
if (context.verbose ("affected") ||
context.config.getBoolean ("echo.command")) // Deprecated 2.0
out << format (STRING_CMD_MODIFY_RECURRING,
sibling->id,
sibling->get ("description"))
<< "\n";
feedback_affected (STRING_CMD_MODIFY_TASK_R, *sibling);
}
}
}
}
else
{
out << STRING_CMD_MODIFY_NOT << "\n";
std::cout << STRING_CMD_MODIFY_NO << "\n";
rc = 1;
}
}
context.tdb2.commit ();
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 ();
feedback_affected (count == 1 ? STRING_CMD_MODIFY_1 : STRING_CMD_MODIFY_N, count);
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_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_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_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_REC_ALWAYS "You cannot remove the recurrence from a recurring task."
#define STRING_CMD_MODIFY_TASK "Modified {1} task."
#define STRING_CMD_MODIFY_TASKS "Modified {1} tasks."
#define STRING_CMD_MODIFY_QUESTION "Modify task {1} '{2}'?"
#define STRING_CMD_MODIFY_RECURRING "Modiying recurring task {1} '{2}'."
#define STRING_CMD_MODIFY_TASK "Modifying task {1} '{2}'."
#define STRING_CMD_MODIFY_TASK_R "Modifying recurring task {1} '{2}'."
#define STRING_CMD_MODIFY_1 "Modified {1} task."
#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_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_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_HERE "Here are the colors currently in use:"
#define STRING_CMD_COLOR_COLOR "Color"