]> git.lyx.org Git - features.git/commitdiff
* fix crashing special menu items on Mac after preferences have been changed.
authorStefan Schimanski <sts@lyx.org>
Wed, 22 Oct 2008 18:02:09 +0000 (18:02 +0000)
committerStefan Schimanski <sts@lyx.org>
Wed, 22 Oct 2008 18:02:09 +0000 (18:02 +0000)
* fix duplicated special menu items in Mac (fixed bug #5168)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27022 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/Menus.cpp

index 937b3199755019d3e39c7ca40872d7ca9fc05d5e..413434aec12dcdfc61daa8eeaecc6134da7af0ac 100644 (file)
@@ -914,17 +914,8 @@ void GuiApplication::resetGui()
                // Gives some error box here.
                return;
 
-#ifdef Q_WS_MACX
-       d->global_menubar_->clear();
-       delete d->global_menubar_;
-       // Create the global default menubar which is shown for the dialogs
-       // and if no GuiView is visible.
-       d->global_menubar_ = new GlobalMenuBar();
-
-       // init the global menubar on Mac. This must be done after the session
-       // was recovered to know the "last files".
-       d->menus_.fillMenuBar(d->global_menubar_, 0, true);
-#endif
+       if (d->global_menubar_)
+               d->menus_.fillMenuBar(d->global_menubar_, 0, false);
 
        QHash<int, GuiView *>::iterator it;
        for (it = d->views_.begin(); it != d->views_.end(); ++it) {
index e21be78af7ed620a0409f29e31188c57823e73d9..ca606f6369fbfbc36c2caa8a33bfe51c066bfcee 100644 (file)
@@ -2235,7 +2235,7 @@ void GuiView::resetDialogs()
        saveLayout();
        menuBar()->clear();
        constructToolbars();
-       guiApp->menus().fillMenuBar(menuBar(), this, true);
+       guiApp->menus().fillMenuBar(menuBar(), this, false);
        if (d.layout_)
                d.layout_->updateContents(true);
        // Now update controls with current buffer.
index 48d3bfe70146b128b3487262912360b7f1f814fa..f40c54fa964bf946abc0b53ae1bd10b397302fea 100644 (file)
@@ -1225,9 +1225,14 @@ struct Menus::Impl {
        /// Mac special menu.
        /** This defines a menu whose entries list the FuncRequests
            that will be removed by expand() in other menus. This is
-           used by the Qt/Mac code
+           used by the Qt/Mac code.
+
+           NOTE: Qt does not remove the menu items when clearing a QMenuBar,
+           such that the items will keep accessing the FuncRequests in
+           the MenuDefinition. While Menus::Impl might be recreated,
+           we keep mac_special_menu_ in memory by making it static.
        */
-       MenuDefinition specialmenu_;
+       static MenuDefinition mac_special_menu_;
 
        ///
        MenuList menulist_;
@@ -1240,6 +1245,10 @@ struct Menus::Impl {
        NameMap name_map_;
 };
 
+
+MenuDefinition Menus::Impl::mac_special_menu_;
+
+
 /*
   Here is what the Qt documentation says about how a menubar is chosen:
 
@@ -1296,11 +1305,11 @@ void Menus::Impl::macxMenuBarInit(GuiView * view, QMenuBar * qmb)
        const size_t num_entries = sizeof(entries) / sizeof(entries[0]);
 
        // the special menu for Menus. Fill it up only once.
-       if (specialmenu_.size() == 0) {
+       if (mac_special_menu_.size() == 0) {
                for (size_t i = 0 ; i < num_entries ; ++i) {
                        FuncRequest const func(entries[i].action,
                                from_utf8(entries[i].arg));
-                       specialmenu_.add(MenuItem(MenuItem::Command, 
+                       mac_special_menu_.add(MenuItem(MenuItem::Command,
                                entries[i].label, func));
                }
        }
@@ -1308,8 +1317,8 @@ void Menus::Impl::macxMenuBarInit(GuiView * view, QMenuBar * qmb)
        // add the entries to a QMenu that will eventually be empty
        // and therefore invisible.
        QMenu * qMenu = qmb->addMenu("special");
-       MenuDefinition::const_iterator cit = specialmenu_.begin();
-       MenuDefinition::const_iterator end = specialmenu_.end();
+       MenuDefinition::const_iterator cit = mac_special_menu_.begin();
+       MenuDefinition::const_iterator end = mac_special_menu_.end();
        for (size_t i = 0 ; cit != end ; ++cit, ++i) {
                Action * action = new Action(view, QIcon(), cit->label(),
                        cit->func(), QString(), qMenu);
@@ -1405,7 +1414,7 @@ void Menus::Impl::expand(MenuDefinition const & frommenu,
                        break;
 
                case MenuItem::Command:
-                       if (!specialmenu_.hasFunc(cit->func()))
+                       if (!mac_special_menu_.hasFunc(cit->func()))
                                tomenu.addWithStatusCheck(*cit);
                }
        }
@@ -1535,7 +1544,11 @@ void Menus::fillMenuBar(QMenuBar * qmb, GuiView * view, bool initial)
 {
        if (initial) {
 #ifdef Q_WS_MACX
-               // setup special mac specific menu item
+               // setup special mac specific menu items, but only do this
+               // the first time a QMenuBar is created. Otherwise Qt will
+               // create duplicate items in the application menu. It seems
+               // that Qt does not remove them when the QMenubar is cleared.
+               LYXERR(Debug::GUI, "Creating Mac OS X special menu bar");
                d->macxMenuBarInit(view, qmb);
 #endif
        } else {