>>>>> "Jean-Marc" == Jean-Marc Lasgouttes <[EMAIL PROTECTED]> writes:

>>>>> "Angus" == Angus Leeming <[EMAIL PROTECTED]> writes:
>>> However, since we are supposedly in freeze time, I came up with
>>> the attached kludgy but simple patch. It adds a method to
>>> kb_keymap that returns the first 1-key binding to a FuncRequest.
>>> This is much easier than writing the complete recursive version,
>>> but I can try to do that if people prefer.

Angus> Would be nice. Kludges tend not to get fixed...

Jean-Marc> I'll wait to see what Lars prefers... This would mean some
Jean-Marc> changes in how MenuBackend works. And since I would like to
Jean-Marc> push some changes in there to fix the remaining OSX menu
Jean-Marc> bug, I save my karma points for later :)

OK, I have updated my kludgy patch. Lars, would that be acceptable to
you? The code only affects OSX.

JMarc
 
Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.1933
diff -u -p -r1.1933 ChangeLog
--- src/ChangeLog	5 Jul 2004 14:34:49 -0000	1.1933
+++ src/ChangeLog	5 Jul 2004 15:53:00 -0000
@@ -1,3 +1,8 @@
+2004-06-24  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* kbmap.C (find1keybinding): new method, only used by LyX/Mac with
+	Qt frontend
+
 2004-07-05  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
 	* BufferView_pimpl.C (setBuffer): set the layout combox value only
Index: src/kbmap.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/kbmap.C,v
retrieving revision 1.54
diff -u -p -r1.54 kbmap.C
--- src/kbmap.C	2 Jul 2004 10:03:21 -0000	1.54
+++ src/kbmap.C	5 Jul 2004 15:53:00 -0000
@@ -325,3 +325,17 @@ kb_keymap::findbindings(FuncRequest cons
 
 	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: src/kbmap.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/kbmap.h,v
retrieving revision 1.34
diff -u -p -r1.34 kbmap.h
--- src/kbmap.h	2 Jul 2004 10:03:22 -0000	1.34
+++ src/kbmap.h	5 Jul 2004 15:53:00 -0000
@@ -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
Index: src/frontends/qt2/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/ChangeLog,v
retrieving revision 1.696
diff -u -p -r1.696 ChangeLog
--- src/frontends/qt2/ChangeLog	23 Jun 2004 14:04:09 -0000	1.696
+++ src/frontends/qt2/ChangeLog	5 Jul 2004 15:53:00 -0000
@@ -1,3 +1,11 @@
+2004-07-05  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* 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  <[EMAIL PROTECTED]>
 
 	* lyx_gui.C (getStatus): under Mac OS X, disable the
Index: src/frontends/qt2/QLPopupMenu.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLPopupMenu.C,v
retrieving revision 1.31
diff -u -p -r1.31 QLPopupMenu.C
--- src/frontends/qt2/QLPopupMenu.C	20 May 2004 09:36:27 -0000	1.31
+++ src/frontends/qt2/QLPopupMenu.C	5 Jul 2004 15:53:01 -0000
@@ -22,6 +22,12 @@
 
 #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 & m
 			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: src/frontends/qt2/QLyXKeySym.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLyXKeySym.C,v
retrieving revision 1.31
diff -u -p -r1.31 QLyXKeySym.C
--- src/frontends/qt2/QLyXKeySym.C	20 May 2004 09:36:27 -0000	1.31
+++ src/frontends/qt2/QLyXKeySym.C	5 Jul 2004 15:53:01 -0000
@@ -169,11 +169,10 @@ char QLyXKeySym::getISOEncoded(string co
 }
 
 
-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_modif
 	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: src/frontends/qt2/QLyXKeySym.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLyXKeySym.h,v
retrieving revision 1.17
diff -u -p -r1.17 QLyXKeySym.h
--- src/frontends/qt2/QLyXKeySym.h	26 Mar 2004 15:12:35 -0000	1.17
+++ src/frontends/qt2/QLyXKeySym.h	5 Jul 2004 15:53:01 -0000
@@ -55,8 +55,11 @@ 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 {

Reply via email to