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/strfwd.h"
24 #include <boost/shared_ptr.hpp>
25 #include <boost/tuple/tuple.hpp>
35 /// Defines key maps and actions for key sequences
39 * Bind/Unbind 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);
45 size_t unbind(std::string const & seq, FuncRequest const & func);
48 * Define/Undefine an action for a key sequence.
49 * @param r internal recursion level
51 void bind(KeySequence * seq, FuncRequest const & func,
53 void unbind(KeySequence * seq, FuncRequest const & func,
57 // if a keybinding has been defined.
58 bool hasBinding(KeySequence const & seq, FuncRequest const & func,
64 /** Parse a bind file. If a valid unbind_map is given, put \unbind
65 * bindings to a separate KeyMap. This is used in the Shortcut preference
66 * dialog where main and user bind files are loaded separately so \unbind
67 * in user.bind can not nullify \bind in the master bind file.
69 * @param bind_file bind file
70 * @param unbind_map pointer to a KeyMap that holds \unbind bindings
72 bool read(std::string const & bind_file, KeyMap * unbind_map = NULL);
74 /** write to a bind file.
75 * @param append append to the bind_file instead of overwrite it
76 * @param unbind use \unbind instead of \bind, indicating this KeyMap
77 * actually record unbind maps.
79 void write(std::string const & bind_file, bool append, bool unbind=false) const;
82 * print all available keysyms
83 * @param forgui true if the string should use translations and
86 docstring const print(bool forgui) const;
89 * Look up a key press in the keymap.
90 * @param key the keysym
91 * @param mod the modifiers
92 * @param seq the current key sequence so far
93 * @return the action / LFUN_COMMAND_PREFIX / LFUN_UNKNOWN_ACTION
96 lookup(KeySymbol const & key, KeyModifier mod, KeySequence * seq) const;
99 typedef std::deque<KeySequence> Bindings;
101 /// Given an action, find all keybindings.
102 Bindings findbindings(FuncRequest const & func) const;
104 /// Given an action, print the keybindings.
105 docstring const printbindings(FuncRequest const & func) const;
107 typedef boost::tuple<FuncRequest, KeySequence, int> Binding;
108 typedef std::vector<Binding> BindingList;
110 * Return all lfun and their associated bindings.
111 * @param unbound list unbound (func without any keybinding) as well
112 * @param tag an optional tag to indicate the source of the bindinglist
114 BindingList listBindings(bool unbound, int tag = 0) const;
117 * Given an action, find the first 1-key binding (if it exists).
118 * The KeySymbol pointer is 0 is no key is found.
119 * [only used by the Qt/Mac frontend]
121 std::pair<KeySymbol, KeyModifier>
122 find1keybinding(FuncRequest const & func) const;
126 * Returns a string of the given keysym, with modifiers.
127 * @param key the key as a keysym
128 * @param mod the modifiers
130 static std::string const printKeySym(KeySymbol const & key,
133 typedef std::pair<KeyModifier, KeyModifier> ModifierPair;
145 /// Keymap for prefix keys
146 boost::shared_ptr<KeyMap> table;
148 /// Action for !prefix keys
153 * Given an action, find all keybindings
154 * @param func the action
155 * @param prefix a sequence to prepend the results
157 Bindings findbindings(FuncRequest const & func,
158 KeySequence const & prefix) const;
160 void listBindings(BindingList & list, KeySequence const & prefix,
163 /// is the table empty ?
164 bool empty() const { return table.empty(); }
166 typedef std::vector<Key> Table;
171 /// Implementation is in LyX.cpp
172 extern KeyMap & theTopLevelKeymap();