From 9444c84b1cdb3b87b3076daf07c806118d2030bf Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 3 Apr 2012 12:01:01 +0000 Subject: [PATCH] rename HooksManager to HookManager --- src/buffer.cc | 6 ++--- src/hook_manager.cc | 29 +++++++++++++++++++++++ src/{hooks_manager.hh => hook_manager.hh} | 14 +++++------ src/hooks_manager.cc | 29 ----------------------- src/main.cc | 8 +++---- src/window.cc | 6 ++--- src/window.hh | 6 ++--- 7 files changed, 49 insertions(+), 49 deletions(-) create mode 100644 src/hook_manager.cc rename src/{hooks_manager.hh => hook_manager.hh} (65%) delete mode 100644 src/hooks_manager.cc diff --git a/src/buffer.cc b/src/buffer.cc index 1c37e2f2..13aa5b00 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -4,7 +4,7 @@ #include "window.hh" #include "assert.hh" #include "utils.hh" -#include "hooks_manager.hh" +#include "hook_manager.hh" #include "context.hh" #include @@ -33,9 +33,9 @@ Buffer::Buffer(const std::string& name, Type type, apply_modification(Modification::make_insert(begin(), initial_content)); if (type == Type::NewFile) - GlobalHooksManager::instance().run_hook("BufCreate", name, Context(*this)); + GlobalHookManager::instance().run_hook("BufCreate", name, Context(*this)); else if (type == Type::File) - GlobalHooksManager::instance().run_hook("BufOpen", name, Context(*this)); + GlobalHookManager::instance().run_hook("BufOpen", name, Context(*this)); } Buffer::~Buffer() diff --git a/src/hook_manager.cc b/src/hook_manager.cc new file mode 100644 index 00000000..283d7b3d --- /dev/null +++ b/src/hook_manager.cc @@ -0,0 +1,29 @@ +#include "hook_manager.hh" + +namespace Kakoune +{ + +void HookManager::add_hook(const std::string& hook_name, HookFunc hook) +{ + m_hook[hook_name].push_back(hook); +} + +void HookManager::run_hook(const std::string& hook_name, + const std::string& param, + const Context& context) const +{ + auto hook_list_it = m_hook.find(hook_name); + if (hook_list_it == m_hook.end()) + return; + + for (auto& hook : hook_list_it->second) + { + try + { + hook(param, context); + } + catch (runtime_error&) {} + } +} + +} diff --git a/src/hooks_manager.hh b/src/hook_manager.hh similarity index 65% rename from src/hooks_manager.hh rename to src/hook_manager.hh index 37d6454a..85b6cc28 100644 --- a/src/hooks_manager.hh +++ b/src/hook_manager.hh @@ -1,5 +1,5 @@ -#ifndef hooks_manager_hh_INCLUDED -#define hooks_manager_hh_INCLUDED +#ifndef hook_manager_hh_INCLUDED +#define hook_manager_hh_INCLUDED #include "utils.hh" @@ -11,7 +11,7 @@ namespace Kakoune class Context; typedef std::function HookFunc; -class HooksManager +class HookManager { public: void add_hook(const std::string& hook_name, HookFunc hook); @@ -19,15 +19,15 @@ public: const Context& context) const; private: - std::unordered_map> m_hooks; + std::unordered_map> m_hook; }; -class GlobalHooksManager : public HooksManager, - public Singleton +class GlobalHookManager : public HookManager, + public Singleton { }; } -#endif // hooks_manager_hh_INCLUDED +#endif // hook_manager_hh_INCLUDED diff --git a/src/hooks_manager.cc b/src/hooks_manager.cc deleted file mode 100644 index 239e429d..00000000 --- a/src/hooks_manager.cc +++ /dev/null @@ -1,29 +0,0 @@ -#include "hooks_manager.hh" - -namespace Kakoune -{ - -void HooksManager::add_hook(const std::string& hook_name, HookFunc hook) -{ - m_hooks[hook_name].push_back(hook); -} - -void HooksManager::run_hook(const std::string& hook_name, - 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) - { - try - { - hook(param, context); - } - catch (runtime_error&) {} - } -} - -} diff --git a/src/main.cc b/src/main.cc index 8e1c4666..f9232eb7 100644 --- a/src/main.cc +++ b/src/main.cc @@ -11,7 +11,7 @@ #include "highlighter_registry.hh" #include "filters.hh" #include "filter_registry.hh" -#include "hooks_manager.hh" +#include "hook_manager.hh" #include "context.hh" #include "ncurses.hh" @@ -392,9 +392,9 @@ void add_hook(const CommandParameters& params, const Context& context) }; if (params[0] == "global") - GlobalHooksManager::instance().add_hook(params[1], hook_func); + GlobalHookManager::instance().add_hook(params[1], hook_func); else if (params[0] == "window") - context.window().hooks_manager().add_hook(params[1], hook_func); + context.window().hook_manager().add_hook(params[1], hook_func); else NCurses::print_status("error: no such hook container " + params[0]); } @@ -914,7 +914,7 @@ int main(int argc, char* argv[]) RegisterManager register_manager; HighlighterRegistry highlighter_registry; FilterRegistry filter_registry; - GlobalHooksManager hooks_manager; + GlobalHookManager hook_manager; run_unit_tests(); diff --git a/src/window.cc b/src/window.cc index e8aa4a4e..2a0b2a86 100644 --- a/src/window.cc +++ b/src/window.cc @@ -2,7 +2,7 @@ #include "assert.hh" #include "highlighter_registry.hh" -#include "hooks_manager.hh" +#include "hook_manager.hh" #include "context.hh" #include @@ -18,7 +18,7 @@ Window::Window(Buffer& buffer) { HighlighterRegistry& registry = HighlighterRegistry::instance(); - GlobalHooksManager::instance().run_hook("WinCreate", buffer.name(), + GlobalHookManager::instance().run_hook("WinCreate", buffer.name(), Context(*this)); registry.add_highlighter_to_window(*this, "expand_tabs", HighlighterParameters()); @@ -129,7 +129,7 @@ std::string Window::status_line() const void Window::on_incremental_insertion_end() { push_selections(); - hooks_manager().run_hook("InsertEnd", "", Context(*this)); + hook_manager().run_hook("InsertEnd", "", Context(*this)); pop_selections(); } diff --git a/src/window.hh b/src/window.hh index 0d7b924c..9105d04a 100644 --- a/src/window.hh +++ b/src/window.hh @@ -8,7 +8,7 @@ #include "completion.hh" #include "highlighter.hh" #include "highlighter_group.hh" -#include "hooks_manager.hh" +#include "hook_manager.hh" namespace Kakoune { @@ -38,7 +38,7 @@ public: HighlighterGroup& highlighters() { return m_highlighters; } - HooksManager& hooks_manager() { return m_hooks_manager; } + HookManager& hook_manager() { return m_hook_manager; } private: friend class Buffer; @@ -56,7 +56,7 @@ private: HighlighterGroup m_highlighters; - HooksManager m_hooks_manager; + HookManager m_hook_manager; }; }