mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-07 22:58:34 +02:00
Hooks
- Gutted the Hooks object. - Commented out on-launch and on-exit triggers.
This commit is contained in:
parent
7f3e42e4e1
commit
bfb19e0a64
3 changed files with 5 additions and 170 deletions
138
src/Hooks.cpp
138
src/Hooks.cpp
|
@ -25,68 +25,14 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cmake.h>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <Context.h>
|
||||
#include <Hooks.h>
|
||||
#include <Timer.h>
|
||||
#include <text.h>
|
||||
#include <i18n.h>
|
||||
|
||||
extern Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Hook::Hook ()
|
||||
: _event ("")
|
||||
, _file ("")
|
||||
, _function ("")
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Hook::Hook (const std::string& e, const std::string& f, const std::string& fn)
|
||||
: _event (e)
|
||||
, _file (f)
|
||||
, _function (fn)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Hook::Hook (const Hook& other)
|
||||
{
|
||||
_event = other._event;
|
||||
_file = other._file;
|
||||
_function = other._function;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Hook& Hook::operator= (const Hook& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
_event = other._event;
|
||||
_file = other._file;
|
||||
_function = other._function;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Hooks::Hooks ()
|
||||
{
|
||||
// New 2.x hooks.
|
||||
_validTaskEvents.push_back ("on-task-add"); // Unimplemented
|
||||
_validTaskEvents.push_back ("on-task-modify"); // Unimplemented
|
||||
_validTaskEvents.push_back ("on-task-complete"); // Unimplemented
|
||||
_validTaskEvents.push_back ("on-task-delete"); // Unimplemented
|
||||
|
||||
_validProgramEvents.push_back ("on-launch");
|
||||
_validProgramEvents.push_back ("on-exit");
|
||||
_validProgramEvents.push_back ("on-file-read"); // Unimplemented
|
||||
_validProgramEvents.push_back ("on-file-write"); // Unimplemented
|
||||
_validProgramEvents.push_back ("on-synch"); // Unimplemented
|
||||
_validProgramEvents.push_back ("on-gc"); // Unimplemented
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -94,87 +40,5 @@ Hooks::~Hooks ()
|
|||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Enumerate all hooks, and tell API about the script files it must load in
|
||||
// order to call them. Note that API will perform a deferred read, which means
|
||||
// that if it isn't called, a script will not be loaded.
|
||||
void Hooks::initialize ()
|
||||
{
|
||||
// Allow a master switch to turn the whole thing off.
|
||||
bool big_red_switch = context.config.getBoolean ("extensions");
|
||||
if (big_red_switch)
|
||||
{
|
||||
Config::const_iterator it;
|
||||
for (it = context.config.begin (); it != context.config.end (); ++it)
|
||||
{
|
||||
std::string type;
|
||||
std::string name;
|
||||
std::string value;
|
||||
|
||||
// "<type>.<name>"
|
||||
Nibbler n (it->first);
|
||||
if (n.getUntil ('.', type) &&
|
||||
type == "hook" &&
|
||||
n.skip ('.') &&
|
||||
n.getUntilEOS (name))
|
||||
{
|
||||
Nibbler n (it->second);
|
||||
|
||||
// <path>:<function> [, ...]
|
||||
while (!n.depleted ())
|
||||
{
|
||||
std::string file;
|
||||
std::string function;
|
||||
if (n.getUntil (':', file) &&
|
||||
n.skip (':') &&
|
||||
n.getUntil (',', function))
|
||||
{
|
||||
context.debug (std::string ("Event '") + name + "' hooked by " + file + ", function " + function);
|
||||
Hook h (name, Path::expand (file), function);
|
||||
_all.push_back (h);
|
||||
|
||||
(void) n.skip (',');
|
||||
}
|
||||
else
|
||||
; // Was: throw std::string (format ("Malformed hook definition '{1}'.", it->first));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
context.debug ("Hooks::initialize --> off");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Program hooks.
|
||||
bool Hooks::trigger (const std::string& event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Task hooks.
|
||||
bool Hooks::trigger (const std::string& event, Task& task)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Hooks::validProgramEvent (const std::string& event)
|
||||
{
|
||||
if (std::find (_validProgramEvents.begin (), _validProgramEvents.end (), event) != _validProgramEvents.end ())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Hooks::validTaskEvent (const std::string& event)
|
||||
{
|
||||
if (std::find (_validTaskEvents.begin (), _validTaskEvents.end (), event) != _validTaskEvents.end ())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO Time the hook runs.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue