]> git.lyx.org Git - lyx.git/blobdiff - src/KeyMap.h
* gcc does not like missing characters in keywords
[lyx.git] / src / KeyMap.h
index 8cd372881e390200e6fa2579f07cc8e2f1d02bf0..05709e69056df24072db38c5e8d84d3af9b837af 100644 (file)
 
 #include "FuncRequest.h"
 
-#include "frontends/key_state.h"
+#include "frontends/KeyModifier.h"
 #include "frontends/KeySymbol.h"
 
 #include "support/docstream.h"
 
 #include <boost/shared_ptr.hpp>
+#include <boost/tuple/tuple.hpp>
 
 #include <vector>
 #include <deque>
@@ -35,20 +36,52 @@ class KeySequence;
 class KeyMap {
 public:
        /**
-        * Bind a key sequence to an action.
+        * Bind/Unbind a key sequence to an action.
         * @return 0 on success, or position in string seq where error
         * occurs.
         * See KeySequence::parse for the syntax of the seq string
         */
        size_t bind(std::string const & seq, FuncRequest const & func);
+       size_t unbind(std::string const & seq, FuncRequest const & func);
+
+       /**
+        * Define/Undefine an action for a key sequence.
+        * @param r internal recursion level
+        */
+       void bind(KeySequence * seq, FuncRequest const & func,
+                   unsigned int r = 0);
+       void unbind(KeySequence * seq, FuncRequest const & func,
+                   unsigned int r = 0);
 
-       // Parse a bind file
-       bool read(std::string const & bind_file);
+
+       // if a keybinding has been defined.
+       bool hasBinding(KeySequence const & seq, FuncRequest const & func,
+                       unsigned int r = 0);
+
+       // clear all bindings
+       void clear();
+
+       /** 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
+        */
+       bool read(std::string const & bind_file, KeyMap * unbind_map = NULL);
+
+       /** 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;
 
        /**
         * print all available keysyms
-        * @param forgui true if the string should use translations and 
-        *   special characters. 
+        * @param forgui true if the string should use translations and
+        *   special characters.
         */
        docstring const print(bool forgui) const;
 
@@ -60,8 +93,7 @@ public:
         * @return the action / LFUN_COMMAND_PREFIX / LFUN_UNKNOWN_ACTION
         */
        FuncRequest const &
-       lookup(KeySymbolPtr key,
-              key_modifier::state mod, KeySequence * seq) const;
+       lookup(KeySymbol const & key, KeyModifier mod, KeySequence * seq) const;
 
        ///
        typedef std::deque<KeySequence> Bindings;
@@ -72,12 +104,21 @@ public:
        /// Given an action, print the keybindings.
        docstring const printbindings(FuncRequest const & func) const;
 
+       typedef boost::tuple<FuncRequest, KeySequence, int> Binding; 
+       typedef std::vector<Binding> 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;
+
        /**
         *  Given an action, find the first 1-key binding (if it exists).
         *  The KeySymbol pointer is 0 is no key is found.
         *  [only used by the Qt/Mac frontend]
         */
-       std::pair<KeySymbol const *, key_modifier::state>
+       std::pair<KeySymbol, KeyModifier>
        find1keybinding(FuncRequest const & func) const;
 
 
@@ -87,18 +128,19 @@ public:
         * @param mod the modifiers
         */
        static std::string const printKeySym(KeySymbol const & key,
-                                            key_modifier::state mod);
+                                            KeyModifier mod);
+
+       typedef std::pair<KeyModifier, KeyModifier> ModifierPair;
 
-       typedef std::pair<key_modifier::state, key_modifier::state> modifier_pair;
 
 private:
        ///
        struct Key {
                /// Keysym
-               KeySymbolPtr code;
+               KeySymbol code;
 
                /// Modifier masks
-               modifier_pair mod;
+               ModifierPair mod;
 
                /// Keymap for prefix keys
                boost::shared_ptr<KeyMap> table;
@@ -107,13 +149,6 @@ private:
                FuncRequest func;
        };
 
-       /**
-        * Define an action for a key sequence.
-        * @param r internal recursion level
-        */
-       void defkey(KeySequence * seq, FuncRequest const & func,
-                   unsigned int r = 0);
-
        /**
         * Given an action, find all keybindings
         * @param func the action
@@ -121,6 +156,9 @@ private:
         */
        Bindings findbindings(FuncRequest const & func,
                              KeySequence const & prefix) const;
+       
+       void listBindings(BindingList & list, KeySequence const & prefix,
+                                 int tag) const;
 
        /// is the table empty ?
        bool empty() const { return table.empty(); }