mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Enhancement - Hooks
- Implemented pre-debug, post-debug. - Implemented pre-header, post-header. - Implemented pre-output, post-output. - Implemented pre-footnote, post-footnote. - Implemented pre-gc, post-gc. - Implemented pre-undo, post-undo. - Implemented pre-add-command, post-add-command.
This commit is contained in:
parent
8540cab0a6
commit
1cd6d4c7e7
4 changed files with 26 additions and 3 deletions
|
@ -159,29 +159,37 @@ int Context::run ()
|
|||
}
|
||||
|
||||
// Dump all debug messages.
|
||||
hooks.trigger ("pre-debug");
|
||||
if (config.getBoolean ("debug"))
|
||||
foreach (d, debugMessages)
|
||||
if (config.getBoolean ("color") || config.getBoolean ("_forcecolor"))
|
||||
std::cout << colorizeDebug (*d) << std::endl;
|
||||
else
|
||||
std::cout << *d << std::endl;
|
||||
hooks.trigger ("post-debug");
|
||||
|
||||
// Dump all headers.
|
||||
hooks.trigger ("pre-header");
|
||||
foreach (h, headers)
|
||||
if (config.getBoolean ("color") || config.getBoolean ("_forcecolor"))
|
||||
std::cout << colorizeHeader (*h) << std::endl;
|
||||
else
|
||||
std::cout << *h << std::endl;
|
||||
hooks.trigger ("post-header");
|
||||
|
||||
// Dump the report output.
|
||||
hooks.trigger ("pre-output");
|
||||
std::cout << output;
|
||||
hooks.trigger ("post-output");
|
||||
|
||||
// Dump all footnotes.
|
||||
hooks.trigger ("pre-footnote");
|
||||
foreach (f, footnotes)
|
||||
if (config.getBoolean ("color") || config.getBoolean ("_forcecolor"))
|
||||
std::cout << colorizeFootnote (*f) << std::endl;
|
||||
else
|
||||
std::cout << *f << std::endl;
|
||||
hooks.trigger ("post-footnote");
|
||||
|
||||
hooks.trigger ("pre-exit");
|
||||
return rc;
|
||||
|
|
|
@ -129,7 +129,14 @@ bool Hooks::eventType (const std::string& event, std::string& type)
|
|||
{
|
||||
if (event == "post-start" ||
|
||||
event == "pre-exit" ||
|
||||
event == "pre-dispatch" || event == "post-dispatch")
|
||||
event == "pre-debug" || event == "post-debug" ||
|
||||
event == "pre-header" || event == "post-header" ||
|
||||
event == "pre-footnote" || event == "post-footnote" ||
|
||||
event == "pre-output" || event == "post-output" ||
|
||||
event == "pre-dispatch" || event == "post-dispatch" ||
|
||||
event == "pre-gc" || event == "post-gc" ||
|
||||
event == "pre-undo" || event == "post-undo" ||
|
||||
event == "pre-add-command" || event == "post-add-command")
|
||||
{
|
||||
type = "program";
|
||||
return true;
|
||||
|
|
|
@ -343,6 +343,7 @@ void TDB::update (const Task& task)
|
|||
int TDB::commit ()
|
||||
{
|
||||
Timer t ("TDB::commit");
|
||||
context.hooks.trigger ("pre-gc");
|
||||
|
||||
int quantity = mNew.size () + mModified.size ();
|
||||
|
||||
|
@ -362,6 +363,7 @@ int TDB::commit ()
|
|||
writeUndo (*task, mLocations[0].undo);
|
||||
|
||||
mNew.clear ();
|
||||
context.hooks.trigger ("post-gc");
|
||||
return quantity;
|
||||
}
|
||||
|
||||
|
@ -408,6 +410,7 @@ int TDB::commit ()
|
|||
mNew.clear ();
|
||||
}
|
||||
|
||||
context.hooks.trigger ("post-gc");
|
||||
return quantity;
|
||||
}
|
||||
|
||||
|
@ -506,6 +509,7 @@ int TDB::nextId ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
void TDB::undo ()
|
||||
{
|
||||
context.hooks.trigger ("pre-undo");
|
||||
Directory location (context.config.get ("data.location"));
|
||||
|
||||
std::string undoFile = location.data + "/undo.data";
|
||||
|
@ -670,6 +674,7 @@ void TDB::undo ()
|
|||
// Rewrite files.
|
||||
File::write (pendingFile, p);
|
||||
File::write (undoFile, u);
|
||||
context.hooks.trigger ("post-undo");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -708,6 +713,7 @@ void TDB::undo ()
|
|||
}
|
||||
|
||||
std::cout << "Undo complete." << std::endl;
|
||||
context.hooks.trigger ("post-undo");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ extern Context context;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int handleAdd (std::string &outs)
|
||||
{
|
||||
context.hooks.trigger ("pre-add-command");
|
||||
std::stringstream out;
|
||||
|
||||
context.task.set ("uuid", uuid ());
|
||||
|
@ -112,6 +113,7 @@ int handleAdd (std::string &outs)
|
|||
context.tdb.unlock ();
|
||||
|
||||
outs = out.str ();
|
||||
context.hooks.trigger ("post-add-command");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue