diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 495e41866..3c9cb28e1 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -150,6 +150,8 @@ bool Hooks::trigger (const std::string& event) std::string type; if (eventType (event, type)) { + context.debug (std::string ("Event ") + event + " triggered"); + // Figure out where to get the calling-context info from. if (type == "program") rc = api.callProgramHook (it->file, it->function); 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-undo" || event == "post-undo" || event == "pre-file-lock" || event == "post-file-lock" || - event == "pre-file-unlock" || event == "post-file-unlock" || event == "pre-add-command" || event == "post-add-command") { type = "program"; @@ -193,8 +194,9 @@ bool Hooks::eventType (const std::string& event, std::string& type) type = "list"; return true; } - else if (event == "pre-tag" || event == "post-tag" || - event == "pre-detag" || event == "post-detag") + else if (event == "pre-tag" || event == "post-tag" || + event == "pre-detag" || event == "post-detag" || + event == "pre-completed" || event == "post-completed") { type = "task"; return true; diff --git a/src/TDB.cpp b/src/TDB.cpp index baa97ed70..4506e0062 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -144,30 +144,26 @@ void TDB::lock (bool lockFile /* = true */) //////////////////////////////////////////////////////////////////////////////// void TDB::unlock () { - if (mAllOpenAndLocked && context.hooks.trigger ("pre-file-unlock")) + mPending.clear (); + mNew.clear (); + mModified.clear (); + + foreach (location, mLocations) { - mPending.clear (); - mNew.clear (); - mModified.clear (); + fflush (location->pending); + fclose (location->pending); + location->pending = NULL; - foreach (location, mLocations) - { - fflush (location->pending); - fclose (location->pending); - location->pending = NULL; + fflush (location->completed); + fclose (location->completed); + location->completed = NULL; - fflush (location->completed); - fclose (location->completed); - location->completed = NULL; - - fflush (location->undo); - fclose (location->undo); - location->completed = NULL; - } - - mAllOpenAndLocked = false; - context.hooks.trigger ("post-file-unlock"); + fflush (location->undo); + fclose (location->undo); + location->completed = NULL; } + + mAllOpenAndLocked = false; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/command.cpp b/src/command.cpp index ee94247c5..839d14e5b 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -994,20 +994,28 @@ int handleDone (std::string &outs) if (taskDiff (before, *task)) { - if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?")) + context.hooks.setTaskId (task->id); + if (context.hooks.trigger ("pre-completed")) { - context.tdb.update (*task); + if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?")) + { + context.tdb.update (*task); - if (context.config.getBoolean ("echo.command")) - out << "Completed " - << task->id - << " '" - << task->get ("description") - << "'" - << std::endl; + if (context.config.getBoolean ("echo.command")) + out << "Completed " + << task->id + << " '" + << task->get ("description") + << "'" + << std::endl; - ++count; + ++count; + } + + context.hooks.trigger ("post-completed"); } + else + continue; } updateRecurrenceMask (all, *task); @@ -1024,7 +1032,9 @@ int handleDone (std::string &outs) rc = 1; } - context.tdb.commit (); + if (count) + context.tdb.commit (); + context.tdb.unlock (); if (context.config.getBoolean ("echo.command"))