mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Enhancement - Hooks
- Implemented pre-delete, post-delete events. - Implemented pre-delete-command, post-delete-command events.
This commit is contained in:
parent
b02374c3f5
commit
d6daa336ca
2 changed files with 108 additions and 94 deletions
|
@ -184,7 +184,8 @@ bool Hooks::eventType (const std::string& event, std::string& type)
|
|||
event == "pre-gc" || event == "post-gc" ||
|
||||
event == "pre-undo" || event == "post-undo" ||
|
||||
event == "pre-file-lock" || event == "post-file-lock" ||
|
||||
event == "pre-add-command" || event == "post-add-command")
|
||||
event == "pre-add-command" || event == "post-add-command" ||
|
||||
event == "pre-delete-command" || event == "post-delete-command")
|
||||
{
|
||||
type = "program";
|
||||
return true;
|
||||
|
@ -196,6 +197,7 @@ bool Hooks::eventType (const std::string& event, std::string& type)
|
|||
}
|
||||
else if (event == "pre-tag" || event == "post-tag" ||
|
||||
event == "pre-detag" || event == "post-detag" ||
|
||||
event == "pre-delete" || event == "post-delete" ||
|
||||
event == "pre-completed" || event == "post-completed")
|
||||
{
|
||||
type = "task";
|
||||
|
|
|
@ -742,6 +742,9 @@ int handleConfig (std::string &outs)
|
|||
int handleDelete (std::string &outs)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if (context.hooks.trigger ("pre-delete-command"))
|
||||
{
|
||||
std::stringstream out;
|
||||
|
||||
context.disallowModification ();
|
||||
|
@ -760,6 +763,9 @@ int handleDelete (std::string &outs)
|
|||
sprintf (endTime, "%u", (unsigned int) time (NULL));
|
||||
|
||||
foreach (task, tasks)
|
||||
{
|
||||
context.hooks.setTaskId (task->id);
|
||||
if (context.hooks.trigger ("pre-delete"))
|
||||
{
|
||||
std::stringstream question;
|
||||
question << "Permanently delete task "
|
||||
|
@ -834,12 +840,18 @@ int handleDelete (std::string &outs)
|
|||
out << "Task not deleted." << std::endl;
|
||||
rc = 1;
|
||||
}
|
||||
|
||||
context.hooks.trigger ("post-delete");
|
||||
}
|
||||
}
|
||||
|
||||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
outs = out.str ();
|
||||
context.hooks.trigger ("post-delete-command");
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue