+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
+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
#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;
label.insert(pos, 1, '&');
}
- if (mi.kind() == MenuItem::Command) {
- string const binding(mi.binding());
- if (!binding.empty()) {
- label += '\t' + binding;
- }
- }
-
return label;
}
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));
}
}
-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)
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));
}
*/
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_;
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);
+}
/// 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