From a1ff9999f526fbbd560f6fa323ffbb68e2e6936f Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 23 Jan 2012 13:58:43 +0000 Subject: [PATCH] the hook command takes a first parameter to specify the hook owner currently 'global' and 'window' are accepted owners. 'window' will add the hook to the current context window. --- src/main.cc | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main.cc b/src/main.cc index a0512932..94e7e769 100644 --- a/src/main.cc +++ b/src/main.cc @@ -571,17 +571,22 @@ void rm_filter(const CommandParameters& params, const Context& context) void add_hook(const CommandParameters& params, const Context& context) { - if (params.size() < 3) + if (params.size() < 4) throw wrong_argument_count(); - CommandParameters hook_params(params.begin()+2, params.end()); + CommandParameters hook_params(params.begin()+3, params.end()); - GlobalHooksManager::instance().add_hook( - params[0], - [=](const std::string& param, const Context& context) { - if (boost::regex_match(param, boost::regex(params[1]))) - CommandManager::instance().execute(hook_params, context); - }); + auto hook_func = [=](const std::string& param, const Context& context) { + if (boost::regex_match(param, boost::regex(params[2]))) + CommandManager::instance().execute(hook_params, context); + }; + + if (params[0] == "global") + GlobalHooksManager::instance().add_hook(params[1], hook_func); + else if (params[0] == "window") + context.window().hooks_manager().add_hook(params[1], hook_func); + else + print_status("error: no such hook container " + params[0]); } void exec_commands_in_file(const CommandParameters& params,