>>>>> "Abdelrazak" == Abdelrazak Younes <[EMAIL PROTECTED]> writes:

Abdelrazak> Jean-Marc Lasgouttes wrote:
>>  I am beginning to wonder whether we should disable all menu
>> merging, as Qt/Mac allows us to do.

Abdelrazak> I think this is a sound solution, at least for 1.5.0.

Let's try to be more ambitious. This patch tries to reimplement the
feature. It is cleaner than the previous one because (1) the use of
Action helps and (2) I think I got a better idea. The idea remains
basically the same, though.

The merging can be disabled by commenting out
 #define MERGE_MAC_MENUS
in QLPopups.h. The patches to GuiApplication.* and qt_helpers.h are
unrelated  cleanups and could be applied separately.

Also, I suspect that this fixes the behaviour of the menu when a
dialog is open.

Bennett, could you test the patch? I do not expect that it will work
at the first try... You could also test what happens when undefining
MERGE_MAC_MENUS, to see whether it would be an acceptable fallback.

Also a question: am I right that the bindings in menus are gone
currently?

JMarc

Index: src/frontends/qt4/qt_helpers.h
===================================================================
--- src/frontends/qt4/qt_helpers.h	(revision 16123)
+++ src/frontends/qt4/qt_helpers.h	(working copy)
@@ -89,7 +89,7 @@ inline void ucs4_to_qstring(char_type co
 {
 	int i = static_cast<int>(ls);
 	s.resize(i);
-	for (i ; --i >= 0; )
+	for ( ; --i >= 0; )
 		s[i] = ucs4_to_qchar(str[i]);
 }
 
Index: src/frontends/qt4/QLMenubar.C
===================================================================
--- src/frontends/qt4/QLMenubar.C	(revision 16123)
+++ src/frontends/qt4/QLMenubar.C	(working copy)
@@ -161,12 +161,17 @@ void QLMenubar::macxMenuBarInit()
 #ifdef Q_WS_MACX
 	mac_menubar_.reset(new QMenuBar);
 
+# ifdef MERGE_MAC_MENU
 	// this is the name of the menu that contains our special entries
 	menubackend_.specialMenu(lyx::from_ascii("LyX"));
 	// make sure that the special entries are added to the first
 	// menu even before this menu has been opened.
-	//name_map_[menubackend_.getMenubar().begin()->submenuname()]->update();
-#endif
+	docstring menuname = menubackend_.getMenubar().begin()->submenuname();
+	name_map_[menuname]->update();
+# else
+	qt_mac_set_menubar_merge(false);
+# endif // MERGE_MAC_MENU
+#endif // Q_WS_MACX
 }
 
 } // namespace frontend
Index: src/frontends/qt4/GuiApplication.C
===================================================================
--- src/frontends/qt4/GuiApplication.C	(revision 16123)
+++ src/frontends/qt4/GuiApplication.C	(working copy)
@@ -58,7 +58,7 @@ using std::endl;
 extern void initEncodings();
 
 ///////////////////////////////////////////////////////////////
-// You can find other X11 and MACX specific stuff
+// You can find other X11 specific stuff
 // at the end of this file...
 ///////////////////////////////////////////////////////////////
 
@@ -121,23 +121,6 @@ GuiApplication::GuiApplication(int & arg
 			<< "Could not find  Qt translations for locale "
 			<< fromqstr(language_name) << std::endl;
 
-/*#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
-	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"));
-
-	qApp->installTranslator(&aqua_trans);
-#endif
-*/
 	using namespace lyx::graphics;
 
 	Image::newImage = boost::bind(&QLImage::newImage);
Index: src/frontends/qt4/QLPopupMenu.C
===================================================================
--- src/frontends/qt4/QLPopupMenu.C	(revision 16123)
+++ src/frontends/qt4/QLPopupMenu.C	(working copy)
@@ -78,9 +78,8 @@ void QLPopupMenu::update()
 	if (!owner_->backend().hasMenu(topLevelMenu_.name())) {
 		lyxerr[Debug::GUI] << "\tWARNING: menu seems empty" << lyx::to_utf8(topLevelMenu_.name()) << endl;
 	}
+	specialMacXmenuHack(this);
 	populate(this, &topLevelMenu_);
-
-	specialMacXmenuHack();
 }
 
 void QLPopupMenu::populate(QMenu* qMenu, Menu * menu)
@@ -171,9 +170,9 @@ void QLPopupMenu::addBinding(docstring &
 }
 
 /// \todo Fix Mac specific menu hack
-void QLPopupMenu::specialMacXmenuHack()
+void QLPopupMenu::specialMacXmenuHack(QMenu * qMenu)
 {
-#ifdef Q_WS_MACX
+#ifdef MERGE_MAC_MENUS
 	/* 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
@@ -181,17 +180,19 @@ void QLPopupMenu::specialMacXmenuHack()
 	   always available. Since we build menus on demand,
 	   we add some dummy contents to one of the menus (JMarc)
 	*/
-/*
+
 	static QLPopupMenu * themenu = this;
-	if (themenu == this && owner_->backend().hasMenu("LyX")) {
-		Menu special = owner_->backend().getMenu("LyX");
+	if (themenu == this && owner_->backend().hasMenu(from_ascii("LyX"))) {
+		Menu special = owner_->backend().getMenu(from_ascii("LyX"));
 		Menu::const_iterator end = special.end();
 		Menu::size_type i = 0;
 		for (Menu::const_iterator cit = special.begin();
-		     cit != end ; ++cit, ++i)
-			insertItem(toqstr(cit->label()), indexOffset + i);
+		     cit != end ; ++cit, ++i) {
+			Action * action = new Action(*(owner_->view()),
+						     cit->label(), cit->func());
+			qMenu->addAction(action);
+		}
 	}
-*/
 #endif
 }
 
Index: src/frontends/qt4/GuiApplication.h
===================================================================
--- src/frontends/qt4/GuiApplication.h	(revision 16123)
+++ src/frontends/qt4/GuiApplication.h	(working copy)
@@ -23,14 +23,6 @@
 
 #include <QApplication>
 
-///////////////////////////////////////////////////////////////
-// Specific stuff
-
-#ifdef Q_WS_MACX
-#include <Carbon/Carbon.h>
-#endif
-///////////////////////////////////////////////////////////////
-
 namespace lyx {
 
 class BufferView;
Index: src/frontends/qt4/QLPopupMenu.h
===================================================================
--- src/frontends/qt4/QLPopupMenu.h	(revision 16123)
+++ src/frontends/qt4/QLPopupMenu.h	(working copy)
@@ -17,6 +17,13 @@
 #include "funcrequest.h"
 #include "MenuBackend.h"
 
+#ifdef Q_WS_MAC
+# define MERGE_MAC_MENUS
+# ifndef MERGE_MAC_MENUS
+extern void qt_mac_set_menubar_merge(bool b);
+# endif
+#endif
+
 namespace lyx {
 namespace frontend {
 
@@ -58,7 +65,7 @@ private:
 
 	/// Mac specific menu hack
 	/// \todo Fix it
-	void specialMacXmenuHack();
+	void specialMacXmenuHack(QMenu * qMenu);
 };
 
 } // namespace frontend

Reply via email to