CmdPurge: Prompt before purging a task

This commit is contained in:
Tomas Babej 2016-03-20 10:02:29 +01:00 committed by Paul Beckingham
parent 6bca92a488
commit fd0d2fc917
2 changed files with 19 additions and 9 deletions

View file

@ -30,6 +30,7 @@
#include <Filter.h> #include <Filter.h>
#include <i18n.h> #include <i18n.h>
#include <main.h> #include <main.h>
#include <text.h>
extern Context context; extern Context context;
@ -73,18 +74,26 @@ int CmdPurge::execute (std::string&)
if (task.getStatus () == Task::deleted) if (task.getStatus () == Task::deleted)
{ {
context.tdb2.purge (task); std::string question;
count++; question = format (STRING_CMD_PURGE_CONFIRM,
task.identifier (true),
task.get ("description"));
// Remove dependencies on the task being purged if (permission (question, filtered.size ()))
for (auto& blockedConst: context.tdb2.all_tasks ())
{ {
Task& blocked = const_cast<Task&>(blockedConst); context.tdb2.purge (task);
if (blocked.has ("depends") && count++;
blocked.get ("depends").find (uuid) != std::string::npos)
// Remove dependencies on the task being purged
for (auto& blockedConst: context.tdb2.all_tasks ())
{ {
blocked.removeDependency (uuid); Task& blocked = const_cast<Task&>(blockedConst);
context.tdb2.modify (blocked); if (blocked.has ("depends") &&
blocked.get ("depends").find (uuid) != std::string::npos)
{
blocked.removeDependency (uuid);
context.tdb2.modify (blocked);
}
} }
} }
} }

View file

@ -399,6 +399,7 @@
#define STRING_CMD_PURGE_USAGE "Removes the specified tasks from the data files. Causes permanent loss of data." #define STRING_CMD_PURGE_USAGE "Removes the specified tasks from the data files. Causes permanent loss of data."
#define STRING_CMD_PURGE_1 "Purged {1} task." #define STRING_CMD_PURGE_1 "Purged {1} task."
#define STRING_CMD_PURGE_N "Purged {1} tasks." #define STRING_CMD_PURGE_N "Purged {1} tasks."
#define STRING_CMD_PURGE_CONFIRM "Permanently remove task {1} '{2}'?"
#define STRING_CMD_START_USAGE "Marks specified task as started" #define STRING_CMD_START_USAGE "Marks specified task as started"
#define STRING_CMD_START_NO "Task not started." #define STRING_CMD_START_NO "Task not started."