#include "KeyMap.h"
#include "debug.h"
-#include "kb_sequence.h"
+#include "KeySequence.h"
#include "LyXAction.h"
#include "Lexer.h"
<< 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) {
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);
}
-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())
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;
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);
}
namespace lyx {
-class kb_sequence;
+class KeySequence;
/// Defines key maps and actions for key sequences
class KeyMap {
* 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);
*/
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;
* 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);
/**
* @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(); }
--- /dev/null
+/**
+ * \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
--- /dev/null
+// -*- 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
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));
}
#ifndef LYXFUNC_H
#define LYXFUNC_H
-#include "kb_sequence.h"
+#include "KeySequence.h"
#include "lfuns.h"
#include "support/docstring.h"
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;
Intl.h \
KeyMap.cpp \
KeyMap.h \
- kb_sequence.cpp \
- kb_sequence.h \
+ KeySequence.cpp \
+ KeySequence.h \
KmodInfo.h \
Language.cpp \
Language.h \
+++ /dev/null
-/**
- * \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
+++ /dev/null
-// -*- 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