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"
28 /// Defines key maps and actions for key sequences
32 System, //< loaded from a bind file
33 UserBind, //< \bind loaded from user.bind
34 UserUnbind, //< \unbind loaded from user.bind, with corresponding
35 //< entry in system bind file
36 UserExtraUnbind //< \unbind loaded from user.bind, without
37 //< corresponding entry in system bind file.
40 * Bind/Unbind a key sequence to an action.
41 * @return 0 on success, or position in string seq where error
43 * See KeySequence::parse for the syntax of the seq string
45 size_t bind(std::string const & seq, FuncRequest const & func);
46 size_t unbind(std::string const & seq, FuncRequest const & func);
49 * Define/Undefine an action for a key sequence.
50 * @param r internal recursion level
52 void bind(KeySequence * seq, FuncRequest const & func,
54 void unbind(KeySequence * seq, FuncRequest const & func,
58 /// returns the function bound to this key sequence, or
59 /// FuncRequest::unknown if no binding exists for it.
60 /// @param r an internal recursion counter
61 // FIXME Surely there's a better way to do that?
62 FuncRequest getBinding(KeySequence const & seq, unsigned int r = 0);
64 /// clear all bindings
67 /** Parse a bind file. If a valid unbind_map is given, put \unbind
68 * bindings to a separate KeyMap. This is used in the Shortcut preference
69 * dialog where main and user bind files are loaded separately so \unbind
70 * in user.bind can not nullify \bind in the master bind file.
72 * @param bind_file bind file
73 * @param unbind_map pointer to a KeyMap that holds \unbind bindings
75 bool read(std::string const & bind_file, KeyMap * unbind_map = 0);
77 /** write to a bind file.
78 * @param append append to the bind_file instead of overwrite it
79 * @param unbind use \unbind instead of \bind, indicating this KeyMap
80 * actually record unbind maps.
82 void write(std::string const & bind_file, bool append, bool unbind = false) const;
85 * print all available keysyms
86 * @param forgui true if the string should use translations and
89 docstring const print(bool forgui) const;
92 * Look up a key press in the keymap.
93 * @param key the keysym
94 * @param mod the modifiers
95 * @param seq the current key sequence so far
96 * @return the action / LFUN_COMMAND_PREFIX / LFUN_UNKNOWN_ACTION
99 lookup(KeySymbol const & key, KeyModifier mod, KeySequence * seq) const;
102 typedef std::vector<KeySequence> Bindings;
104 /// Given an action, find all keybindings.
105 Bindings findBindings(FuncRequest const & func) const;
107 /// Given an action, print the keybindings.
108 docstring printBindings(FuncRequest const & func,
109 KeySequence::outputFormat format) const;
112 Binding(FuncRequest const & r, KeySequence const & s, ItemType t)
113 : request(r), sequence(s), tag(t) {}
115 KeySequence sequence;
116 KeyMap::ItemType tag;
118 typedef std::vector<Binding> BindingList;
120 * Return all lfun and their associated bindings.
121 * @param unbound list unbound (func without any keybinding) as well
122 * @param tag an optional tag to indicate the source of the bindinglist
124 BindingList listBindings(bool unbound, ItemType tag = System) const;
127 * Given an action, find the first 1-key binding (if it exists).
128 * The KeySymbol pointer is 0 is no key is found.
129 * [only used by the Qt/Mac frontend]
131 std::pair<KeySymbol, KeyModifier>
132 find1keybinding(FuncRequest const & func) const;
135 * Returns a string of the given keysym, with modifiers.
136 * @param key the key as a keysym
137 * @param mod the modifiers
139 static std::string const printKeySym(KeySymbol const & key,
144 typedef std::pair<KeyModifier, KeyModifier> ModifierPair;
152 /// Keymap for prefix keys
153 std::tr1::shared_ptr<KeyMap> table;
154 /// Action for !prefix keys
159 * Given an action, find all keybindings
160 * @param func the action
161 * @param prefix a sequence to prepend the results
163 Bindings findBindings(FuncRequest const & func,
164 KeySequence const & prefix) const;
166 void listBindings(BindingList & list, KeySequence const & prefix,
169 /// is the table empty ?
170 bool empty() const { return table.empty(); }
172 typedef std::vector<Key> Table;
177 /// Implementation is in LyX.cpp
178 extern KeyMap & theTopLevelKeymap();