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:
@@ -159,29 +159,37 @@ int Context::run ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Dump all debug messages.
|
// Dump all debug messages.
|
||||||
|
hooks.trigger ("pre-debug");
|
||||||
if (config.getBoolean ("debug"))
|
if (config.getBoolean ("debug"))
|
||||||
foreach (d, debugMessages)
|
foreach (d, debugMessages)
|
||||||
if (config.getBoolean ("color") || config.getBoolean ("_forcecolor"))
|
if (config.getBoolean ("color") || config.getBoolean ("_forcecolor"))
|
||||||
std::cout << colorizeDebug (*d) << std::endl;
|
std::cout << colorizeDebug (*d) << std::endl;
|
||||||
else
|
else
|
||||||
std::cout << *d << std::endl;
|
std::cout << *d << std::endl;
|
||||||
|
hooks.trigger ("post-debug");
|
||||||
|
|
||||||
// Dump all headers.
|
// Dump all headers.
|
||||||
|
hooks.trigger ("pre-header");
|
||||||
foreach (h, headers)
|
foreach (h, headers)
|
||||||
if (config.getBoolean ("color") || config.getBoolean ("_forcecolor"))
|
if (config.getBoolean ("color") || config.getBoolean ("_forcecolor"))
|
||||||
std::cout << colorizeHeader (*h) << std::endl;
|
std::cout << colorizeHeader (*h) << std::endl;
|
||||||
else
|
else
|
||||||
std::cout << *h << std::endl;
|
std::cout << *h << std::endl;
|
||||||
|
hooks.trigger ("post-header");
|
||||||
|
|
||||||
// Dump the report output.
|
// Dump the report output.
|
||||||
|
hooks.trigger ("pre-output");
|
||||||
std::cout << output;
|
std::cout << output;
|
||||||
|
hooks.trigger ("post-output");
|
||||||
|
|
||||||
// Dump all footnotes.
|
// Dump all footnotes.
|
||||||
|
hooks.trigger ("pre-footnote");
|
||||||
foreach (f, footnotes)
|
foreach (f, footnotes)
|
||||||
if (config.getBoolean ("color") || config.getBoolean ("_forcecolor"))
|
if (config.getBoolean ("color") || config.getBoolean ("_forcecolor"))
|
||||||
std::cout << colorizeFootnote (*f) << std::endl;
|
std::cout << colorizeFootnote (*f) << std::endl;
|
||||||
else
|
else
|
||||||
std::cout << *f << std::endl;
|
std::cout << *f << std::endl;
|
||||||
|
hooks.trigger ("post-footnote");
|
||||||
|
|
||||||
hooks.trigger ("pre-exit");
|
hooks.trigger ("pre-exit");
|
||||||
return rc;
|
return rc;
|
||||||
|
|||||||
@@ -127,9 +127,16 @@ bool Hooks::trigger (const std::string& event)
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Hooks::eventType (const std::string& event, std::string& type)
|
bool Hooks::eventType (const std::string& event, std::string& type)
|
||||||
{
|
{
|
||||||
if (event == "post-start" ||
|
if (event == "post-start" ||
|
||||||
event == "pre-exit" ||
|
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";
|
type = "program";
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -343,6 +343,7 @@ void TDB::update (const Task& task)
|
|||||||
int TDB::commit ()
|
int TDB::commit ()
|
||||||
{
|
{
|
||||||
Timer t ("TDB::commit");
|
Timer t ("TDB::commit");
|
||||||
|
context.hooks.trigger ("pre-gc");
|
||||||
|
|
||||||
int quantity = mNew.size () + mModified.size ();
|
int quantity = mNew.size () + mModified.size ();
|
||||||
|
|
||||||
@@ -362,6 +363,7 @@ int TDB::commit ()
|
|||||||
writeUndo (*task, mLocations[0].undo);
|
writeUndo (*task, mLocations[0].undo);
|
||||||
|
|
||||||
mNew.clear ();
|
mNew.clear ();
|
||||||
|
context.hooks.trigger ("post-gc");
|
||||||
return quantity;
|
return quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,6 +410,7 @@ int TDB::commit ()
|
|||||||
mNew.clear ();
|
mNew.clear ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.hooks.trigger ("post-gc");
|
||||||
return quantity;
|
return quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,6 +509,7 @@ int TDB::nextId ()
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void TDB::undo ()
|
void TDB::undo ()
|
||||||
{
|
{
|
||||||
|
context.hooks.trigger ("pre-undo");
|
||||||
Directory location (context.config.get ("data.location"));
|
Directory location (context.config.get ("data.location"));
|
||||||
|
|
||||||
std::string undoFile = location.data + "/undo.data";
|
std::string undoFile = location.data + "/undo.data";
|
||||||
@@ -670,6 +674,7 @@ void TDB::undo ()
|
|||||||
// Rewrite files.
|
// Rewrite files.
|
||||||
File::write (pendingFile, p);
|
File::write (pendingFile, p);
|
||||||
File::write (undoFile, u);
|
File::write (undoFile, u);
|
||||||
|
context.hooks.trigger ("post-undo");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -708,6 +713,7 @@ void TDB::undo ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Undo complete." << std::endl;
|
std::cout << "Undo complete." << std::endl;
|
||||||
|
context.hooks.trigger ("post-undo");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ extern Context context;
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int handleAdd (std::string &outs)
|
int handleAdd (std::string &outs)
|
||||||
{
|
{
|
||||||
|
context.hooks.trigger ("pre-add-command");
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
|
|
||||||
context.task.set ("uuid", uuid ());
|
context.task.set ("uuid", uuid ());
|
||||||
@@ -112,6 +113,7 @@ int handleAdd (std::string &outs)
|
|||||||
context.tdb.unlock ();
|
context.tdb.unlock ();
|
||||||
|
|
||||||
outs = out.str ();
|
outs = out.str ();
|
||||||
|
context.hooks.trigger ("post-add-command");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user