Enhancement - Hooks
- Implemented pre-completed, post-completed events. - Added debug info for event triggers. - Removed support for pre-file-unlock, post-file-unlock, as they are called from TDB::~TDB in Context::~Context, which is after Hooks::~Hooks, which means segfault.
This commit is contained in:
@@ -150,6 +150,8 @@ bool Hooks::trigger (const std::string& event)
|
|||||||
std::string type;
|
std::string type;
|
||||||
if (eventType (event, type))
|
if (eventType (event, type))
|
||||||
{
|
{
|
||||||
|
context.debug (std::string ("Event ") + event + " triggered");
|
||||||
|
|
||||||
// Figure out where to get the calling-context info from.
|
// Figure out where to get the calling-context info from.
|
||||||
if (type == "program") rc = api.callProgramHook (it->file, it->function);
|
if (type == "program") rc = api.callProgramHook (it->file, it->function);
|
||||||
else if (type == "list") rc = api.callListHook (it->file, it->function/*, tasks*/);
|
else if (type == "list") rc = api.callListHook (it->file, it->function/*, tasks*/);
|
||||||
@@ -182,7 +184,6 @@ bool Hooks::eventType (const std::string& event, std::string& type)
|
|||||||
event == "pre-gc" || event == "post-gc" ||
|
event == "pre-gc" || event == "post-gc" ||
|
||||||
event == "pre-undo" || event == "post-undo" ||
|
event == "pre-undo" || event == "post-undo" ||
|
||||||
event == "pre-file-lock" || event == "post-file-lock" ||
|
event == "pre-file-lock" || event == "post-file-lock" ||
|
||||||
event == "pre-file-unlock" || event == "post-file-unlock" ||
|
|
||||||
event == "pre-add-command" || event == "post-add-command")
|
event == "pre-add-command" || event == "post-add-command")
|
||||||
{
|
{
|
||||||
type = "program";
|
type = "program";
|
||||||
@@ -194,7 +195,8 @@ bool Hooks::eventType (const std::string& event, std::string& type)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (event == "pre-tag" || event == "post-tag" ||
|
else if (event == "pre-tag" || event == "post-tag" ||
|
||||||
event == "pre-detag" || event == "post-detag")
|
event == "pre-detag" || event == "post-detag" ||
|
||||||
|
event == "pre-completed" || event == "post-completed")
|
||||||
{
|
{
|
||||||
type = "task";
|
type = "task";
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -143,8 +143,6 @@ void TDB::lock (bool lockFile /* = true */)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void TDB::unlock ()
|
void TDB::unlock ()
|
||||||
{
|
|
||||||
if (mAllOpenAndLocked && context.hooks.trigger ("pre-file-unlock"))
|
|
||||||
{
|
{
|
||||||
mPending.clear ();
|
mPending.clear ();
|
||||||
mNew.clear ();
|
mNew.clear ();
|
||||||
@@ -166,8 +164,6 @@ void TDB::unlock ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
mAllOpenAndLocked = false;
|
mAllOpenAndLocked = false;
|
||||||
context.hooks.trigger ("post-file-unlock");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -993,6 +993,9 @@ int handleDone (std::string &outs)
|
|||||||
task->setStatus (Task::completed);
|
task->setStatus (Task::completed);
|
||||||
|
|
||||||
if (taskDiff (before, *task))
|
if (taskDiff (before, *task))
|
||||||
|
{
|
||||||
|
context.hooks.setTaskId (task->id);
|
||||||
|
if (context.hooks.trigger ("pre-completed"))
|
||||||
{
|
{
|
||||||
if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?"))
|
if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?"))
|
||||||
{
|
{
|
||||||
@@ -1008,6 +1011,11 @@ int handleDone (std::string &outs)
|
|||||||
|
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.hooks.trigger ("post-completed");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRecurrenceMask (all, *task);
|
updateRecurrenceMask (all, *task);
|
||||||
@@ -1024,7 +1032,9 @@ int handleDone (std::string &outs)
|
|||||||
rc = 1;
|
rc = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count)
|
||||||
context.tdb.commit ();
|
context.tdb.commit ();
|
||||||
|
|
||||||
context.tdb.unlock ();
|
context.tdb.unlock ();
|
||||||
|
|
||||||
if (context.config.getBoolean ("echo.command"))
|
if (context.config.getBoolean ("echo.command"))
|
||||||
|
|||||||
Reference in New Issue
Block a user