From: Stefan Schimanski Date: Fri, 14 Mar 2008 15:34:31 +0000 (+0000) Subject: * we have not only one instance of the menu bar. Hence we better take the right Menu... X-Git-Tag: 1.6.10~5653 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=3a7c68d3f75a45c9751c06803ccb82dde9081aaa;p=features.git * we have not only one instance of the menu bar. Hence we better take the right Menu objects of the current buffer. Otherwise we easily get crashes if the last GuiView is closed. The Menu objects are gone then too. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23717 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 8f81ddb051..27b2f98090 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -1145,9 +1145,10 @@ Menu::~Menu() void Menu::updateView() { - guiApp->menus().updateMenu(d->name); + guiApp->menus().updateMenu(this); } + ///////////////////////////////////////////////////////////////////// // Menus::Impl definition and implementation ///////////////////////////////////////////////////////////////////// @@ -1183,7 +1184,7 @@ struct Menus::Impl { /// MenuDefinition menubar_; - typedef QHash NameMap; + typedef QMap > NameMap; /// name to menu for \c menu() method. NameMap name_map_; @@ -1510,17 +1511,16 @@ void Menus::fillMenuBar(GuiView * view) Menu * menu = new Menu(view, m->submenuname(), true); menu->setTitle(label(*m)); - view->menuBar()->addMenu(menu); + qmb->addMenu(menu); - d->name_map_[name] = menu; + d->name_map_[view][name] = menu; } } -void Menus::updateMenu(QString const & name) +void Menus::updateMenu(Menu * qmenu) { - Menu * qmenu = d->name_map_[name]; - LYXERR(Debug::GUI, "Triggered menu: " << fromqstr(name)); + LYXERR(Debug::GUI, "Triggered menu: " << fromqstr(qmenu->d->name)); qmenu->clear(); if (qmenu->d->name.isEmpty()) @@ -1529,14 +1529,14 @@ void Menus::updateMenu(QString const & name) // Here, We make sure that theLyXFunc points to the correct LyXView. theLyXFunc().setLyXView(qmenu->d->view); - if (!d->hasMenu(name)) { + if (!d->hasMenu(qmenu->d->name)) { qmenu->addAction(qt_("No action defined!")); LYXERR(Debug::GUI, "\tWARNING: non existing menu: " << fromqstr(qmenu->d->name)); return; } - MenuDefinition const & fromLyxMenu = d->getMenu(name); + MenuDefinition const & fromLyxMenu = d->getMenu(qmenu->d->name); d->expand(fromLyxMenu, *qmenu->d->top_level_menu, qmenu->d->view->buffer()); qmenu->d->populate(*qmenu, *qmenu->d->top_level_menu); } @@ -1545,14 +1545,14 @@ void Menus::updateMenu(QString const & name) Menu * Menus::menu(QString const & name, GuiView & view) { LYXERR(Debug::GUI, "Context menu requested: " << fromqstr(name)); - Menu * menu = d->name_map_.value(name, 0); + Menu * menu = d->name_map_[&view].value(name, 0); if (!menu && !name.startsWith("context-")) { LYXERR0("requested context menu not found: " << fromqstr(name)); return 0; } menu = new Menu(&view, name, true); - d->name_map_[name] = menu; + d->name_map_[&view][name] = menu; return menu; } diff --git a/src/frontends/qt4/Menus.h b/src/frontends/qt4/Menus.h index 3fed41719d..80de0da292 100644 --- a/src/frontends/qt4/Menus.h +++ b/src/frontends/qt4/Menus.h @@ -37,8 +37,9 @@ public: /// Menu(GuiView * gv, QString const & name, bool top_level); + /// ~Menu(); - + private Q_SLOTS: /// void updateView(); @@ -71,7 +72,7 @@ public: void read(Lexer &); /// - void updateMenu(QString const & name); + void updateMenu(Menu * qmenu); private: /// Use the Pimpl idiom to hide the internals.