Confirmation

- Implemented consistent confirmation.
This commit is contained in:
Paul Beckingham 2011-10-14 01:50:16 -04:00
parent 821c554e41
commit 6b40b0fb4a

View file

@ -27,9 +27,8 @@
#define L10N // Localization complete. #define L10N // Localization complete.
#include <sstream> #include <iostream>
#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>
@ -53,7 +52,6 @@ int CmdAnnotate::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;
@ -69,36 +67,23 @@ int CmdAnnotate::execute (std::string& output)
if (!modifications.size ()) if (!modifications.size ())
throw std::string (STRING_CMD_XPEND_NEED_TEXT); throw std::string (STRING_CMD_XPEND_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)
{ {
Task before (*task); Task before (*task);
// Annotate the specified task. // Annotate the specified task.
std::string question = format (STRING_CMD_ANNO_QUESTION, std::string question = format (STRING_CMD_ANNO_CONFIRM,
task->id, task->id,
task->get ("description")); task->get ("description"));
modify_task_annotate (*task, modifications); modify_task_annotate (*task, modifications);
if (permission.confirmed (*task, taskDifferences (before, *task) + question)) if (permission (*task, taskDifferences (before, *task) + question, filtered.size ()))
{ {
context.tdb2.modify (*task); context.tdb2.modify (*task);
++count; ++count;
feedback_affected (STRING_CMD_ANNO_TASK, *task);
if (context.verbose ("affected") ||
context.config.getBoolean ("echo.command")) // Deprecated 2.0
out << format (task->has ("parent")
? STRING_CMD_ANNO_RECURRING
: STRING_CMD_ANNO_DELETING,
task->id,
task->get ("description"))
<< "\n";
dependencyChainOnComplete (*task); dependencyChainOnComplete (*task);
context.footnote (onProjectChange (*task, true)); context.footnote (onProjectChange (*task, true));
@ -107,7 +92,7 @@ int CmdAnnotate::execute (std::string& output)
{ {
std::vector <Task> siblings = context.tdb2.siblings (*task); std::vector <Task> siblings = context.tdb2.siblings (*task);
if (siblings.size () && if (siblings.size () &&
confirm (STRING_CMD_ANNO_CONF_RECUR)) confirm (STRING_CMD_ANNO_CONFIRM_R))
{ {
std::vector <Task>::iterator sibling; std::vector <Task>::iterator sibling;
for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling) for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling)
@ -115,13 +100,7 @@ int CmdAnnotate::execute (std::string& output)
modify_task_annotate (*sibling, modifications); modify_task_annotate (*sibling, modifications);
context.tdb2.modify (*sibling); context.tdb2.modify (*sibling);
++count; ++count;
feedback_affected (STRING_CMD_ANNO_TASK_R, *sibling);
if (context.verbose ("affected") ||
context.config.getBoolean ("echo.command")) // Deprecated 2.0
out << format (STRING_CMD_ANNO_RECURRING,
sibling->id,
sibling->get ("description"))
<< "\n";
} }
// Annotate the parent // Annotate the parent
@ -134,22 +113,13 @@ int CmdAnnotate::execute (std::string& output)
} }
else else
{ {
out << STRING_CMD_DELETE_NOT << "\n"; std::cout << STRING_CMD_ANNO_NO << "\n";
rc = 1; rc = 1;
} }
} }
context.tdb2.commit (); context.tdb2.commit ();
feedback_affected (count == 1 ? STRING_CMD_ANNO_1 : STRING_CMD_ANNO_N, count);
if (context.verbose ("affected") ||
context.config.getBoolean ("echo.command")) // Deprecated 2.0
out << format ((count == 1
? STRING_CMD_ANNO_SUMMARY
: STRING_CMD_ANNO_SUMMARY_N),
count)
<< "\n";
output = out.str ();
return rc; return rc;
} }