X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FKeyMap.h;h=ac9de6298bf8f99db9f315246bedc7a344c1879e;hb=88e739b44b5c4a23c5e64cf470c0fb49a7bcbd6c;hp=acb0c22110ccdd0093a52aadd9e4a0802dfee1a0;hpb=c08309a9e284026a207f428afb4c4b4b5f0fbb9a;p=lyx.git diff --git a/src/KeyMap.h b/src/KeyMap.h index acb0c22110..ac9de6298b 100644 --- a/src/KeyMap.h +++ b/src/KeyMap.h @@ -4,7 +4,7 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author Lars Gullik Bjønnes + * \author Lars Gullik Bjønnes * \author Jean-Marc Lasgouttes * \author John Levon * @@ -19,16 +19,33 @@ #include "support/strfwd.h" -#include - +#include #include namespace lyx { +namespace support { + class FileName; +} + /// 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. + }; + enum BindReadType { + MissingOK, //< It's OK if this file is missing. + Fallback, //< If missing, fallback to default "cua". This should only + //< be used when attempting to read the user-secified bind file. + Default //< Report error and return. + }; /** * Bind/Unbind a key sequence to an action. * @return 0 on success, or position in string seq where error @@ -48,29 +65,35 @@ 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; + /// * FuncRequest::prefix if this is the start of longer keysequences + /// @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 + /** 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 + * @param rt how to respond if the file can't be found + * @param i18n whether to search in localized folders */ - bool read(std::string const & bind_file, KeyMap * unbind_map = NULL); + bool read(std::string const & bind_file, KeyMap * unbind_map = 0, + BindReadType rt = Default, bool i18n = true); /** 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 @@ -87,7 +110,7 @@ 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::vector Bindings; @@ -96,22 +119,24 @@ public: Bindings findBindings(FuncRequest const & func) const; /// Given an action, print the keybindings. - docstring printBindings(FuncRequest const & func) const; + docstring printBindings(FuncRequest const & func, + KeySequence::outputFormat format, + bool const untranslated = false) 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; /** * 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; + BindingList listBindings(bool unbound, ItemType tag = System) const; /** * Given an action, find the first 1-key binding (if it exists). @@ -119,8 +144,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. @@ -130,10 +154,10 @@ public: static std::string const printKeySym(KeySymbol const & key, KeyModifier mod); +private: + /// typedef std::pair ModifierPair; - -private: /// struct Key { /// Keysym @@ -141,21 +165,32 @@ private: /// Modifier masks ModifierPair mod; /// Keymap for prefix keys - boost::shared_ptr table; + std::shared_ptr prefixes; /// Action for !prefix keys FuncRequest func; }; + enum ReturnValues { + ReadOK, + ReadError, + FileError, + FormatMismatch + }; + /// + bool read(support::FileName const & bind_file, KeyMap * unbind_map = 0); + /// + ReturnValues readWithoutConv(support::FileName const & bind_file, KeyMap * unbind_map = 0); + /** * Given an action, find all keybindings * @param func the action * @param prefix a sequence to prepend the results */ Bindings findBindings(FuncRequest const & func, - KeySequence const & prefix) const; - + 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(); }