Here is an updated version of the patch this purports to fix menu
merging with Qt/Mac. Unlike previous incarnations, this one has a
chance to work properly.

I'd appreciate to see it get some testing (Bennett, Nirmal, for when
you come back from vacation...).

JMarc

Index: src/frontends/qt2/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/ChangeLog,v
retrieving revision 1.704
diff -u -p -r1.704 ChangeLog
--- src/frontends/qt2/ChangeLog	9 Aug 2004 13:00:30 -0000	1.704
+++ src/frontends/qt2/ChangeLog	9 Aug 2004 13:18:57 -0000
@@ -1,3 +1,16 @@
+2004-07-12  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* lyx_gui.C (parse_init): add a new translator whose sole purpose
+	is to hide some menu entries from Qt/Mac scrutiniy and avoid some
+	menu merging.
+
+	* QLMenubar.C (QLMenubar): remove special code to work around
+	Qt/Mac menu merging madness.
+
+	* QLPopupMenu.C (QLPopupMenu): add dummy entries to toplevel menus
+	(so that Qt/Mac moves them to the LyX menu)
+	(fire): recognize special values of index under Qt/Mac
+
 2004-08-09  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
 	* FileDialog.C: #define USE_NATIVE_FILEDIALOG under LyX/Mac
Index: src/frontends/qt2/QLMenubar.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLMenubar.C,v
retrieving revision 1.9
diff -u -p -r1.9 QLMenubar.C
--- src/frontends/qt2/QLMenubar.C	9 Jun 2004 14:10:27 -0000	1.9
+++ src/frontends/qt2/QLMenubar.C	9 Aug 2004 13:18:57 -0000
@@ -22,7 +22,6 @@
 #include <qmenubar.h>
 #include <qcursor.h>
 
-
 using std::pair;
 using std::string;
 
@@ -41,17 +40,6 @@ QLMenubar::QLMenubar(LyXView * view, Men
 		pair<int, QLPopupMenu *> menu =
 			createMenu(menuBar(), &(*m), this, true);
 		name_map_[m->submenuname()] = menu.second;
-#ifdef Q_WS_MACX
-		/* The qt/mac menu code has a very silly hack that
-		   moves some menu entries that it recognizes by name
-		   (ex: "Preferences...") to the "LyX" menu. This
-		   feature can only work if the menu entries are
-		   always available. Since we build menus on demand,
-		   we have to have a reasonable default value before
-		   the menus have been explicitely opened. (JMarc)
-		*/
-		menu.second->showing();
-#endif
 	}
 }
 
Index: src/frontends/qt2/QLPopupMenu.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLPopupMenu.C,v
retrieving revision 1.32
diff -u -p -r1.32 QLPopupMenu.C
--- src/frontends/qt2/QLPopupMenu.C	7 Jul 2004 09:32:19 -0000	1.32
+++ src/frontends/qt2/QLPopupMenu.C	9 Aug 2004 13:18:57 -0000
@@ -55,6 +55,14 @@ string const getLabel(MenuItem const & m
 	return label;
 }
 
+#ifdef Q_WS_MACX
+// some constants needed for special handling of Mac menus
+// They are chosen to be large enough to avoid clashes with real menu indices.
+const int aboutIndex = 5001;
+const int prefsIndex = 5002;
+const int quitIndex = 5003;
+#endif
+
 } // namespace anon
 
 
@@ -77,12 +85,42 @@ QLPopupMenu::QLPopupMenu(QLMenubar * own
 		connect(this, SIGNAL(aboutToShow()), this, SLOT(showing()));
 	connect(this, SIGNAL(activated(int)),
 		this, SLOT(fire(int)));
+#ifdef Q_WS_MACX
+	/* The qt/mac menu code has a very silly hack that
+	   moves some menu entries that it recognizes by name
+	   (e.g. "Preferences...") to the "LyX" menu. This
+	   feature can only work if the menu entries are
+	   always available. Since we build menus on demand,
+	   we add some dummy contents to each menu (JMarc)
+	*/
+	if (toplevel) {
+		insertItem("About LyX", aboutIndex);
+		insertItem("Preferences...", prefsIndex);
+		insertItem("Quit LyX", quitIndex);
+	}
+#endif
 }
 
 
 void QLPopupMenu::fire(int index)
 {
+#ifdef Q_WS_MACX
+	switch (index) {
+	case aboutIndex:
+		owner_->view()->activated(FuncRequest(LFUN_DIALOG_SHOW, "aboutlyx"));
+		break;
+	case prefsIndex:
+		owner_->view()->activated(FuncRequest(LFUN_DIALOG_SHOW, "prefs"));
+		break;
+	case quitIndex:
+		owner_->view()->activated(FuncRequest(LFUN_QUIT));
+		break;
+	default:
+		owner_->view()->activated(funcs_[index]);
+	}
+#else
 	owner_->view()->activated(funcs_[index]);
+#endif
 }
 
 
@@ -99,7 +137,7 @@ void QLPopupMenu::populate(Menu * menu)
 			pair<int, QLPopupMenu *> res = createMenu(this, &(*m), owner_);
 			setItemEnabled(res.first, m->status().enabled());
 			res.second->populate(m->submenu());
-		} else {
+		} else { // we have a MenuItem::Command
 			FuncStatus const status = m->status();
 
 			Funcs::iterator fit =
@@ -129,6 +167,8 @@ void QLPopupMenu::populate(Menu * menu)
 				label += '\t' + toqstr(binding);
 			}
 #endif
+
+			// Actually insert the menu item
 			insertItem(label, index);
 			setItemEnabled(index, status.enabled());
 			setItemChecked(index, status.onoff(true));
Index: src/frontends/qt2/lyx_gui.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/lyx_gui.C,v
retrieving revision 1.69
diff -u -p -r1.69 lyx_gui.C
--- src/frontends/qt2/lyx_gui.C	8 Aug 2004 22:37:39 -0000	1.69
+++ src/frontends/qt2/lyx_gui.C	9 Aug 2004 13:18:57 -0000
@@ -152,7 +152,6 @@ namespace lyx_gui {
 
 bool use_gui = true;
 
-
 void parse_init(int & argc, char * argv[])
 {
 	static LQApplication app(argc, argv);
@@ -173,6 +172,23 @@ void parse_init(int & argc, char * argv[
 		lyxerr[Debug::GUI]
 			<< "Could not find  Qt translations for locale "
 			<< QTextCodec::locale() << std::endl;
+#endif
+
+#ifdef Q_WS_MACX
+	// These translations are meant to break Qt/Mac menu merging
+	// algorithm on some entries. It lists the menu names that
+	// should not be moved to the LyX menu
+	static QTranslator aqua_trans(0);
+	aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setting", 0, 
+					     "do_not_merge_me"));
+	aqua_trans.insert(QTranslatorMessage("QMenuBar", "Config", 0, 
+					     "do_not_merge_me"));
+	aqua_trans.insert(QTranslatorMessage("QMenuBar", "Options", 0, 
+					     "do_not_merge_me"));
+	aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setup", 0, 
+					     "do_not_merge_me"));
+
+	app.installTranslator(&aqua_trans);
 #endif
 
 	using namespace lyx::graphics;

Reply via email to