Confirmation

- Implemented consistent confirmation.
This commit is contained in:
Paul Beckingham 2011-10-14 02:35:24 -04:00
parent 02e7c4f3ce
commit e73c255612
3 changed files with 33 additions and 79 deletions

View file

@ -27,9 +27,8 @@
#define L10N // Localization complete.
#include <sstream>
#include <iostream>
#include <Context.h>
#include <Permission.h>
#include <main.h>
#include <text.h>
#include <util.h>
@ -53,7 +52,6 @@ int CmdStart::execute (std::string& output)
{
int rc = 0;
int count = 0;
std::stringstream out;
// Apply filter.
std::vector <Task> 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 <Task>::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;
}

View file

@ -27,9 +27,8 @@
#define L10N // Localization complete.
#include <sstream>
#include <iostream>
#include <Context.h>
#include <Permission.h>
#include <main.h>
#include <text.h>
#include <i18n.h>
@ -52,7 +51,6 @@ int CmdStop::execute (std::string& output)
{
int rc = 0;
int count = 0;
std::stringstream out;
// Apply filter.
std::vector <Task> 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 <Task>::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;
}

View file

@ -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."