From 68f3d241992bcf555c5d6a54d4bf8809848ec91f Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 26 Nov 2011 18:34:10 +0000 Subject: [PATCH] HooksManager: replace HookContext with Context --- src/hooks_manager.cc | 5 +++-- src/hooks_manager.hh | 22 ++++------------------ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/hooks_manager.cc b/src/hooks_manager.cc index 7dbbaf42..0a9ef1ce 100644 --- a/src/hooks_manager.cc +++ b/src/hooks_manager.cc @@ -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); } } diff --git a/src/hooks_manager.hh b/src/hooks_manager.hh index 81549f60..5a96aa83 100644 --- a/src/hooks_manager.hh +++ b/src/hooks_manager.hh @@ -1,7 +1,7 @@ #ifndef hooks_manager_hh_INCLUDED #define hooks_manager_hh_INCLUDED -#include "window.hh" +#include "context.hh" #include "utils.hh" #include @@ -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 HookFunc; +typedef std::function HookFunc; class HooksManager : public Singleton { 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> m_hooks;