From: André Pönitz Date: Fri, 27 Apr 2007 08:19:12 +0000 (+0000) Subject: rename kb_sequence into KeySequence X-Git-Tag: 1.6.10~10021 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=5265a8c02c7223f72dda771fd776c104bc729487;p=features.git rename kb_sequence into KeySequence git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18057 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/KeyMap.cpp b/src/KeyMap.cpp index 354a8d62bf..bef688fe54 100644 --- a/src/KeyMap.cpp +++ b/src/KeyMap.cpp @@ -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); } diff --git a/src/KeyMap.h b/src/KeyMap.h index 97687a7c60..eaf1006e40 100644 --- a/src/KeyMap.h +++ b/src/KeyMap.h @@ -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 Bindings; + typedef std::deque 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 index 0000000000..c13c41ecdf --- /dev/null +++ b/src/KeySequence.cpp @@ -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 + +#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 index 0000000000..3aead2826c --- /dev/null +++ b/src/KeySequence.h @@ -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 +#include + + +namespace lyx { + +class KeyMap; +class FuncRequest; + +/// Holds a key sequence and the current and standard keymaps +class KeySequence { +public: + typedef std::vector 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 + modifier_pair; + + /// modifiers for keys in the sequence + std::vector modifiers; + + /// is keysequence deleted ? + bool deleted_; +}; + + +} // namespace lyx + +#endif diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index c1355cc70a..cf78d14234 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -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)); } diff --git a/src/LyXFunc.h b/src/LyXFunc.h index 370ce6ab7f..12e9ce3e04 100644 --- a/src/LyXFunc.h +++ b/src/LyXFunc.h @@ -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 keyseq; + boost::scoped_ptr keyseq; /// - boost::scoped_ptr cancel_meta_seq; + boost::scoped_ptr cancel_meta_seq; /// key_modifier::state meta_fake_bit; diff --git a/src/Makefile.am b/src/Makefile.am index d0df97ba1a..ca8e8b7937 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 index 145fffe7ad..0000000000 --- a/src/kb_sequence.cpp +++ /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 - -#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 index 9c12e3bd9d..0000000000 --- a/src/kb_sequence.h +++ /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 -#include - - -namespace lyx { - -class KeyMap; -class FuncRequest; - -/// Holds a key sequence and the current and standard keymaps -class kb_sequence { -public: - typedef std::vector 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 - modifier_pair; - - /// modifiers for keys in the sequence - std::vector modifiers; - - /// is keysequence deleted ? - bool deleted_; -}; - - -} // namespace lyx - -#endif