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"
19 #include "frontends/KeyModifier.h"
20 #include "frontends/KeySymbol.h"
22 #include "support/docstream.h"
24 #include <boost/shared_ptr.hpp>
25 #include <boost/tuple/tuple.hpp>
35 /// Defines key maps and actions for key sequences
39 * Bind a key sequence to an action.
40 * @return 0 on success, or position in string seq where error
42 * See KeySequence::parse for the syntax of the seq string
44 size_t bind(std::string const & seq, FuncRequest const & func);
46 // Unbind a key sequence
47 size_t unbind(std::string const & seq, FuncRequest const & func);
49 // if a keybinding has been defined.
50 bool hasBinding(KeySequence const & seq, FuncRequest const & func,
56 /** Parse a bind file. If a valid unbind_map is given, put \unbind
57 * bindings to a separate KeyMap. This is used in the Shortcut preference
58 * dialog where main and user bind files are loaded separately so \unbind
59 * in user.bind can not nullify \bind in the master bind file.
61 * @param bind_file bind file
62 * @param unbind_map pointer to a KeyMap that holds \unbind bindings
64 bool read(std::string const & bind_file, KeyMap * unbind_map = NULL);
66 /** write to a bind file.
67 * @param append append to the bind_file instead of overwrite it
68 * @param unbind use \unbind instead of \bind, indicating this KeyMap
69 * actually record unbind maps.
71 void write(std::string const & bind_file, bool append, bool unbind=false) const;
74 * print all available keysyms
75 * @param forgui true if the string should use translations and
78 docstring const print(bool forgui) const;
81 * Look up a key press in the keymap.
82 * @param key the keysym
83 * @param mod the modifiers
84 * @param seq the current key sequence so far
85 * @return the action / LFUN_COMMAND_PREFIX / LFUN_UNKNOWN_ACTION
88 lookup(KeySymbol const & key, KeyModifier mod, KeySequence * seq) const;
91 typedef std::deque<KeySequence> Bindings;
93 /// Given an action, find all keybindings.
94 Bindings findbindings(FuncRequest const & func) const;
96 /// Given an action, print the keybindings.
97 docstring const printbindings(FuncRequest const & func) const;
99 typedef boost::tuple<FuncRequest, KeySequence, int> Binding;
100 typedef std::vector<Binding> BindingList;
102 * Return all lfun and their associated bindings.
103 * @param unbound list unbound (func without any keybinding) as well
104 * @param tag an optional tag to indicate the source of the bindinglist
106 BindingList listBindings(bool unbound, int tag = 0) const;
109 * Given an action, find the first 1-key binding (if it exists).
110 * The KeySymbol pointer is 0 is no key is found.
111 * [only used by the Qt/Mac frontend]
113 std::pair<KeySymbol, KeyModifier>
114 find1keybinding(FuncRequest const & func) const;
118 * Returns a string of the given keysym, with modifiers.
119 * @param key the key as a keysym
120 * @param mod the modifiers
122 static std::string const printKeySym(KeySymbol const & key,
125 typedef std::pair<KeyModifier, KeyModifier> ModifierPair;
137 /// Keymap for prefix keys
138 boost::shared_ptr<KeyMap> table;
140 /// Action for !prefix keys
145 * Define an action for a key sequence.
146 * @param r internal recursion level
148 void defkey(KeySequence * seq, FuncRequest const & func,
150 void delkey(KeySequence * seq, FuncRequest const & func,
154 * Given an action, find all keybindings
155 * @param func the action
156 * @param prefix a sequence to prepend the results
158 Bindings findbindings(FuncRequest const & func,
159 KeySequence const & prefix) const;
161 void listBindings(BindingList & list, KeySequence const & prefix,
164 /// is the table empty ?
165 bool empty() const { return table.empty(); }
167 typedef std::vector<Key> Table;
172 /// Implementation is in LyX.cpp
173 extern KeyMap & theTopLevelKeymap();