X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FKeyMap.h;h=cc7c15595915cf3ec9ea94e65125f8e4d964536c;hb=d6f1915684328c6e3fe61c6eef8846b5cabec334;hp=b9f8b28641b4a4c184a140d4ca935f2b8bfbf849;hpb=65ce182131727603e99e1659a86a3e90b41dcab4;p=lyx.git diff --git a/src/KeyMap.h b/src/KeyMap.h index b9f8b28641..cc7c155959 100644 --- a/src/KeyMap.h +++ b/src/KeyMap.h @@ -22,7 +22,6 @@ #include #include -#include namespace lyx { @@ -30,6 +29,14 @@ namespace lyx { /// Defines key maps and actions for key sequences class KeyMap { public: + enum ItemType { + System, //< loaded from a bind file + UserBind, //< \bind loaded from user.bind + UserUnbind, //< \unbind loaded from user.bind, with corresponding + //< entry in system bind file + UserExtraUnbind //< \unbind loaded from user.bind, without + //< corresponding entry in system bind file. + }; /** * Bind/Unbind a key sequence to an action. * @return 0 on success, or position in string seq where error @@ -49,11 +56,13 @@ public: unsigned int r = 0); - // if a keybinding has been defined. - bool hasBinding(KeySequence const & seq, FuncRequest const & func, - unsigned int r = 0); + /// returns the function bound to this key sequence, or + /// FuncRequest::unknown if no binding exists for it. + /// @param r an internal recursion counter + // FIXME Surely there's a better way to do that? + FuncRequest getBinding(KeySequence const & seq, unsigned int r = 0); - // clear all bindings + /// clear all bindings void clear(); /** Parse a bind file. If a valid unbind_map is given, put \unbind @@ -64,14 +73,14 @@ public: * @param bind_file bind file * @param unbind_map pointer to a KeyMap that holds \unbind bindings */ - bool read(std::string const & bind_file, KeyMap * unbind_map = NULL); + bool read(std::string const & bind_file, KeyMap * unbind_map = 0); /** write to a bind file. * @param append append to the bind_file instead of overwrite it * @param unbind use \unbind instead of \bind, indicating this KeyMap * actually record unbind maps. */ - void write(std::string const & bind_file, bool append, bool unbind=false) const; + void write(std::string const & bind_file, bool append, bool unbind = false) const; /** * print all available keysyms @@ -88,23 +97,23 @@ public: * @return the action / LFUN_COMMAND_PREFIX / LFUN_UNKNOWN_ACTION */ FuncRequest const & - lookup(KeySymbol const & key, KeyModifier mod, KeySequence * seq) const; + lookup(KeySymbol const & key, KeyModifier mod, KeySequence * seq) const; /// - typedef std::deque Bindings; + typedef std::vector Bindings; /// Given an action, find all keybindings. - Bindings findbindings(FuncRequest const & func) const; + Bindings findBindings(FuncRequest const & func) const; /// Given an action, print the keybindings. - docstring const printbindings(FuncRequest const & func) const; + docstring printBindings(FuncRequest const & func) const; struct Binding { - Binding(FuncRequest const & r, KeySequence const & s, int t) + Binding(FuncRequest const & r, KeySequence const & s, ItemType t) : request(r), sequence(s), tag(t) {} FuncRequest request; KeySequence sequence; - int tag; + KeyMap::ItemType tag; }; typedef std::vector BindingList; /** @@ -112,7 +121,7 @@ public: * @param unbound list unbound (func without any keybinding) as well * @param tag an optional tag to indicate the source of the bindinglist */ - BindingList listBindings(bool unbound, int tag = 0) const; + BindingList listBindings(bool unbound, ItemType tag = System) const; /** * Given an action, find the first 1-key binding (if it exists). @@ -120,8 +129,7 @@ public: * [only used by the Qt/Mac frontend] */ std::pair - find1keybinding(FuncRequest const & func) const; - + find1keybinding(FuncRequest const & func) const; /** * Returns a string of the given keysym, with modifiers. @@ -131,21 +139,18 @@ public: static std::string const printKeySym(KeySymbol const & key, KeyModifier mod); +private: + /// typedef std::pair ModifierPair; - -private: /// struct Key { /// Keysym KeySymbol code; - /// Modifier masks ModifierPair mod; - /// Keymap for prefix keys boost::shared_ptr table; - /// Action for !prefix keys FuncRequest func; }; @@ -155,11 +160,11 @@ private: * @param func the action * @param prefix a sequence to prepend the results */ - Bindings findbindings(FuncRequest const & func, - KeySequence const & prefix) const; + Bindings findBindings(FuncRequest const & func, + KeySequence const & prefix) const; void listBindings(BindingList & list, KeySequence const & prefix, - int tag) const; + ItemType tag) const; /// is the table empty ? bool empty() const { return table.empty(); }