The following patch aims at improving the situation of shortcuts in GUI. It basically boils down to two changes:
- in GuiApplication, make qt_trans (now qt_trans_) a member of the application, so that it does not get deleted at the end of the contructor. This means that translation of qt stuff now actually works (key modifiers, file dialog...). - LyXKeySym::print now uses a bool parameter telling whether we want a string suitable for GUI (with translated modifiers and maybe special Mac characters) or a internal version (the old Ctrl+O). The rest of the path is just the propagation of the second part. Objections? Bennett, before I commit, I'll ask you to try it out, as usual. Now all shortcuts should be displayed in the right way. JMarc
Index: src/lyxfunc.C =================================================================== --- src/lyxfunc.C (revision 16479) +++ src/lyxfunc.C (working copy) @@ -294,7 +294,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr lyxerr << BOOST_CURRENT_FUNCTION << " Key [action=" << func.action << "][" - << to_utf8(keyseq->print()) << ']' + << to_utf8(keyseq->print(false)) << ']' << endl; } @@ -303,7 +303,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr // num_bytes == 0? (Lgb) if (keyseq->length() > 1) { - lyx_view_->message(keyseq->print()); + lyx_view_->message(keyseq->print(true)); } @@ -787,7 +787,7 @@ void LyXFunc::dispatch(FuncRequest const case LFUN_COMMAND_PREFIX: BOOST_ASSERT(lyx_view_); - lyx_view_->message(keyseq->printOptions()); + lyx_view_->message(keyseq->printOptions(true)); break; case LFUN_COMMAND_EXECUTE: @@ -808,7 +808,7 @@ void LyXFunc::dispatch(FuncRequest const case LFUN_META_PREFIX: meta_fake_bit = key_modifier::alt; - setMessage(keyseq->print()); + setMessage(keyseq->print(true)); break; case LFUN_BUFFER_TOGGLE_READ_ONLY: @@ -1168,7 +1168,7 @@ void LyXFunc::dispatch(FuncRequest const break; case LFUN_SERVER_NOTIFY: - dispatch_buffer = keyseq->print(); + dispatch_buffer = keyseq->print(false); theLyXServer().notifyClient(to_utf8(dispatch_buffer)); break; @@ -2034,12 +2034,12 @@ docstring const LyXFunc::viewStatusMessa { // When meta-fake key is pressed, show the key sequence so far + "M-". if (wasMetaKey()) - return keyseq->print() + "M-"; + return keyseq->print(true) + "M-"; // Else, when a non-complete key sequence is pressed, // show the available options. if (keyseq->length() > 0 && !keyseq->deleted()) - return keyseq->printOptions(); + return keyseq->printOptions(true); if (!view()->buffer()) return _("Welcome to LyX!"); Index: src/frontends/LyXKeySym.h =================================================================== --- src/frontends/LyXKeySym.h (revision 16479) +++ src/frontends/LyXKeySym.h (working copy) @@ -58,9 +58,9 @@ public: /** * Return a string describing the KeySym with modifier mod. - * This should use the native UI format when applicable + * Use the native UI format when \c forgui is true. */ - virtual docstring const print(key_modifier::state mod) const = 0; + virtual docstring const print(key_modifier::state mod, bool forgui) const = 0; }; Index: src/frontends/qt4/QLyXKeySym.C =================================================================== --- src/frontends/qt4/QLyXKeySym.C (revision 16479) +++ src/frontends/qt4/QLyXKeySym.C (working copy) @@ -211,7 +211,7 @@ size_t QLyXKeySym::getUCSEncoded() const } -docstring const QLyXKeySym::print(key_modifier::state mod) const +docstring const QLyXKeySym::print(key_modifier::state mod, bool forgui) const { int tmpkey = key_; @@ -221,8 +221,11 @@ docstring const QLyXKeySym::print(key_mo tmpkey += Qt::CTRL; if (mod & key_modifier::alt) tmpkey += Qt::ALT; + + QKeySequence seq(tmpkey); - return qstring_to_ucs4(QKeySequence(tmpkey).toString()); + return qstring_to_ucs4(seq.toString(forgui ? QKeySequence::NativeText + : QKeySequence::PortableText)); } Index: src/frontends/qt4/QLyXKeySym.h =================================================================== --- src/frontends/qt4/QLyXKeySym.h (revision 16479) +++ src/frontends/qt4/QLyXKeySym.h (working copy) @@ -58,8 +58,12 @@ public: */ virtual size_t getUCSEncoded() const; - /// Return a human-readable version of a key+modifier pair. - virtual docstring const print(key_modifier::state mod) const; + /** + * Return a human-readable version of a key+modifier pair. + * This will be the GUI version (translated and with special + * characters for Mac OS X) when \c forgui is true. + */ + virtual docstring const print(key_modifier::state mod, bool forgui) const; /// int key() const { Index: src/frontends/qt4/GuiApplication.C =================================================================== --- src/frontends/qt4/GuiApplication.C (revision 16479) +++ src/frontends/qt4/GuiApplication.C (working copy) @@ -107,13 +107,12 @@ GuiApplication::GuiApplication(int & arg #endif // install translation file for Qt built-in dialogs - QTranslator qt_trans; QString language_name = QString("qt_") + QLocale::system().name(); language_name.truncate(5); - if (qt_trans.load(language_name, + if (qt_trans_.load(language_name, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { - qApp->installTranslator(&qt_trans); + qApp->installTranslator(&qt_trans_); // even if the language calls for RtL, don't do that qApp->setLayoutDirection(Qt::LeftToRight); lyxerr[Debug::GUI] Index: src/frontends/qt4/QLPopupMenu.C =================================================================== --- src/frontends/qt4/QLPopupMenu.C (revision 16479) +++ src/frontends/qt4/QLPopupMenu.C (working copy) @@ -106,13 +106,13 @@ void QLPopupMenu::populate(QMenu* qMenu, } else { // we have a MenuItem::Command - lyxerr[Debug::GUI] << "creating Menu Item " << lyx::to_utf8(m->label()) << endl; - - docstring label = getLabel(*m); - addBinding(label, *m); + lyxerr[Debug::GUI] << "creating Menu Item " + << lyx::to_utf8(m->label()) + << endl; Action * action = new Action(*(owner_->view()), - label, m->func()); + getLabel(*m), m->func()); + action->setShortcut(QKeySequence(toqstr(m->binding()))); qMenu->addAction(action); } } @@ -134,14 +134,6 @@ docstring const QLPopupMenu::getLabel(Me return label; } -void QLPopupMenu::addBinding(docstring & label, MenuItem const & mi) -{ - docstring const binding(mi.binding()); - if (!binding.empty()) { - label += '\t' + binding; - } -} - } // namespace frontend } // namespace lyx Index: src/frontends/qt4/GuiApplication.h =================================================================== --- src/frontends/qt4/GuiApplication.h (revision 16479) +++ src/frontends/qt4/GuiApplication.h (working copy) @@ -22,6 +22,7 @@ #include "frontends/Application.h" #include <QApplication> +#include <QTranslator> namespace lyx { @@ -92,6 +93,8 @@ private: /// ColorCache color_cache_; /// + QTranslator qt_trans_; + /// std::map<int, boost::shared_ptr<socket_callback> > socket_callbacks_; #ifdef Q_WS_X11 Index: src/frontends/qt4/QLPopupMenu.h =================================================================== --- src/frontends/qt4/QLPopupMenu.h (revision 16479) +++ src/frontends/qt4/QLPopupMenu.h (working copy) @@ -49,9 +49,6 @@ private: /// Get a Menu item label from the menu backend lyx::docstring const getLabel(MenuItem const & mi); - /// add binding keys a the menu item label. - void addBinding(lyx::docstring & label, MenuItem const & mi); - /// Top Level Menu Menu topLevelMenu_; }; Index: src/kbsequence.C =================================================================== --- src/kbsequence.C (revision 16479) +++ src/kbsequence.C (working copy) @@ -130,17 +130,14 @@ string::size_type kb_sequence::parse(str } -docstring const kb_sequence::print() const +docstring const kb_sequence::print(bool forgui) const { docstring buf; - //if (deleted_) - // return buf; + const KeySequence::size_type length = sequence.size(); - KeySequence::size_type i, length = sequence.size(); - - for (i = 0; i < length; ++i) { - buf += sequence[i]->print(modifiers[i].first); + for (KeySequence::size_type i = 0; i < length; ++i) { + buf += sequence[i]->print(modifiers[i].first, forgui); // append a blank if (i + 1 < length) { @@ -151,17 +148,17 @@ docstring const kb_sequence::print() con } -docstring const kb_sequence::printOptions() const +docstring const kb_sequence::printOptions(bool forgui) const { docstring buf; - buf += print(); + buf += print(forgui); if (!curmap) return buf; buf += _(" options: "); - buf += curmap->print(); + buf += curmap->print(forgui); return buf; } Index: src/kbsequence.h =================================================================== --- src/kbsequence.h (revision 16479) +++ src/kbsequence.h (working copy) @@ -63,15 +63,19 @@ public: /** * Return the current sequence as a string. + * @param forgui true if the string should use translations and + * special characters. * @see parse() */ - docstring const print() const; + 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() const; + docstring const printOptions(bool forgui) const; /// Mark the sequence as deleted. void mark_deleted(); Index: src/kbmap.C =================================================================== --- src/kbmap.C (revision 16479) +++ src/kbmap.C (working copy) @@ -55,12 +55,6 @@ string const kb_keymap::printKeySym(LyXK } -docstring const kb_keymap::printKey(kb_key const & key) const -{ - return key.code->print(key.mod.first); -} - - string::size_type kb_keymap::bind(string const & seq, FuncRequest const & func) { if (lyxerr.debugging(Debug::KBMAP)) { @@ -220,12 +214,12 @@ kb_keymap::lookup(LyXKeySymPtr key, } -docstring const kb_keymap::print() const +docstring const kb_keymap::print(bool forgui) const { docstring buf; Table::const_iterator end = table.end(); for (Table::const_iterator cit = table.begin(); cit != end; ++cit) { - buf += printKey((*cit)); + buf += cit->code->print(cit->mod.first, forgui); buf += ' '; } return buf; @@ -252,7 +246,7 @@ void kb_keymap::defkey(kb_sequence * seq if (r + 1 == seq->length()) { lyxerr[Debug::KBMAP] << "Warning: New binding for '" - << to_utf8(seq->print()) + << to_utf8(seq->print(false)) << "' is overriding old binding..." << endl; if (it->table.get()) { @@ -263,7 +257,7 @@ void kb_keymap::defkey(kb_sequence * seq return; } else if (!it->table.get()) { lyxerr << "Error: New binding for '" - << to_utf8(seq->print()) + << to_utf8(seq->print(false)) << "' is overriding old binding..." << endl; return; @@ -296,7 +290,7 @@ docstring const kb_keymap::printbindings Bindings bindings = findbindings(func); for (Bindings::const_iterator cit = bindings.begin(); cit != bindings.end() ; ++cit) - res << '[' << cit->print() << ']'; + res << '[' << cit->print(true) << ']'; return res.str(); } Index: src/MenuBackend.C =================================================================== --- src/MenuBackend.C (revision 16479) +++ src/MenuBackend.C (working copy) @@ -144,7 +144,7 @@ docstring const MenuItem::binding() cons kb_keymap::Bindings bindings = theTopLevelKeymap().findbindings(func_); if (bindings.size()) { - return bindings.begin()->print(); + return bindings.begin()->print(false); } else { lyxerr[Debug::KBMAP] << "No binding for " Index: src/kbmap.h =================================================================== --- src/kbmap.h (revision 16479) +++ src/kbmap.h (working copy) @@ -45,8 +45,12 @@ public: // Parse a bind file bool read(std::string const & bind_file); - /// print all available keysyms - docstring const print() const; + /** + * print all available keysyms + * @param forgui true if the string should use translations and + * special characters. + */ + docstring const print(bool forgui) const; /** * Look up a key press in the keymap. @@ -110,9 +114,6 @@ private: void defkey(kb_sequence * seq, FuncRequest const & func, unsigned int r = 0); - /// Returns a string of the given key - docstring const printKey(kb_key const & key) const; - /** * Given an action, find all keybindings * @param func the action