]> git.lyx.org Git - features.git/commitdiff
make bindings appear in LyX/Mac menus
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 7 Jul 2004 09:32:19 +0000 (09:32 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 7 Jul 2004 09:32:19 +0000 (09:32 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8836 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/frontends/qt2/ChangeLog
src/frontends/qt2/QLPopupMenu.C
src/frontends/qt2/QLyXKeySym.C
src/frontends/qt2/QLyXKeySym.h
src/kbmap.C
src/kbmap.h

index bdcb5dd7f876c60596746a50b93d6dc24f234772..8f181310ad3d55959e0e8d587259dd6497bbc5f7 100644 (file)
@@ -1,3 +1,8 @@
+2004-06-24  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * kbmap.C (find1keybinding): new method, only used by LyX/Mac with
+       Qt frontend
+
 2004-07-05  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * BufferView_pimpl.C (setBuffer): set the layout combox value only
index eb15c360ac65844a5bfe0631894ee3cad89a1d42..752aa70c6fbf4cd7cdbb6549fff32525559ad4c2 100644 (file)
@@ -1,3 +1,11 @@
+2004-07-05  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * 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  <lasgouttes@lyx.org>
 
        * lyx_gui.C (getStatus): under Mac OS X, disable the
index 6a72c221845da29ee1c2b57ceb852754a07cb493..083f86846e7fa6b8696642c2b719519cc5645f3c 100644 (file)
 
 #include "support/lstrings.h"
 
+#ifdef Q_WS_MACX
+#include "kbmap.h"
+#include "QLyXKeySym.h"
+extern boost::scoped_ptr<kb_keymap> 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<LyXKeySym const *, key_modifier::state>
+                               binding = toplevel_keymap->find1keybinding(m->func());
+                       if (binding.first) {
+                               QLyXKeySym const *key = static_cast<QLyXKeySym const *>(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));
                }
index e904c16ef144e6e092965966c03a631a2d2ddb22..09b1797453e5d04d9e7329705b5ca456d6e29989 100644 (file)
@@ -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));
 }
 
 
index 96f359c9d185361600b1606d36183e829e068cd5..a0d18af290453bbc7e786937df0d9fa208e4a99b 100644 (file)
@@ -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_;
index 55f7b025238b0d530957525ccaf6bb48e754d660..280a72df58878e770b978496b0aabe17c014cb94 100644 (file)
@@ -325,3 +325,17 @@ kb_keymap::findbindings(FuncRequest const & func,
 
        return res;
 }
+
+
+std::pair<LyXKeySym const *, key_modifier::state>
+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<LyXKeySym const *, key_modifier::state>(0, key_modifier::none);
+}      
index a5ea729b49340d7be4897d402a341344b9cc20cf..3648f14bc3fd8de7b0f2a5c2e475ea0fc0183338 100644 (file)
@@ -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<LyXKeySym const *, key_modifier::state>
+       find1keybinding(FuncRequest const & func) const;
+
+
        /**
         * Returns a string of the given keysym, with modifiers.
         * @param key the key as a keysym