HooksManager: extract the Singleton version as GlobalHooksManager

This commit is contained in:
Maxime Coste 2012-01-23 13:40:42 +00:00
parent 73ae3d292f
commit db9040e29e
4 changed files with 12 additions and 7 deletions

View File

@ -27,7 +27,7 @@ Buffer::Buffer(const std::string& name, Type type,
{
BufferManager::instance().register_buffer(this);
HooksManager::instance().run_hook("BufCreate", name, Context(*this));
GlobalHooksManager::instance().run_hook("BufCreate", name, Context(*this));
compute_lines();
}

View File

@ -11,7 +11,7 @@ namespace Kakoune
typedef std::function<void (const std::string&, const Context&)> HookFunc;
class HooksManager : public Singleton<HooksManager>
class HooksManager
{
public:
void add_hook(const std::string& hook_name, HookFunc hook);
@ -22,6 +22,11 @@ private:
std::unordered_map<std::string, std::vector<HookFunc>> m_hooks;
};
class GlobalHooksManager : public HooksManager,
public Singleton<GlobalHooksManager>
{
};
}
#endif // hooks_manager_hh_INCLUDED

View File

@ -575,7 +575,7 @@ void add_hook(const CommandParameters& params, const Context& context)
CommandParameters hook_params(params.begin()+2, params.end());
HooksManager::instance().add_hook(
GlobalHooksManager::instance().add_hook(
params[0],
[=](const std::string& param, const Context& context) {
if (boost::regex_match(param, boost::regex(params[1])))
@ -955,7 +955,7 @@ int main(int argc, char* argv[])
RegisterManager register_manager;
HighlighterRegistry highlighter_registry;
FilterRegistry filter_registry;
HooksManager hooks_manager;
GlobalHooksManager hooks_manager;
command_manager.register_command(std::vector<std::string>{ "e", "edit" }, edit,
CommandManager::None,

View File

@ -57,7 +57,7 @@ Window::Window(Buffer& buffer)
HighlighterRegistry& registry = HighlighterRegistry::instance();
HooksManager::instance().run_hook("WinCreate", buffer.name(),
GlobalHooksManager::instance().run_hook("WinCreate", buffer.name(),
Context(*this));
registry.add_highlighter_to_window(*this, "expand_tabs", HighlighterParameters());
@ -465,7 +465,7 @@ IncrementalInserter::~IncrementalInserter()
m_window.push_selections();
try
{
HooksManager::instance().run_hook("WinInsertEnd", "", Context(m_window));
GlobalHooksManager::instance().run_hook("WinInsertEnd", "", Context(m_window));
}
catch (runtime_error& e) {}
m_window.pop_selections();