2012-04-03 16:01:01 +04:00
|
|
|
#ifndef hook_manager_hh_INCLUDED
|
|
|
|
#define hook_manager_hh_INCLUDED
|
2011-11-25 18:26:29 +04:00
|
|
|
|
|
|
|
#include "utils.hh"
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2012-01-23 17:56:43 +04:00
|
|
|
class Context;
|
2012-04-14 05:17:09 +04:00
|
|
|
typedef std::function<void (const String&, const Context&)> HookFunc;
|
2011-11-25 18:26:29 +04:00
|
|
|
|
2012-04-03 16:01:01 +04:00
|
|
|
class HookManager
|
2011-11-25 18:26:29 +04:00
|
|
|
{
|
|
|
|
public:
|
2012-06-07 17:29:44 +04:00
|
|
|
HookManager(HookManager& parent) : m_parent(&parent) {}
|
|
|
|
|
2012-04-14 05:17:09 +04:00
|
|
|
void add_hook(const String& hook_name, HookFunc hook);
|
|
|
|
void run_hook(const String& hook_name, const String& param,
|
2011-11-26 22:34:10 +04:00
|
|
|
const Context& context) const;
|
2011-11-25 18:26:29 +04:00
|
|
|
|
|
|
|
private:
|
2012-06-07 17:29:44 +04:00
|
|
|
HookManager()
|
|
|
|
: m_parent(nullptr) {}
|
|
|
|
// the only one allowed to construct a root hook manager
|
|
|
|
friend class GlobalHookManager;
|
|
|
|
|
|
|
|
HookManager* m_parent;
|
2012-04-14 05:17:09 +04:00
|
|
|
std::unordered_map<String, std::vector<HookFunc>> m_hook;
|
2011-11-25 18:26:29 +04:00
|
|
|
};
|
|
|
|
|
2012-04-03 16:01:01 +04:00
|
|
|
class GlobalHookManager : public HookManager,
|
|
|
|
public Singleton<GlobalHookManager>
|
2012-01-23 17:40:42 +04:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2011-11-25 18:26:29 +04:00
|
|
|
}
|
|
|
|
|
2012-04-03 16:01:01 +04:00
|
|
|
#endif // hook_manager_hh_INCLUDED
|
2011-11-25 18:26:29 +04:00
|
|
|
|