1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-24 20:13:00 +03:00
kakoune/src/hook_manager.hh

44 lines
934 B
C++
Raw Normal View History

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 "idvaluemap.hh"
2011-11-25 18:26:29 +04:00
#include "utils.hh"
#include <unordered_map>
namespace Kakoune
{
2013-02-18 17:00:43 +04:00
struct Context;
2013-01-17 16:44:14 +04:00
typedef std::function<void (const String&, 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:
HookManager(HookManager& parent) : m_parent(&parent) {}
void add_hook(const String& hook_name, String id, HookFunc hook);
void remove_hooks(const String& id);
void run_hook(const String& hook_name, const String& param,
2013-01-17 16:44:14 +04:00
Context& context) const;
2011-11-25 18:26:29 +04:00
private:
HookManager()
: m_parent(nullptr) {}
// the only one allowed to construct a root hook manager
friend class GlobalHooks;
HookManager* m_parent;
std::unordered_map<String, idvaluemap<String, HookFunc>> m_hook;
2011-11-25 18:26:29 +04:00
};
class GlobalHooks : public HookManager,
public Singleton<GlobalHooks>
{
};
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