HooksManager: replace HookContext with Context
This commit is contained in:
parent
957446dee4
commit
68f3d24199
|
@ -9,14 +9,15 @@ void HooksManager::add_hook(const std::string& hook_name, HookFunc hook)
|
||||||
}
|
}
|
||||||
|
|
||||||
void HooksManager::run_hook(const std::string& hook_name,
|
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);
|
auto hook_list_it = m_hooks.find(hook_name);
|
||||||
if (hook_list_it == m_hooks.end())
|
if (hook_list_it == m_hooks.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (auto& hook : hook_list_it->second)
|
for (auto& hook : hook_list_it->second)
|
||||||
hook(context);
|
hook(param, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef hooks_manager_hh_INCLUDED
|
#ifndef hooks_manager_hh_INCLUDED
|
||||||
#define hooks_manager_hh_INCLUDED
|
#define hooks_manager_hh_INCLUDED
|
||||||
|
|
||||||
#include "window.hh"
|
#include "context.hh"
|
||||||
#include "utils.hh"
|
#include "utils.hh"
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
@ -9,28 +9,14 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
struct HookContext
|
typedef std::function<void (const std::string&, const Context&)> HookFunc;
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
class HooksManager : public Singleton<HooksManager>
|
class HooksManager : public Singleton<HooksManager>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void add_hook(const std::string& hook_name, HookFunc hook);
|
void add_hook(const std::string& hook_name, HookFunc hook);
|
||||||
void run_hook(const std::string& hook_name,
|
void run_hook(const std::string& hook_name, const std::string& param,
|
||||||
const HookContext& context) const;
|
const Context& context) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, std::vector<HookFunc>> m_hooks;
|
std::unordered_map<std::string, std::vector<HookFunc>> m_hooks;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user