rename HooksManager to HookManager

This commit is contained in:
Maxime Coste 2012-04-03 12:01:01 +00:00
parent 2cd318e50d
commit 9444c84b1c
7 changed files with 49 additions and 49 deletions

View File

@ -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 <algorithm>
@ -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()

29
src/hook_manager.cc Normal file
View File

@ -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&) {}
}
}
}

View File

@ -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<void (const std::string&, const Context&)> 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<std::string, std::vector<HookFunc>> m_hooks;
std::unordered_map<std::string, std::vector<HookFunc>> m_hook;
};
class GlobalHooksManager : public HooksManager,
public Singleton<GlobalHooksManager>
class GlobalHookManager : public HookManager,
public Singleton<GlobalHookManager>
{
};
}
#endif // hooks_manager_hh_INCLUDED
#endif // hook_manager_hh_INCLUDED

View File

@ -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&) {}
}
}
}

View File

@ -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();

View File

@ -2,7 +2,7 @@
#include "assert.hh"
#include "highlighter_registry.hh"
#include "hooks_manager.hh"
#include "hook_manager.hh"
#include "context.hh"
#include <algorithm>
@ -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();
}

View File

@ -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;
};
}