]> git.lyx.org Git - lyx.git/commitdiff
Make the shortcuts work correctly with the mac.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 4 Jan 2007 17:10:24 +0000 (17:10 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 4 Jan 2007 17:10:24 +0000 (17:10 +0000)
* src/frontends/LyXKeySym.h:
* src/frontends/qt4/QLyXKeySym.h:
* src/frontends/qt4/QLyXKeySym.C (print): add a forgui boolean that
tells whether the string should used localized names and special
characters.

* src/MenuBackend.C (binding):
* src/kbmap.C (print):
* src/kbsequence.C (print, printOptions): add forgui parameter.

* src/frontends/qt4/QLPopupMenu.C (addBinding): use a non-localaized
binding for Qt/Mac (because it needs to be parsed back) and a
localized one for the others (so that it looks good).

* src/kbmap.C (defkey,printbindings):
* src/lyxfunc.C (processKeySym,dispatch,viewStatusMessage): adapt to
above changes.

* src/kbmap.C (printKey): remove.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16510 a592a061-630c-0410-9148-cb99ea01b6c8

src/MenuBackend.C
src/MenuBackend.h
src/frontends/LyXKeySym.h
src/frontends/qt4/QLPopupMenu.C
src/frontends/qt4/QLyXKeySym.C
src/frontends/qt4/QLyXKeySym.h
src/kbmap.C
src/kbmap.h
src/kbsequence.C
src/kbsequence.h
src/lyxfunc.C

index d113efda010019f7b80e9d06172464262075c42c..81d6a5db90fcb3d41f08ab7cd48de15880425af1 100644 (file)
@@ -134,7 +134,7 @@ docstring const MenuItem::shortcut() const
 }
 
 
-docstring const MenuItem::binding() const
+docstring const MenuItem::binding(bool forgui) const
 {
        if (kind_ != Command)
                return docstring();
@@ -144,7 +144,7 @@ docstring const MenuItem::binding() const
        kb_keymap::Bindings bindings = theTopLevelKeymap().findbindings(func_);
 
        if (bindings.size()) {
-               return bindings.begin()->print();
+               return bindings.begin()->print(forgui);
        } else {
                lyxerr[Debug::KBMAP]
                        << "No binding for "
index 7d2fd84a354d50e315e0060d5b608293d08aa012..903b130630f4c1942ececb41e4a5964d7985e4ff 100644 (file)
@@ -110,8 +110,11 @@ public:
        FuncStatus & status() { return status_; }
        /// returns the status of the lfun associated with this entry
        void status(FuncStatus const & status) { status_ = status; }
-       /// returns the binding associated to this action
-       docstring const binding() const;
+       /**
+        * returns the binding associated to this action.        
+        * Use the native UI format when \c forgui is true.
+        */
+       docstring const binding(bool forgui) const;
        /// the description of the  submenu (if relevant)
        docstring const & submenuname() const { return submenuname_; }
        /// set the description of the  submenu
index b5b536b8d95dfd7255a5d1ac90a2b8050324e0ef..618082ee2c3bf1af3ddea42cab350d0f2ed81723 100644 (file)
@@ -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 9410f602811f500892de556bf20d104799d97e9d..e92ddd4c2c4d97b9c85fc6c160d98932c790ac17 100644 (file)
@@ -136,7 +136,11 @@ docstring const QLPopupMenu::getLabel(MenuItem const & mi)
 
 void QLPopupMenu::addBinding(docstring & label, MenuItem const & mi)
 {
-       docstring const binding(mi.binding());
+#ifdef Q_WS_MACX
+       docstring const binding(mi.binding(false));
+#else
+       docstring const binding(mi.binding(true));
+#endif
        if (!binding.empty()) {
                label += '\t' + binding;
        }
index a6450ed1aa64a0c99058a16e39180665691a4634..c6ef16a2ad6b69d42a6641c9aeec386dc4ce1c64 100644 (file)
@@ -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_modifier::state mod) const
                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 6060189b2c322ea249f287d816a12c97188fa74e..9fc85fc3ee1ea31f0bfbf89ce48591a8d8155b1c 100644 (file)
@@ -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 5c197eb14a8884b4a09b9ed72fcb9161b802c725..b026b8630fee0a19c8565bfd159533b79080bc18 100644 (file)
@@ -55,12 +55,6 @@ string const kb_keymap::printKeySym(LyXKeySym const & key,
 }
 
 
-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;
@@ -294,7 +288,7 @@ docstring const kb_keymap::printbindings(FuncRequest const & func) const
        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 029a4e1b4eafcf406187ddd9b9eb132a77629a3d..2ffe6885f15c2c452fb40a0f1b7a0364e4fcaa57 100644 (file)
@@ -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
index f37afa95767c685d511bd5c58202dd2d11a8be07..9277793fcc0e7164a73078e26b9a7000f87f88ce 100644 (file)
@@ -130,17 +130,14 @@ string::size_type kb_sequence::parse(string const & s)
 }
 
 
-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() const
 }
 
 
-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 6fa089880cfcf86f852d0b440f0fd79e8d5a7b28..6dc269a0357687f9f3e343c8927992a5a4036848 100644 (file)
@@ -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 77de3364170753511cf6a934256d0a731821c0f1..a631c42d356c095f792f983eb5dff2f30f06a154 100644 (file)
@@ -294,7 +294,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
                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 keysym, key_modifier::state state)
        // num_bytes == 0? (Lgb)
 
        if (keyseq->length() > 1) {
-               lyx_view_->message(keyseq->print());
+               lyx_view_->message(keyseq->print(true));
        }
 
 
@@ -788,7 +788,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                case LFUN_COMMAND_PREFIX:
                        BOOST_ASSERT(lyx_view_);
-                       lyx_view_->message(keyseq->printOptions());
+                       lyx_view_->message(keyseq->printOptions(true));
                        break;
 
                case LFUN_COMMAND_EXECUTE:
@@ -809,7 +809,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                case LFUN_META_PREFIX:
                        meta_fake_bit = key_modifier::alt;
-                       setMessage(keyseq->print());
+                       setMessage(keyseq->print(true));
                        break;
 
                case LFUN_BUFFER_TOGGLE_READ_ONLY:
@@ -1169,7 +1169,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                case LFUN_SERVER_NOTIFY:
-                       dispatch_buffer = keyseq->print();
+                       dispatch_buffer = keyseq->print(false);
                        theLyXServer().notifyClient(to_utf8(dispatch_buffer));
                        break;
 
@@ -2035,12 +2035,12 @@ docstring const LyXFunc::viewStatusMessage()
 {
        // 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!");