]> git.lyx.org Git - features.git/commitdiff
rename kb_sequence into KeySequence
authorAndré Pönitz <poenitz@gmx.net>
Fri, 27 Apr 2007 08:19:12 +0000 (08:19 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 27 Apr 2007 08:19:12 +0000 (08:19 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18057 a592a061-630c-0410-9148-cb99ea01b6c8

src/KeyMap.cpp
src/KeyMap.h
src/KeySequence.cpp [new file with mode: 0644]
src/KeySequence.h [new file with mode: 0644]
src/LyXFunc.cpp
src/LyXFunc.h
src/Makefile.am
src/kb_sequence.cpp [deleted file]
src/kb_sequence.h [deleted file]

index 354a8d62bfe1bf1484a73ee5b71380e3a3610337..bef688fe54eb3d383119304944a05cd4ec62e89a 100644 (file)
@@ -16,7 +16,7 @@
 #include "KeyMap.h"
 
 #include "debug.h"
-#include "kb_sequence.h"
+#include "KeySequence.h"
 #include "LyXAction.h"
 #include "Lexer.h"
 
@@ -61,7 +61,7 @@ size_t KeyMap::bind(string const & seq, FuncRequest const & func)
               << seq << "' Action `"
               << func.action << '\'' << endl;
 
-       kb_sequence k(0, 0);
+       KeySequence k(0, 0);
 
        string::size_type const res = k.parse(seq);
        if (res == string::npos) {
@@ -172,7 +172,7 @@ bool KeyMap::read(string const & bind_file)
 
 FuncRequest const &
 KeyMap::lookup(LyXKeySymPtr key,
-                 key_modifier::state mod, kb_sequence * seq) const
+                 key_modifier::state mod, KeySequence * seq) const
 {
        static FuncRequest const unknown(LFUN_UNKNOWN_ACTION);
 
@@ -224,7 +224,7 @@ docstring const KeyMap::print(bool forgui) const
 }
 
 
-void KeyMap::defkey(kb_sequence * seq, FuncRequest const & func, unsigned int r)
+void KeyMap::defkey(KeySequence * seq, FuncRequest const & func, unsigned int r)
 {
        LyXKeySymPtr code = seq->sequence[r];
        if (!code->isOK())
@@ -292,12 +292,12 @@ docstring const KeyMap::printbindings(FuncRequest const & func) const
 
 KeyMap::Bindings KeyMap::findbindings(FuncRequest const & func) const
 {
-       return findbindings(func, kb_sequence(0, 0));
+       return findbindings(func, KeySequence(0, 0));
 }
 
 
 KeyMap::Bindings KeyMap::findbindings(FuncRequest const & func,
-                       kb_sequence const & prefix) const
+                       KeySequence const & prefix) const
 {
        Bindings res;
        if (table.empty()) return res;
@@ -306,13 +306,13 @@ KeyMap::Bindings KeyMap::findbindings(FuncRequest const & func,
        for (Table::const_iterator cit = table.begin();
            cit != end; ++cit) {
                if (cit->table.get()) {
-                       kb_sequence seq = prefix;
+                       KeySequence seq = prefix;
                        seq.addkey(cit->code, cit->mod.first);
                        Bindings res2 =
                                cit->table->findbindings(func, seq);
                        res.insert(res.end(), res2.begin(), res2.end());
                } else if (cit->func == func) {
-                       kb_sequence seq = prefix;
+                       KeySequence seq = prefix;
                        seq.addkey(cit->code, cit->mod.first);
                        res.push_back(seq);
                }
index 97687a7c6084dc061a1c40d7e2c351a95b76d8d9..eaf1006e40819d06f0eabbe0d03743cbd2874d0a 100644 (file)
@@ -29,7 +29,7 @@
 
 namespace lyx {
 
-class kb_sequence;
+class KeySequence;
 
 /// Defines key maps and actions for key sequences
 class KeyMap {
@@ -38,7 +38,7 @@ public:
         * Bind a key sequence to an action.
         * @return 0 on success, or position in string seq where error
         * occurs.
-        * See kb_sequence::parse for the syntax of the seq string
+        * See KeySequence::parse for the syntax of the seq string
         */
        size_t bind(std::string const & seq, FuncRequest const & func);
 
@@ -61,10 +61,10 @@ public:
         */
        FuncRequest const &
        lookup(LyXKeySymPtr key,
-              key_modifier::state mod, kb_sequence * seq) const;
+              key_modifier::state mod, KeySequence * seq) const;
 
        ///
-       typedef std::deque<kb_sequence> Bindings;
+       typedef std::deque<KeySequence> Bindings;
 
        /// Given an action, find all keybindings.
        Bindings findbindings(FuncRequest const & func) const;
@@ -111,7 +111,7 @@ private:
         * Define an action for a key sequence.
         * @param r internal recursion level
         */
-       void defkey(kb_sequence * seq, FuncRequest const & func,
+       void defkey(KeySequence * seq, FuncRequest const & func,
                    unsigned int r = 0);
 
        /**
@@ -120,7 +120,7 @@ private:
         * @param prefix a sequence to prepend the results
         */
        Bindings findbindings(FuncRequest const & func,
-                             kb_sequence const & prefix) const;
+                             KeySequence const & prefix) const;
 
        /// is the table empty ?
        bool empty() const { return table.empty(); }
diff --git a/src/KeySequence.cpp b/src/KeySequence.cpp
new file mode 100644 (file)
index 0000000..c13c41e
--- /dev/null
@@ -0,0 +1,183 @@
+/**
+ * \file KeySequence.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ * \author Jean-Marc Lasgouttes
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "KeySequence.h"
+
+#include "gettext.h"
+#include "KeyMap.h"
+#include "lfuns.h"
+
+#include "frontends/LyXKeySym.h"
+#include "frontends/LyXKeySymFactory.h"
+
+
+namespace lyx {
+
+using std::make_pair;
+using std::string;
+
+
+FuncRequest const &
+KeySequence::addkey(LyXKeySymPtr key,
+                   key_modifier::state mod, key_modifier::state nmod)
+{
+       // adding a key to a deleted sequence
+       // starts a new sequence
+       if (deleted_) {
+               deleted_ = false;
+               sequence.clear();
+               modifiers.clear();
+       }
+
+       modifiers.push_back(make_pair(mod, nmod));
+       sequence.push_back(key);
+
+       if (curmap) {
+               return curmap->lookup(key, mod, this);
+       }
+
+       static FuncRequest unknown(LFUN_UNKNOWN_ACTION);
+       return unknown;
+}
+
+
+size_t KeySequence::parse(string const & s)
+{
+       if (s.empty())
+               return 1;
+
+       size_t i = 0;
+       key_modifier::state mod = key_modifier::none;
+       key_modifier::state nmod = key_modifier::none;
+
+       while (i < s.length()) {
+               if (s[i] == ' ')
+                       ++i;
+               if (i >= s.length())
+                       break;
+
+               if (i + 1 < s.length() && s[i + 1] == '-') {
+                       switch (s[i]) {
+                       case 's': case 'S':
+                               mod |= key_modifier::shift;
+                               i += 2;
+                               continue;
+                       case 'c': case 'C':
+                               mod |= key_modifier::ctrl;
+                               i += 2;
+                               continue;
+                       case 'm': case 'M':
+                               mod |= key_modifier::alt;
+                               i += 2;
+                               continue;
+                       default:
+                               return i + 1;
+                       }
+               } else if (i + 2 < s.length() && s[i] == '~'
+                          && s[i + 2] == '-') {
+                       switch (s[i + 1]) {
+                       case 's': case 'S':
+                               nmod |= key_modifier::shift;
+                               i += 3;
+                               continue;
+                       case 'c': case 'C':
+                               nmod |= key_modifier::ctrl;
+                               i += 3;
+                               continue;
+                       case 'm': case 'M':
+                               nmod |= key_modifier::alt;
+                               i += 3;
+                               continue;
+                       default:
+                               return i + 2;
+                       }
+               } else {
+                       string tbuf;
+                       size_t j = i;
+                       for (; j < s.length() && s[j] != ' '; ++j)
+                               tbuf += s[j];    // (!!!check bounds :-)
+
+                       LyXKeySymPtr key(LyXKeySymFactory::create());
+                       key->init(tbuf);
+
+                       if (!key->isOK())
+                               return j;
+
+                       i = j;
+
+                       addkey(key, mod, nmod);
+                       mod = key_modifier::none;
+               }
+       }
+
+       // empty sequence?
+       if (sequence.size() == 0)
+               return 0;
+
+       // everything is fine
+       return string::npos;
+}
+
+
+docstring const KeySequence::print(bool forgui) const
+{
+       docstring buf;
+
+       size_t const length = sequence.size();
+
+       for (size_t i = 0; i < length; ++i) {
+               buf += sequence[i]->print(modifiers[i].first, forgui);
+               // append a blank
+               if (i + 1 < length)
+                       buf += ' ';
+       }
+       return buf;
+}
+
+
+docstring const KeySequence::printOptions(bool forgui) const
+{
+       docstring buf;
+
+       buf += print(forgui);
+
+       if (!curmap)
+               return buf;
+
+       buf += _("   options: ");
+       buf += curmap->print(forgui);
+       return buf;
+}
+
+
+void KeySequence::mark_deleted()
+{
+       deleted_ = true;
+}
+
+
+void KeySequence::reset()
+{
+       mark_deleted();
+       curmap = stdmap;
+}
+
+void KeySequence::clear()
+{
+       sequence.clear();
+       reset();
+}
+
+
+} // namespace lyx
diff --git a/src/KeySequence.h b/src/KeySequence.h
new file mode 100644 (file)
index 0000000..3aead28
--- /dev/null
@@ -0,0 +1,120 @@
+// -*- C++ -*-
+/**
+ * \file KeySequence.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ * \author Jean-Marc Lasgouttes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef KB_SEQUENCE_H
+#define KB_SEQUENCE_H
+
+#include "frontends/key_state.h"
+#include "frontends/LyXKeySym.h"
+
+#include <string>
+#include <vector>
+
+
+namespace lyx {
+
+class KeyMap;
+class FuncRequest;
+
+/// Holds a key sequence and the current and standard keymaps
+class KeySequence {
+public:
+       typedef std::vector<LyXKeySymPtr> Sequence;
+
+       friend class KeyMap;
+
+       ///
+       KeySequence(KeyMap * std, KeyMap * cur)
+               : stdmap(std), curmap(cur), deleted_(false) {}
+
+       /**
+        * Add a key to the key sequence and look it up in the curmap
+        * if the latter is defined.
+        * @param keysym the key to add
+        * @param mod modifier mask
+        * @param nmod which modifiers to mask out for equality test
+        * @return the action matching this key sequence or LFUN_UNKNOWN_ACTION
+        */
+       FuncRequest const &
+       addkey(LyXKeySymPtr keysym, key_modifier::state mod,
+              key_modifier::state nmod = key_modifier::none);
+
+       /**
+        * Add a sequence of keys from a string to the sequence
+        * @return string::npos if OK, else error position in string
+        *
+        * Keys in the string must be separated with whitespace;
+        * Use the keysym names used by XStringToKeysym, f.ex.
+        * "Space", "a", "Return", ...
+        * Prefixes are S-, C-, M- for shift, control, meta
+        * Prefixes can also be ignored by using the Tilde "~"
+        * f.ex.: "~S-Space".
+        */
+       size_t parse(std::string const & s);
+
+       /**
+        * Return the current sequence as a string.
+        * @param forgui true if the string should use translations and 
+        *   special characters. 
+        * @see parse()
+        */
+       docstring const print(bool forgui) const;
+
+       /**
+        * Return the current sequence and available options as
+        * a string. No options are added if no curmap kb map exists.
+        * @param forgui true if the string should use translations and 
+        *   special characters. 
+        */
+       docstring const printOptions(bool forgui) const;
+
+       /// Mark the sequence as deleted.
+       void mark_deleted();
+
+       /// Reset sequence to become "deleted"
+       void reset();
+
+       /// clear in full
+       void clear();
+
+       bool deleted() const { return deleted_; }
+
+       /// length of sequence
+       size_t length() const { return sequence.size(); }
+
+       /// Keymap to use if a new sequence is starting
+       KeyMap * stdmap;
+
+       /// Keymap to use for the next key
+       KeyMap * curmap;
+
+private:
+       /**
+        * Array holding the current key sequence as KeySyms.
+        * If sequence[length - 1] < 0xff it can be used as ISO8859 char
+        */
+       Sequence sequence;
+
+       typedef std::pair<key_modifier::state, key_modifier::state>
+               modifier_pair;
+
+       /// modifiers for keys in the sequence
+       std::vector<modifier_pair> modifiers;
+
+       /// is keysequence deleted ?
+       bool deleted_;
+};
+
+
+} // namespace lyx
+
+#endif
index c1355cc70a33176c1e28f5137ea0964e4c8e06cf..cf78d142342b17b48bf96f315934f5bc5edf72a5 100644 (file)
@@ -209,8 +209,8 @@ LyXFunc::LyXFunc()
 
 void LyXFunc::initKeySequences(KeyMap * kb)
 {
-       keyseq.reset(new kb_sequence(kb, kb));
-       cancel_meta_seq.reset(new kb_sequence(kb, kb));
+       keyseq.reset(new KeySequence(kb, kb));
+       cancel_meta_seq.reset(new KeySequence(kb, kb));
 }
 
 
index 370ce6ab7f6a38dc0f039f1bd1ef1d2feade5b39..12e9ce3e0406e72c412b880880a06d12f89dcf7a 100644 (file)
@@ -15,7 +15,7 @@
 #ifndef LYXFUNC_H
 #define LYXFUNC_H
 
-#include "kb_sequence.h"
+#include "KeySequence.h"
 #include "lfuns.h"
 
 #include "support/docstring.h"
@@ -92,9 +92,9 @@ private:
        char_type encoded_last_key;
 
        ///
-       boost::scoped_ptr<kb_sequence> keyseq;
+       boost::scoped_ptr<KeySequence> keyseq;
        ///
-       boost::scoped_ptr<kb_sequence> cancel_meta_seq;
+       boost::scoped_ptr<KeySequence> cancel_meta_seq;
        ///
        key_modifier::state meta_fake_bit;
 
index d0df97ba1a9b2914ac046d3d9b76492670ace3f3..ca8e8b79378dca99a87f4f3c40477396e8853320 100644 (file)
@@ -148,8 +148,8 @@ lyx_SOURCES = \
        Intl.h \
        KeyMap.cpp \
        KeyMap.h \
-       kb_sequence.cpp \
-       kb_sequence.h \
+       KeySequence.cpp \
+       KeySequence.h \
        KmodInfo.h \
        Language.cpp \
        Language.h \
diff --git a/src/kb_sequence.cpp b/src/kb_sequence.cpp
deleted file mode 100644 (file)
index 145fffe..0000000
+++ /dev/null
@@ -1,185 +0,0 @@
-/**
- * \file kb_sequence.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Lars Gullik Bjønnes
- * \author Jean-Marc Lasgouttes
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "kb_sequence.h"
-
-#include "gettext.h"
-#include "KeyMap.h"
-#include "lfuns.h"
-
-#include "frontends/LyXKeySym.h"
-#include "frontends/LyXKeySymFactory.h"
-
-
-namespace lyx {
-
-using std::make_pair;
-using std::string;
-
-
-FuncRequest const &
-kb_sequence::addkey(LyXKeySymPtr key,
-                   key_modifier::state mod, key_modifier::state nmod)
-{
-       // adding a key to a deleted sequence
-       // starts a new sequence
-       if (deleted_) {
-               deleted_ = false;
-               sequence.clear();
-               modifiers.clear();
-       }
-
-       modifiers.push_back(make_pair(mod, nmod));
-       sequence.push_back(key);
-
-       if (curmap) {
-               return curmap->lookup(key, mod, this);
-       }
-
-       static FuncRequest unknown(LFUN_UNKNOWN_ACTION);
-       return unknown;
-}
-
-
-string::size_type kb_sequence::parse(string const & s)
-{
-       if (s.empty()) return 1;
-
-       string::size_type i = 0;
-       key_modifier::state mod = key_modifier::none;
-       key_modifier::state nmod = key_modifier::none;
-
-       while (i < s.length()) {
-               if (s[i] == ' ')
-                       ++i;
-               if (i >= s.length())
-                       break;
-
-               if (i + 1 < s.length() && s[i + 1] == '-') {
-                       switch (s[i]) {
-                       case 's': case 'S':
-                               mod |= key_modifier::shift;
-                               i += 2;
-                               continue;
-                       case 'c': case 'C':
-                               mod |= key_modifier::ctrl;
-                               i += 2;
-                               continue;
-                       case 'm': case 'M':
-                               mod |= key_modifier::alt;
-                               i += 2;
-                               continue;
-                       default:
-                               return i + 1;
-                       }
-               } else if (i + 2 < s.length() && s[i] == '~'
-                          && s[i + 2] == '-') {
-                       switch (s[i + 1]) {
-                       case 's': case 'S':
-                               nmod |= key_modifier::shift;
-                               i += 3;
-                               continue;
-                       case 'c': case 'C':
-                               nmod |= key_modifier::ctrl;
-                               i += 3;
-                               continue;
-                       case 'm': case 'M':
-                               nmod |= key_modifier::alt;
-                               i += 3;
-                               continue;
-                       default:
-                               return i + 2;
-                       }
-               } else {
-                       string tbuf;
-                       string::size_type j = i;
-                       for (; j < s.length() && s[j] != ' '; ++j)
-                               tbuf += s[j];    // (!!!check bounds :-)
-
-                       LyXKeySymPtr key(LyXKeySymFactory::create());
-                       key->init(tbuf);
-
-                       if ( ! key->isOK() ) {
-                               return j;
-                       }
-
-                       i = j;
-
-                       addkey(key, mod, nmod);
-                       mod = key_modifier::none;
-               }
-       }
-
-       // empty sequence?
-       if (sequence.size() == 0)
-               return 0;
-
-       // everything is fine
-       return string::npos;
-}
-
-
-docstring const kb_sequence::print(bool forgui) const
-{
-       docstring buf;
-
-       const KeySequence::size_type length = sequence.size();
-
-       for (KeySequence::size_type i = 0; i < length; ++i) {
-               buf += sequence[i]->print(modifiers[i].first, forgui);
-
-               // append a blank
-               if (i + 1 < length) {
-                       buf += ' ';
-               }
-       }
-       return buf;
-}
-
-
-docstring const kb_sequence::printOptions(bool forgui) const
-{
-       docstring buf;
-
-       buf += print(forgui);
-
-       if (!curmap)
-               return buf;
-
-       buf += _("   options: ");
-       buf += curmap->print(forgui);
-       return buf;
-}
-
-
-void kb_sequence::mark_deleted()
-{
-       deleted_ = true;
-}
-
-
-void kb_sequence::reset()
-{
-       mark_deleted();
-       curmap = stdmap;
-}
-
-void kb_sequence::clear()
-{
-       sequence.clear();
-       reset();
-}
-
-
-} // namespace lyx
diff --git a/src/kb_sequence.h b/src/kb_sequence.h
deleted file mode 100644 (file)
index 9c12e3b..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-// -*- C++ -*-
-/**
- * \file kb_sequence.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Lars Gullik Bjønnes
- * \author Jean-Marc Lasgouttes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef KB_SEQUENCE_H
-#define KB_SEQUENCE_H
-
-#include "frontends/key_state.h"
-#include "frontends/LyXKeySym.h"
-
-#include <string>
-#include <vector>
-
-
-namespace lyx {
-
-class KeyMap;
-class FuncRequest;
-
-/// Holds a key sequence and the current and standard keymaps
-class kb_sequence {
-public:
-       typedef std::vector<LyXKeySymPtr> KeySequence;
-
-       friend class KeyMap;
-
-       ///
-       kb_sequence(KeyMap * std, KeyMap * cur)
-               : stdmap(std), curmap(cur), deleted_(false) {}
-
-       /**
-        * Add a key to the key sequence and look it up in the curmap
-        * if the latter is defined.
-        * @param keysym the key to add
-        * @param mod modifier mask
-        * @param nmod which modifiers to mask out for equality test
-        * @return the action matching this key sequence or LFUN_UNKNOWN_ACTION
-        */
-       FuncRequest const &
-       addkey(LyXKeySymPtr keysym, key_modifier::state mod,
-              key_modifier::state nmod = key_modifier::none);
-
-       /**
-        * Add a sequence of keys from a string to the sequence
-        * @return string::npos if OK, else error position in string
-        *
-        * Keys in the string must be separated with whitespace;
-        * Use the keysym names used by XStringToKeysym, f.ex.
-        * "Space", "a", "Return", ...
-        * Prefixes are S-, C-, M- for shift, control, meta
-        * Prefixes can also be ignored by using the Tilde "~"
-        * f.ex.: "~S-Space".
-        */
-       std::string::size_type parse(std::string const & s);
-
-       /**
-        * Return the current sequence as a string.
-        * @param forgui true if the string should use translations and 
-        *   special characters. 
-        * @see parse()
-        */
-       docstring const print(bool forgui) const;
-
-       /**
-        * Return the current sequence and available options as
-        * a string. No options are added if no curmap kb map exists.
-        * @param forgui true if the string should use translations and 
-        *   special characters. 
-        */
-       docstring const printOptions(bool forgui) const;
-
-       /// Mark the sequence as deleted.
-       void mark_deleted();
-
-       /// Reset sequence to become "deleted"
-       void reset();
-
-       /// clear in full
-       void clear();
-
-       bool deleted() const {
-               return deleted_;
-       }
-
-       /// length of sequence
-       KeySequence::size_type length() const {
-               return sequence.size();
-       }
-
-       /// Keymap to use if a new sequence is starting
-       KeyMap * stdmap;
-
-       /// Keymap to use for the next key
-       KeyMap * curmap;
-
-private:
-       /**
-        * Array holding the current key sequence as KeySyms.
-        * If sequence[length - 1] < 0xff it can be used as ISO8859 char
-        */
-       KeySequence sequence;
-
-       typedef std::pair<key_modifier::state, key_modifier::state>
-               modifier_pair;
-
-       /// modifiers for keys in the sequence
-       std::vector<modifier_pair> modifiers;
-
-       /// is keysequence deleted ?
-       bool deleted_;
-};
-
-
-} // namespace lyx
-
-#endif