From d3ab333b146e883b957ecc7feca075530843849f Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 7 Jul 2004 09:32:19 +0000 Subject: [PATCH] make bindings appear in LyX/Mac menus git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8836 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 5 +++++ src/frontends/qt2/ChangeLog | 8 +++++++ src/frontends/qt2/QLPopupMenu.C | 38 ++++++++++++++++++++++++++------- src/frontends/qt2/QLyXKeySym.C | 11 +++++++--- src/frontends/qt2/QLyXKeySym.h | 5 ++++- src/kbmap.C | 14 ++++++++++++ src/kbmap.h | 9 ++++++++ 7 files changed, 78 insertions(+), 12 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index bdcb5dd7f8..8f181310ad 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2004-06-24 Jean-Marc Lasgouttes + + * kbmap.C (find1keybinding): new method, only used by LyX/Mac with + Qt frontend + 2004-07-05 Jean-Marc Lasgouttes * BufferView_pimpl.C (setBuffer): set the layout combox value only diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index eb15c360ac..752aa70c6f 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,11 @@ +2004-07-05 Jean-Marc Lasgouttes + + * QLyXKeySym.C (qprint): like print, but return a QString + (print): use qprint. + + * QLPopupMenu.C (getLabel): do not add the binding here anymore + (populate): changes to make bindings work on Qt/Mac. + 2004-06-09 Jean-Marc Lasgouttes * lyx_gui.C (getStatus): under Mac OS X, disable the diff --git a/src/frontends/qt2/QLPopupMenu.C b/src/frontends/qt2/QLPopupMenu.C index 6a72c22184..083f86846e 100644 --- a/src/frontends/qt2/QLPopupMenu.C +++ b/src/frontends/qt2/QLPopupMenu.C @@ -22,6 +22,12 @@ #include "support/lstrings.h" +#ifdef Q_WS_MACX +#include "kbmap.h" +#include "QLyXKeySym.h" +extern boost::scoped_ptr toplevel_keymap; +#endif + using std::distance; using std::make_pair; using std::string; @@ -46,13 +52,6 @@ string const getLabel(MenuItem const & mi) label.insert(pos, 1, '&'); } - if (mi.kind() == MenuItem::Command) { - string const binding(mi.binding()); - if (!binding.empty()) { - label += '\t' + binding; - } - } - return label; } @@ -107,7 +106,30 @@ void QLPopupMenu::populate(Menu * menu) funcs_.insert(funcs_.end(), m->func()); int const index = distance(funcs_.begin(), fit); - insertItem(toqstr(getLabel(*m)), index); + QString label = toqstr(getLabel(*m)); +#ifdef Q_WS_MACX + /* There are two constraints on Qt/Mac: (1) + the bindings require a unicode string to be + represented meaningfully and std::string + does not work (2) only 1-key bindings can + be represented in menus. + + This is why the unpleasant hack bellow is + needed (JMarc) + */ + pair + binding = toplevel_keymap->find1keybinding(m->func()); + if (binding.first) { + QLyXKeySym const *key = static_cast(binding.first); + label += '\t' + key->qprint(binding.second); + } +#else + string const binding(m->binding()); + if (!binding.empty()) { + label += '\t' + toqstr(binding); + } +#endif + insertItem(label, index); setItemEnabled(index, status.enabled()); setItemChecked(index, status.onoff(true)); } diff --git a/src/frontends/qt2/QLyXKeySym.C b/src/frontends/qt2/QLyXKeySym.C index e904c16ef1..09b1797453 100644 --- a/src/frontends/qt2/QLyXKeySym.C +++ b/src/frontends/qt2/QLyXKeySym.C @@ -169,11 +169,10 @@ char QLyXKeySym::getISOEncoded(string const & encoding) const } -string const QLyXKeySym::print(key_modifier::state mod) const +QString const QLyXKeySym::qprint(key_modifier::state mod) const { int tmpkey = key_; - if (mod & key_modifier::shift) tmpkey += Qt::SHIFT; if (mod & key_modifier::ctrl) @@ -181,7 +180,13 @@ string const QLyXKeySym::print(key_modifier::state mod) const if (mod & key_modifier::alt) tmpkey += Qt::ALT; - return fromqstr(QAccel::keyToString(tmpkey)); + return QAccel::keyToString(tmpkey); +} + + +string const QLyXKeySym::print(key_modifier::state mod) const +{ + return fromqstr(qprint(mod)); } diff --git a/src/frontends/qt2/QLyXKeySym.h b/src/frontends/qt2/QLyXKeySym.h index 96f359c9d1..a0d18af290 100644 --- a/src/frontends/qt2/QLyXKeySym.h +++ b/src/frontends/qt2/QLyXKeySym.h @@ -55,9 +55,12 @@ public: */ virtual char getISOEncoded(std::string const & encoding) const; - /// + /// Return a human-readable version of a key+modifier pair. virtual std::string const print(key_modifier::state mod) const; + /// + QString const qprint(key_modifier::state mod) const; + /// int key() const { return key_; diff --git a/src/kbmap.C b/src/kbmap.C index 55f7b02523..280a72df58 100644 --- a/src/kbmap.C +++ b/src/kbmap.C @@ -325,3 +325,17 @@ kb_keymap::findbindings(FuncRequest const & func, return res; } + + +std::pair +kb_keymap::find1keybinding(FuncRequest const & func) const +{ + Table::const_iterator end = table.end(); + for (Table::const_iterator cit = table.begin(); + cit != end; ++cit) { + if (!cit->table.get() && cit->func == func) + return std::make_pair(cit->code.get(), cit->mod.first); + } + + return std::make_pair(0, key_modifier::none); +} diff --git a/src/kbmap.h b/src/kbmap.h index a5ea729b49..3648f14bc3 100644 --- a/src/kbmap.h +++ b/src/kbmap.h @@ -65,6 +65,15 @@ public: /// Given an action, print the keybindings. std::string const printbindings(FuncRequest const & func) const; + /** + * Given an action, find the first 1-key binding (if it exists). + * The LyXKeySym pointer is 0 is no key is found. + * [only used by the Qt/Mac frontend] + */ + std::pair + find1keybinding(FuncRequest const & func) const; + + /** * Returns a string of the given keysym, with modifiers. * @param key the key as a keysym -- 2.39.2