X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FKeyMap.h;h=acb0c22110ccdd0093a52aadd9e4a0802dfee1a0;hb=9337d73f1f9a6d4dae2e239e9f679a7452660c40;hp=bb28d37433e4df7c23d0fef004cef112628cff5d;hpb=c4033d401202ffc57b5a04ef9cf83b494b7ddfa0;p=lyx.git diff --git a/src/KeyMap.h b/src/KeyMap.h index bb28d37433..acb0c22110 100644 --- a/src/KeyMap.h +++ b/src/KeyMap.h @@ -15,35 +15,62 @@ #define KEYMAP_H #include "FuncRequest.h" +#include "KeySequence.h" -#include "frontends/KeyModifier.h" -#include "frontends/KeySymbol.h" - -#include "support/docstream.h" +#include "support/strfwd.h" #include #include -#include namespace lyx { -class KeySequence; - /// Defines key maps and actions for key sequences class KeyMap { public: /** - * Bind a key sequence to an action. + * Bind/Unbind a key sequence to an action. * @return 0 on success, or position in string seq where error * occurs. * See KeySequence::parse for the syntax of the seq string */ size_t bind(std::string const & seq, FuncRequest const & func); + size_t unbind(std::string const & seq, FuncRequest const & func); - // Parse a bind file - bool read(std::string const & bind_file); + /** + * Define/Undefine an action for a key sequence. + * @param r internal recursion level + */ + void bind(KeySequence * seq, FuncRequest const & func, + unsigned int r = 0); + void unbind(KeySequence * seq, FuncRequest const & func, + unsigned int r = 0); + + + // if a keybinding has been defined. + bool hasBinding(KeySequence const & seq, FuncRequest const & func, + unsigned int r = 0); + + // clear all bindings + void clear(); + + /** Parse a bind file. If a valid unbind_map is given, put \unbind + * bindings to a separate KeyMap. This is used in the Shortcut preference + * dialog where main and user bind files are loaded separately so \unbind + * in user.bind can not nullify \bind in the master bind file. + * + * @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); + + /** 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; /** * print all available keysyms @@ -63,13 +90,28 @@ public: 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) + : request(r), sequence(s), tag(t) {} + FuncRequest request; + KeySequence sequence; + int tag; + }; + typedef std::vector BindingList; + /** + * Return all lfun and their associated bindings. + * @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; /** * Given an action, find the first 1-key binding (if it exists). @@ -90,36 +132,30 @@ public: 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; }; - /** - * Define an action for a key sequence. - * @param r internal recursion level - */ - void defkey(KeySequence * seq, FuncRequest const & func, - unsigned int r = 0); - /** * Given an action, find all keybindings * @param func the action * @param prefix a sequence to prepend the results */ - Bindings findbindings(FuncRequest const & func, + Bindings findBindings(FuncRequest const & func, KeySequence const & prefix) const; + + void listBindings(BindingList & list, KeySequence const & prefix, + int tag) const; /// is the table empty ? bool empty() const { return table.empty(); }