From fd0d2fc91731aa8d2387468a214cc79fceb761cc Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sun, 20 Mar 2016 10:02:29 +0100 Subject: [PATCH] CmdPurge: Prompt before purging a task --- src/commands/CmdPurge.cpp | 27 ++++++++++++++++++--------- src/l10n/eng-USA.h | 1 + 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/commands/CmdPurge.cpp b/src/commands/CmdPurge.cpp index 12cf14c3a..1d9143e43 100644 --- a/src/commands/CmdPurge.cpp +++ b/src/commands/CmdPurge.cpp @@ -30,6 +30,7 @@ #include #include #include +#include extern Context context; @@ -73,18 +74,26 @@ int CmdPurge::execute (std::string&) if (task.getStatus () == Task::deleted) { - context.tdb2.purge (task); - count++; + std::string question; + question = format (STRING_CMD_PURGE_CONFIRM, + task.identifier (true), + task.get ("description")); - // Remove dependencies on the task being purged - for (auto& blockedConst: context.tdb2.all_tasks ()) + if (permission (question, filtered.size ())) { - Task& blocked = const_cast(blockedConst); - if (blocked.has ("depends") && - blocked.get ("depends").find (uuid) != std::string::npos) + context.tdb2.purge (task); + count++; + + // Remove dependencies on the task being purged + for (auto& blockedConst: context.tdb2.all_tasks ()) { - blocked.removeDependency (uuid); - context.tdb2.modify (blocked); + Task& blocked = const_cast(blockedConst); + if (blocked.has ("depends") && + blocked.get ("depends").find (uuid) != std::string::npos) + { + blocked.removeDependency (uuid); + context.tdb2.modify (blocked); + } } } } diff --git a/src/l10n/eng-USA.h b/src/l10n/eng-USA.h index 857628cf4..3bded4f9e 100644 --- a/src/l10n/eng-USA.h +++ b/src/l10n/eng-USA.h @@ -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_1 "Purged {1} task." #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_NO "Task not started."