From 025f30b36150bdbe404687a5d9656d3b7fab8445 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 2 Jul 2004 10:03:22 +0000 Subject: [PATCH] cleanup reading of lfun bindings git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8832 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 12 ++++++++++++ src/MenuBackend.C | 8 ++++---- src/kbmap.C | 41 +++++++++++++++++++++++++++++++---------- src/kbmap.h | 18 ++++++++++++++++-- src/lyxfunc.C | 2 +- 5 files changed, 64 insertions(+), 17 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 24d2f33559..199f415698 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2004-06-30 Jean-Marc Lasgouttes + + * kbmap.C (findbindings): a couple of new methods. returns a + container of kb_sequence objects. The real work is done by the + private recursive version + (printbindings): uses findbindings to print out a bracketed list + of bindings (renamed from findbinding). + + * MenuBackend.C (binding): use kb_keymap::findbindings + + * lyxfunc.C (sendDispatchMessage): use use kb_keymap::printbindings. + 2004-07-01 Georg Baum * buffer.C: up LYX_FORMAT to 235 (needed for the paperpackage fix) diff --git a/src/MenuBackend.C b/src/MenuBackend.C index 7eb3166240..543ba73c78 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -137,13 +137,13 @@ string const MenuItem::binding() const // Get the keys bound to this action, but keep only the // first one later - string bindings = toplevel_keymap->findbinding(func_); + kb_keymap::Bindings bindings = toplevel_keymap->findbindings(func_); - if (!bindings.empty()) { - return bindings.substr(1, bindings.find(']') - 1); + if (bindings.size()) { + return bindings.begin()->print(); } else { lyxerr[Debug::KBMAP] - << "No bindings for " + << "No binding for " << lyxaction.getActionName(func_.action) << '(' << func_.argument << ')' << endl; return string(); diff --git a/src/kbmap.C b/src/kbmap.C index e494868c77..55f7b02523 100644 --- a/src/kbmap.C +++ b/src/kbmap.C @@ -23,6 +23,7 @@ #include "frontends/LyXKeySym.h" #include "support/filetools.h" +#include "support/std_sstream.h" using lyx::support::i18nLibFileSearch; @@ -281,24 +282,44 @@ void kb_keymap::defkey(kb_sequence * seq, } -string const kb_keymap::findbinding(FuncRequest const & func, - string const & prefix) const +string const kb_keymap::printbindings(FuncRequest const & func) const { - string res; + std::ostringstream res; + Bindings bindings = findbindings(func); + for (Bindings::const_iterator cit = bindings.begin(); + cit != bindings.end() ; ++cit) + res << '[' << cit->print() << ']'; + return res.str(); +} + + +kb_keymap::Bindings +kb_keymap::findbindings(FuncRequest const & func) const +{ + return findbindings(func, kb_sequence(0, 0)); +} + + +kb_keymap::Bindings +kb_keymap::findbindings(FuncRequest const & func, + kb_sequence const & prefix) const +{ + Bindings res; if (table.empty()) return res; Table::const_iterator end = table.end(); for (Table::const_iterator cit = table.begin(); cit != end; ++cit) { if (cit->table.get()) { - res += cit->table->findbinding(func, - prefix - + printKey((*cit)) - + ' '); + kb_sequence 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) { - res += '['; - res += prefix + printKey((*cit)); - res += "] "; + kb_sequence seq = prefix; + seq.addkey(cit->code, cit->mod.first); + res.push_back(seq); } } diff --git a/src/kbmap.h b/src/kbmap.h index b8eabff92d..a5ea729b49 100644 --- a/src/kbmap.h +++ b/src/kbmap.h @@ -21,6 +21,7 @@ #include #include +#include class kb_sequence; class LyXKeySym; @@ -55,9 +56,14 @@ public: lookup(LyXKeySymPtr key, key_modifier::state mod, kb_sequence * seq) const; + /// + typedef std::deque Bindings; + /// Given an action, find all keybindings. - std::string const findbinding(FuncRequest const & func, - std::string const & prefix = std::string()) const; + Bindings findbindings(FuncRequest const & func) const; + + /// Given an action, print the keybindings. + std::string const printbindings(FuncRequest const & func) const; /** * Returns a string of the given keysym, with modifiers. @@ -95,6 +101,14 @@ private: /// Returns a string of the given key std::string const printKey(kb_key const & key) const; + /** + * Given an action, find all keybindings + * @param func the action + * @param prefix a sequence to prepend the results + */ + Bindings findbindings(FuncRequest const & func, + kb_sequence const & prefix) const; + /// is the table empty ? bool empty() const { return table.empty(); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index fade20901e..2b268bc98b 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1451,7 +1451,7 @@ void LyXFunc::sendDispatchMessage(string const & msg, } } - string const shortcuts = toplevel_keymap->findbinding(cmd); + string const shortcuts = toplevel_keymap->printbindings(cmd); if (!shortcuts.empty()) { comname += ": " + shortcuts;