home/src/keymap_manager.hh

60 lines
1.2 KiB
C++
Raw Normal View History

2013-10-25 01:01:17 +02:00
#ifndef keymap_manager_hh_INCLUDED
#define keymap_manager_hh_INCLUDED
#include "array_view.hh"
2013-10-25 01:01:17 +02:00
#include "keys.hh"
#include "hash.hh"
#include "string.hh"
#include "hash_map.hh"
2015-01-12 14:45:44 +01:00
#include "vector.hh"
2013-10-25 01:01:17 +02:00
namespace Kakoune
{
2015-04-11 18:22:37 +02:00
enum class KeymapMode : char
2013-10-25 01:01:17 +02:00
{
None,
Normal,
Insert,
Prompt,
Menu,
Goto,
View,
User,
2015-07-01 17:47:42 +02:00
Object,
2013-10-25 01:01:17 +02:00
};
class KeymapManager
{
public:
KeymapManager(KeymapManager& parent) : m_parent(&parent) {}
2015-01-12 14:45:44 +01:00
using KeyList = Vector<Key, MemoryDomain::Mapping>;
void map_key(Key key, KeymapMode mode, KeyList mapping, String docstring);
2013-10-25 01:01:17 +02:00
void unmap_key(Key key, KeymapMode mode);
bool is_mapped(Key key, KeymapMode mode) const;
KeyList get_mapped_keys(KeymapMode mode) const;
2017-11-24 10:25:36 +01:00
struct KeymapInfo
{
KeyList keys;
String docstring;
};
2017-11-24 10:25:36 +01:00
const KeymapInfo& get_mapping(Key key, KeymapMode mode) const;
2013-10-25 01:01:17 +02:00
private:
KeymapManager()
: m_parent(nullptr) {}
// the only one allowed to construct a root map manager
friend class Scope;
2013-10-25 01:01:17 +02:00
KeymapManager* m_parent;
using KeyAndMode = std::pair<Key, KeymapMode>;
2017-11-24 10:25:36 +01:00
HashMap<KeyAndMode, KeymapInfo, MemoryDomain::Mapping> m_mapping;
2013-10-25 01:01:17 +02:00
};
}
#endif // keymap_manager_hh_INCLUDED