Confirmation

- Implemented consistent confirmation.
This commit is contained in:
Paul Beckingham
2011-10-14 02:23:22 -04:00
parent 1b54516b45
commit 02e7c4f3ce
4 changed files with 25 additions and 31 deletions

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 <text.h> #include <text.h>
#include <util.h> #include <util.h>
#include <i18n.h> #include <i18n.h>
@@ -53,7 +52,6 @@ int CmdDenotate::execute (std::string& output)
{ {
int rc = 0; int rc = 0;
int count = 0; int count = 0;
std::stringstream out;
bool sensitive = context.config.getBoolean ("search.case.sensitive"); bool sensitive = context.config.getBoolean ("search.case.sensitive");
// Apply filter. // Apply filter.
@@ -72,10 +70,6 @@ int CmdDenotate::execute (std::string& output)
std::string pattern = words.combine (); std::string pattern = words.combine ();
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)
{ {
@@ -118,39 +112,26 @@ int CmdDenotate::execute (std::string& output)
if (taskDiff (before, *task)) if (taskDiff (before, *task))
{ {
std::string question = format (STRING_CMD_DENO_QUESTION, std::string question = format (STRING_CMD_DENO_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 ()))
{ {
++count; ++count;
context.tdb2.modify (*task); context.tdb2.modify (*task);
if (context.verbose ("affected") || feedback_affected (format (STRING_CMD_DENO_FOUND, anno));
context.config.getBoolean ("echo.command")) // Deprecated 2.0
out << format (STRING_CMD_DENO_FOUND, anno)
<< "\n";
} }
} }
else else
{ {
out << format (STRING_CMD_DENO_NOMATCH, pattern) std::cout << format (STRING_CMD_DENO_NOMATCH, pattern) << "\n";
<< "\n";
rc = 1; rc = 1;
} }
} }
context.tdb2.commit (); context.tdb2.commit ();
feedback_affected (count == 1 ? STRING_CMD_DENO_1 : STRING_CMD_DENO_N, count);
if (context.verbose ("affected") ||
context.config.getBoolean ("echo.command")) // Deprecated 2.0
out << format ((count == 1
? STRING_CMD_DENO_TASK
: STRING_CMD_DENO_TASKS),
count)
<< "\n";
output = out.str ();
return rc; return rc;
} }

View File

