Confirmation

- Implemented consistent confirmation.
This commit is contained in:
Paul Beckingham 2011-10-14 01:49:39 -04:00
parent 6e1ad5207d
commit 821c554e41
2 changed files with 102 additions and 120 deletions

View file

@ -25,12 +25,10 @@
//
////////////////////////////////////////////////////////////////////////////////
#define L10N // Localization complete.
#include <sstream>
#include <iostream>
#include <Context.h>
#include <Permission.h>
#include <util.h>
#include <text.h>
#include <i18n.h>
@ -54,7 +52,7 @@ int CmdDelete::execute (std::string& output)
{
int rc = 0;
int count = 0;
std::stringstream out;
//std::stringstream out;
// Apply filter.
std::vector <Task> filtered;
@ -71,121 +69,80 @@ int CmdDelete::execute (std::string& output)
std::vector <Task>::iterator task;
for (task = filtered.begin (); task != filtered.end (); ++task)
{
Task before (*task);
if (task->getStatus () == Task::pending ||
task->getStatus () == Task::waiting)
{
modify_task_annotate (*task, modifications);
std::string question = format (STRING_CMD_DELETE_QUESTION,
// Delete the specified task.
std::string question = format (STRING_CMD_DELETE_CONFIRM,
task->id,
task->get ("description"));
if (!context.config.getBoolean ("confirmation") || confirm (question))
{
// Check for the more complex case of a recurring task. If this is a
// recurring task, get confirmation to delete them all.
std::string parent = task->get ("parent");
if (parent != "")
{
std::vector <Task> siblings;
modify_task_annotate (*task, modifications);
task->setStatus (Task::deleted);
if (! task->has ("end"))
task->setEnd ();
if (context.config.getBoolean ("confirmation") &&
confirm (STRING_CMD_DELETE_CONF_RECUR))
if (permission (*task, question, filtered.size ()))
{
updateRecurrenceMask (*task);
context.tdb2.modify (*task);
++count;
feedback_affected (STRING_CMD_DELETE_TASK *task);
dependencyChainOnComplete (*task);
context.footnote (onProjectChange (*task, true));
// Delete siblings.
if (task->has ("parent"))
{
std::vector <Task> siblings = context.tdb2.siblings (*task);
if (siblings.size () &&
confirm (STRING_CMD_DELETE_CONFIRM_R))
{
// Scan all pending tasks for siblings of this task, and the parent
// itself, and delete them.
siblings = context.tdb2.siblings (*task);
std::vector <Task>::iterator sibling;
for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling)
{
if (sibling->get ("parent") == parent ||
sibling->get ("uuid") == parent)
{
sibling->setStatus (Task::deleted);
modify_task_annotate (*sibling, modifications);
sibling->setStatus (Task::deleted);
if (! sibling->has ("end"))
sibling->setEnd ();
// Don't want a 'delete' to clobber the end date that may have
// been written by a 'done' command.
if (! sibling->has ("end"))
sibling->setEnd ();
// Apply the command line modifications to the sibling.
modify_task_annotate (*sibling, modifications);
context.tdb2.modify (*sibling);
++count;
if (context.verbose ("affected") ||
context.config.getBoolean ("echo.command")) // Deprecated 2.0
out << format (STRING_CMD_DELETE_RECURRING,
sibling->id,
sibling->get ("description"))
<< "\n";
}
updateRecurrenceMask (*sibling);
context.tdb2.modify (*sibling);
++count;
feedback_affected (STRING_CMD_DELETE_TASK_R, *sibling);
}
// Delete the parent
Task parent;
context.tdb2.get (task->get ("parent"), parent);
parent.setStatus (Task::deleted);
if (! parent.has ("end"))
parent.setEnd ();
context.tdb2.modify (parent);
}
else
{
// Update mask in parent.
task->setStatus (Task::deleted);
updateRecurrenceMask (*task);
// Don't want a 'delete' to clobber the end date that may have
// been written by a 'done' command.
if (! task->has ("end"))
task->setEnd ();
context.tdb2.modify (*task);
++count;
out << format (STRING_CMD_DELETE_RECURRING,
task->id,
task->get ("description"))
<< "\n";
dependencyChainOnComplete (*task);
context.footnote (onProjectChange (*task));
}
}
else
{
task->setStatus (Task::deleted);
// Don't want a 'delete' to clobber the end date that may have
// been written by a 'done' command.
if (! task->has ("end"))
task->setEnd ();
context.tdb2.modify (*task);
++count;
if (context.verbose ("affected") ||
context.config.getBoolean ("echo.command")) // Deprecated 2.0
out << format (STRING_CMD_DELETE_DELETING,
task->id,
task->get ("description"))
<< "\n";
dependencyChainOnComplete (*task);
context.footnote (onProjectChange (*task));
}
}
else
{
out << STRING_CMD_DELETE_NOT << "\n";
std::cout << STRING_CMD_DELETE_NO << "\n";
rc = 1;
}
}
else
{
out << format (STRING_CMD_DELETE_NOTPEND,
task->id,
task->get ("description"))
std::cout << format (STRING_CMD_DELETE_NOTPEND,
task->id,
task->get ("description"))
<< "\n";
rc = 1;
}
}
context.tdb2.commit ();
output = out.str ();
feedback_affected (count == 1 ? STRING_CMD_DELETE_1 : STRING_CMD_DELETE_N, count);
return rc;
}