HooksManager: replace HookContext with Context

This commit is contained in:
Maxime Coste 2011-11-26 18:34:10 +00:00
parent 957446dee4
commit 68f3d24199
2 changed files with 7 additions and 20 deletions

View File

@ -9,14 +9,15 @@ void HooksManager::add_hook(const std::string& hook_name, HookFunc hook)
}
void HooksManager::run_hook(const std::string& hook_name,
const HookContext& context) const
const std::string& param,
const Context& context) const
{
auto hook_list_it = m_hooks.find(hook_name);
if (hook_list_it == m_hooks.end())
return;
for (auto& hook : hook_list_it->second)
hook(context);
hook(param, context);
}
}

View File

@ -1,7 +1,7 @@
#ifndef hooks_manager_hh_INCLUDED
#define hooks_manager_hh_INCLUDED
#include "window.hh"
#include "context.hh"
#include "utils.hh"
#include <unordered_map>
@ -9,28 +9,14 @@
namespace Kakoune
{
struct HookContext
{
Window* window;
Buffer* buffer;
std::string context;
HookContext(const std::string& context)
: window(nullptr), buffer(nullptr), context(context) {}
HookContext(const std::string& context, Window& window)
: window(&window), buffer(&window.buffer()), context(context) {}
HookContext(const std::string& context, Buffer& buffer)
: window(nullptr), buffer(&buffer), context(context) {}
};
typedef std::function<void (const HookContext&)> HookFunc;
typedef std::function<void (const std::string&, const Context&)> HookFunc;
class HooksManager : public Singleton<HooksManager>
{
public:
void add_hook(const std::string& hook_name, HookFunc hook);
void run_hook(const std::string& hook_name,
const HookContext& context) const;
void run_hook(const std::string& hook_name, const std::string& param,
const Context& context) const;
private:
std::unordered_map<std::string, std::vector<HookFunc>> m_hooks;