@@ -325,7 +325,6 @@
#define STRING_CMD_APPEND_N "Appended {1} tasks." #define STRING_CMD_APPEND_N "Appended {1} tasks."
#define STRING_CMD_APPEND_TASK "Appending to task {1} '{2}'." #define STRING_CMD_APPEND_TASK "Appending to task {1} '{2}'."
#define STRING_CMD_APPEND_TASK_R "Appending to recurring task {1} '{2}'." #define STRING_CMD_APPEND_TASK_R "Appending to recurring task {1} '{2}'."
#define STRING_CMD_APPEND_DELETING "Appending to task {1} '{2}'."
#define STRING_CMD_APPEND_CONFIRM_R "This is a recurring task. Do you want to append to all pending recurrences of this same task?" #define STRING_CMD_APPEND_CONFIRM_R "This is a recurring task. Do you want to append to all pending recurrences of this same task?"
#define STRING_CMD_APPEND_CONFIRM "Append to task {1} '{2}'?" #define STRING_CMD_APPEND_CONFIRM "Append to task {1} '{2}'?"
#define STRING_CMD_APPEND_NO "Task not appended." #define STRING_CMD_APPEND_NO "Task not appended."
@@ -335,7 +334,6 @@
#define STRING_CMD_PREPEND_N "Prepended {1} tasks." #define STRING_CMD_PREPEND_N "Prepended {1} tasks."
#define STRING_CMD_PREPEND_TASK "Prepending to task {1} '{2}'." #define STRING_CMD_PREPEND_TASK "Prepending to task {1} '{2}'."
#define STRING_CMD_PREPEND_TASK_R "Prepending to recurring task {1} '{2}'." #define STRING_CMD_PREPEND_TASK_R "Prepending to recurring task {1} '{2}'."
#define STRING_CMD_PREPEND_DELETING "Prepending to task {1} '{2}'."
#define STRING_CMD_PREPEND_CONFIRM_R "This is a recurring task. Do you want to prepend to all pending recurrences of this same task?" #define STRING_CMD_PREPEND_CONFIRM_R "This is a recurring task. Do you want to prepend to all pending recurrences of this same task?"
#define STRING_CMD_PREPEND_CONFIRM "Prepend to task {1} '{2}'?" #define STRING_CMD_PREPEND_CONFIRM "Prepend to task {1} '{2}'?"
#define STRING_CMD_PREPEND_NO "Task not prepended." #define STRING_CMD_PREPEND_NO "Task not prepended."
@@ -352,14 +350,16 @@
#define STRING_CMD_COLUMNS_USAGE "Displays all supported columns and formatting styles" #define STRING_CMD_COLUMNS_USAGE "Displays all supported columns and formatting styles"
#define STRING_CMD_COLUMNS_NOTE "* Means default format, and therefore optional. For example, 'due' and 'due.formatted' are equivalent." #define STRING_CMD_COLUMNS_NOTE "* Means default format, and therefore optional. For example, 'due' and 'due.formatted' are equivalent."
#define STRING_CMD_COLUMNS_USAGE2 "Displays only a list of supported columns" #define STRING_CMD_COLUMNS_USAGE2 "Displays only a list of supported columns"
#define STRING_CMD_DENO_USAGE "Deletes an annotation" #define STRING_CMD_DENO_USAGE "Deletes an annotation"
#define STRING_CMD_DENO_WORDS "An annotation pattern must be provided." #define STRING_CMD_DENO_WORDS "An annotation pattern must be provided."
#define STRING_CMD_DENO_NONE "The specified task has no annotations that can be deleted." #define STRING_CMD_DENO_NONE "The specified task has no annotations that can be deleted."
#define STRING_CMD_DENO_CONFIRM "Denotate task {1} '{2}'?"
#define STRING_CMD_DENO_FOUND "Found annotation '{1}' and deleted it." #define STRING_CMD_DENO_FOUND "Found annotation '{1}' and deleted it."
#define STRING_CMD_DENO_NOMATCH "Did not find any matching annotation to be deleted for '{1}'." #define STRING_CMD_DENO_NOMATCH "Did not find any matching annotation to be deleted for '{1}'."
#define STRING_CMD_DENO_TASK "Denotated {1} task." #define STRING_CMD_DENO_1 "Denotated {1} task."
#define STRING_CMD_DENO_TASKS "Denotated {1} tasks." #define STRING_CMD_DENO_N "Denotated {1} tasks."
#define STRING_CMD_DENO_QUESTION "Denotate task {1} '{2}'?"
#define STRING_CMD_IMPORT_USAGE "Imports JSON files" #define STRING_CMD_IMPORT_USAGE "Imports JSON files"
#define STRING_CMD_IMPORT_SUMMARY "Imported {1} tasks." #define STRING_CMD_IMPORT_SUMMARY "Imported {1} tasks."
#define STRING_CMD_IMPORT_NOFILE "You must specify a file to import." #define STRING_CMD_IMPORT_NOFILE "You must specify a file to import."

View File

@@ -295,6 +295,18 @@ std::string renderAttribute (const std::string& name, const std::string& value)
return value; return value;
} }
////////////////////////////////////////////////////////////////////////////////
// Implements:
// <string>
void feedback_affected (const std::string& effect)
{
if (context.verbose ("affected") ||
context.config.getBoolean ("echo.command")) // Deprecated 2.0
{
std::cout << effect << "\n";
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Implements: // Implements:
// Deleted 3 tasks // Deleted 3 tasks

View File

@@ -74,8 +74,9 @@ bool taskDiff (const Task&, const Task&);
std::string taskDifferences (const Task&, const Task&); std::string taskDifferences (const Task&, const Task&);
std::string taskInfoDifferences (const Task&, const Task&); std::string taskInfoDifferences (const Task&, const Task&);
std::string renderAttribute (const std::string&, const std::string&); std::string renderAttribute (const std::string&, const std::string&);
void feedback_affected (const std::string&, const Task&); void feedback_affected (const std::string&);
void feedback_affected (const std::string&, int); void feedback_affected (const std::string&, int);
void feedback_affected (const std::string&, const Task&);
// sort.cpp // sort.cpp
void sort_tasks (std::vector <Task>&, std::vector <int>&, const std::string&); void sort_tasks (std::vector <Task>&, std::vector <int>&, const std::string&);