keymap_manager.hh (1587B)
1 #ifndef keymap_manager_hh_INCLUDED 2 #define keymap_manager_hh_INCLUDED 3 4 #include "keys.hh" 5 #include "string.hh" 6 #include "hash_map.hh" 7 #include "vector.hh" 8 9 namespace Kakoune 10 { 11 12 enum class KeymapMode : char 13 { 14 None, 15 Normal, 16 Insert, 17 Prompt, 18 Menu, 19 Goto, 20 View, 21 User, 22 Object, 23 Combine, 24 FirstUserMode, 25 }; 26 27 class KeymapManager 28 { 29 public: 30 using KeyList = Vector<Key, MemoryDomain::Mapping>; 31 struct KeymapInfo 32 { 33 KeyList keys; 34 String docstring; 35 bool atomic = false; 36 }; 37 38 KeymapManager(KeymapManager& parent) : m_parent(&parent) {} 39 40 void reparent(KeymapManager& parent) { m_parent = &parent; } 41 42 void map_key(Key key, KeymapMode mode, KeyList mapping, String docstring, 43 bool atomic = false); 44 void unmap_key(Key key, KeymapMode mode); 45 void unmap_keys(KeymapMode mode); 46 47 KeyList get_mapped_keys(KeymapMode mode) const; 48 const KeymapInfo* get_mapping(Key key, KeymapMode mode) const; 49 50 using UserModeList = Vector<String>; 51 UserModeList& user_modes() { 52 if (m_parent) 53 return m_parent->user_modes(); 54 return m_user_modes; 55 } 56 void add_user_mode(String user_mode_name); 57 58 private: 59 KeymapManager() 60 : m_parent(nullptr) {} 61 // the only one allowed to construct a root map manager 62 friend class Scope; 63 64 KeymapManager* m_parent; 65 using KeyAndMode = std::pair<Key, KeymapMode>; 66 HashMap<KeyAndMode, KeymapInfo, MemoryDomain::Mapping> m_mapping; 67 68 UserModeList m_user_modes; 69 }; 70 71 } 72 73 #endif // keymap_manager_hh_INCLUDED