4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
11 * Full author contact details are available in file CREDITS.
17 #include "FuncRequest.h"
18 #include "KeySequence.h"
20 #include "support/strfwd.h"
32 /// Defines key maps and actions for key sequences
36 System, //< loaded from a bind file
37 UserBind, //< \bind loaded from user.bind
38 UserUnbind, //< \unbind loaded from user.bind, with corresponding
39 //< entry in system bind file
40 UserExtraUnbind //< \unbind loaded from user.bind, without
41 //< corresponding entry in system bind file.
44 MissingOK, //< It's OK if this file is missing.
45 Fallback, //< If missing, fallback to default "cua". This should only
46 //< be used when attempting to read the user-secified bind file.
47 Default //< Report error and return.
50 * Bind/Unbind a key sequence to an action.
51 * @return 0 on success, or position in string seq where error
53 * See KeySequence::parse for the syntax of the seq string
55 size_t bind(std::string const & seq, FuncRequest const & func);
56 size_t unbind(std::string const & seq, FuncRequest const & func);
59 * Define/Undefine an action for a key sequence.
60 * @param r internal recursion level
62 void bind(KeySequence * seq, FuncRequest const & func,
64 void unbind(KeySequence * seq, FuncRequest const & func,
68 /// returns the function bound to this key sequence, or
69 /// FuncRequest::unknown if no binding exists for it.
70 /// @param r an internal recursion counter
71 // FIXME Surely there's a better way to do that?
72 FuncRequest getBinding(KeySequence const & seq, unsigned int r = 0);
74 /// clear all bindings
77 /** Parse a bind file. If a valid unbind_map is given, put \unbind
78 * bindings to a separate KeyMap. This is used in the Shortcut preference
79 * dialog where main and user bind files are loaded separately so \unbind
80 * in user.bind can not nullify \bind in the master bind file.
82 * @param bind_file bind file
83 * @param unbind_map pointer to a KeyMap that holds \unbind bindings
84 * @param rt how to respond if the file can't be found
86 bool read(std::string const & bind_file, KeyMap * unbind_map = 0,
87 BindReadType rt = Default);
89 /** write to a bind file.
90 * @param append append to the bind_file instead of overwrite it
91 * @param unbind use \unbind instead of \bind, indicating this KeyMap
92 * actually record unbind maps.
94 void write(std::string const & bind_file, bool append, bool unbind = false) const;
97 * print all available keysyms
98 * @param forgui true if the string should use translations and
101 docstring const print(bool forgui) const;
104 * Look up a key press in the keymap.
105 * @param key the keysym
106 * @param mod the modifiers
107 * @param seq the current key sequence so far
108 * @return the action / LFUN_COMMAND_PREFIX / LFUN_UNKNOWN_ACTION
111 lookup(KeySymbol const & key, KeyModifier mod, KeySequence * seq) const;
114 typedef std::vector<KeySequence> Bindings;
116 /// Given an action, find all keybindings.
117 Bindings findBindings(FuncRequest const & func) const;
119 /// Given an action, print the keybindings.
120 docstring printBindings(FuncRequest const & func,
121 KeySequence::outputFormat format) const;
124 Binding(FuncRequest const & r, KeySequence const & s, ItemType t)
125 : request(r), sequence(s), tag(t) {}
127 KeySequence sequence;
128 KeyMap::ItemType tag;
130 typedef std::vector<Binding> BindingList;
132 * Return all lfun and their associated bindings.
133 * @param unbound list unbound (func without any keybinding) as well
134 * @param tag an optional tag to indicate the source of the bindinglist
136 BindingList listBindings(bool unbound, ItemType tag = System) const;
139 * Given an action, find the first 1-key binding (if it exists).
140 * The KeySymbol pointer is 0 is no key is found.
141 * [only used by the Qt/Mac frontend]
143 std::pair<KeySymbol, KeyModifier>
144 find1keybinding(FuncRequest const & func) const;
147 * Returns a string of the given keysym, with modifiers.
148 * @param key the key as a keysym
149 * @param mod the modifiers
151 static std::string const printKeySym(KeySymbol const & key,
156 typedef std::pair<KeyModifier, KeyModifier> ModifierPair;
164 /// Keymap for prefix keys
165 std::shared_ptr<KeyMap> prefixes;
166 /// Action for !prefix keys
177 bool read(support::FileName const & bind_file, KeyMap * unbind_map = 0);
179 ReturnValues readWithoutConv(support::FileName const & bind_file, KeyMap * unbind_map = 0);
182 * Given an action, find all keybindings
183 * @param func the action
184 * @param prefix a sequence to prepend the results
186 Bindings findBindings(FuncRequest const & func,
187 KeySequence const & prefix) const;
189 void listBindings(BindingList & list, KeySequence const & prefix,
192 /// is the table empty ?
193 bool empty() const { return table.empty(); }
195 typedef std::vector<Key> Table;
200 /// Implementation is in LyX.cpp
201 extern KeyMap & theTopLevelKeymap();