2012-04-03 14:01:01 +02:00
|
|
|
#ifndef hook_manager_hh_INCLUDED
|
|
|
|
#define hook_manager_hh_INCLUDED
|
2011-11-25 15:26:29 +01:00
|
|
|
|
2017-03-07 02:12:37 +01:00
|
|
|
#include "hash_map.hh"
|
2014-12-23 14:54:09 +01:00
|
|
|
#include "completion.hh"
|
2016-05-15 11:37:42 +02:00
|
|
|
#include "safe_ptr.hh"
|
2011-11-25 15:26:29 +01:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2013-11-11 20:10:49 +01:00
|
|
|
class Context;
|
2017-10-02 08:20:36 +02:00
|
|
|
class Regex;
|
2011-11-25 15:26:29 +01:00
|
|
|
|
2018-04-17 00:27:09 +02:00
|
|
|
enum class HookFlags
|
|
|
|
{
|
|
|
|
None = 0,
|
2018-08-02 11:52:48 +02:00
|
|
|
Always = 1 << 0,
|
|
|
|
Once = 1 << 1
|
2018-04-17 00:27:09 +02:00
|
|
|
};
|
|
|
|
constexpr bool with_bit_ops(Meta::Type<HookFlags>) { return true; }
|
|
|
|
|
2016-05-15 11:37:42 +02:00
|
|
|
class HookManager : public SafeCountable
|
2011-11-25 15:26:29 +01:00
|
|
|
{
|
|
|
|
public:
|
2017-10-02 08:20:36 +02:00
|
|
|
HookManager(HookManager& parent);
|
|
|
|
~HookManager();
|
2012-06-07 15:29:44 +02:00
|
|
|
|
2018-04-17 00:27:09 +02:00
|
|
|
void add_hook(StringView hook_name, String group, HookFlags flags,
|
|
|
|
Regex filter, String commands);
|
2014-06-16 21:42:12 +02:00
|
|
|
void remove_hooks(StringView group);
|
2014-07-21 22:14:32 +02:00
|
|
|
CandidateList complete_hook_group(StringView prefix, ByteCount pos_in_token);
|
2015-03-05 15:59:27 +01:00
|
|
|
void run_hook(StringView hook_name, StringView param,
|
2018-08-02 11:52:48 +02:00
|
|
|
Context& context);
|
2011-11-25 15:26:29 +01:00
|
|
|
|
|
|
|
private:
|
2017-10-02 08:20:36 +02:00
|
|
|
HookManager();
|
2012-06-07 15:29:44 +02:00
|
|
|
// the only one allowed to construct a root hook manager
|
2014-10-30 15:00:42 +01:00
|
|
|
friend class Scope;
|
2012-06-07 15:29:44 +02:00
|
|
|
|
2017-10-02 08:20:36 +02:00
|
|
|
struct Hook;
|
2017-06-07 10:34:07 +02:00
|
|
|
|
2016-05-15 11:37:42 +02:00
|
|
|
SafePtr<HookManager> m_parent;
|
2017-06-07 13:15:16 +02:00
|
|
|
HashMap<String, Vector<std::unique_ptr<Hook>, MemoryDomain::Hooks>, MemoryDomain::Hooks> m_hooks;
|
|
|
|
|
2016-11-28 14:59:55 +01:00
|
|
|
mutable Vector<std::pair<StringView, StringView>, MemoryDomain::Hooks> m_running_hooks;
|
2017-06-07 13:15:16 +02:00
|
|
|
mutable Vector<std::unique_ptr<Hook>, MemoryDomain::Hooks> m_hooks_trash;
|
2011-11-25 15:26:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-03 14:01:01 +02:00
|
|
|
#endif // hook_manager_hh_INCLUDED
|