* 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
This commit is contained in:
Stefan Schimanski 2008-03-14 15:34:31 +00:00
parent 23b74676a2
commit 3a7c68d3f7
2 changed files with 14 additions and 13 deletions

View File

@ -1145,9 +1145,10 @@ Menu::~Menu()
void Menu::updateView() void Menu::updateView()
{ {
guiApp->menus().updateMenu(d->name); guiApp->menus().updateMenu(this);
} }
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// Menus::Impl definition and implementation // Menus::Impl definition and implementation
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
@ -1183,7 +1184,7 @@ struct Menus::Impl {
/// ///
MenuDefinition menubar_; MenuDefinition menubar_;
typedef QHash<QString, Menu *> NameMap; typedef QMap<GuiView *, QHash<QString, Menu *> > NameMap;
/// name to menu for \c menu() method. /// name to menu for \c menu() method.
NameMap name_map_; NameMap name_map_;
@ -1510,17 +1511,16 @@ void Menus::fillMenuBar(GuiView * view)
Menu * menu = new Menu(view, m->submenuname(), true); Menu * menu = new Menu(view, m->submenuname(), true);
menu->setTitle(label(*m)); 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(qmenu->d->name));
LYXERR(Debug::GUI, "Triggered menu: " << fromqstr(name));
qmenu->clear(); qmenu->clear();
if (qmenu->d->name.isEmpty()) 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. // Here, We make sure that theLyXFunc points to the correct LyXView.
theLyXFunc().setLyXView(qmenu->d->view); theLyXFunc().setLyXView(qmenu->d->view);
if (!d->hasMenu(name)) { if (!d->hasMenu(qmenu->d->name)) {
qmenu->addAction(qt_("No action defined!")); qmenu->addAction(qt_("No action defined!"));
LYXERR(Debug::GUI, "\tWARNING: non existing menu: " LYXERR(Debug::GUI, "\tWARNING: non existing menu: "
<< fromqstr(qmenu->d->name)); << fromqstr(qmenu->d->name));
return; 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()); d->expand(fromLyxMenu, *qmenu->d->top_level_menu, qmenu->d->view->buffer());
qmenu->d->populate(*qmenu, *qmenu->d->top_level_menu); 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) Menu * Menus::menu(QString const & name, GuiView & view)
{ {
LYXERR(Debug::GUI, "Context menu requested: " << fromqstr(name)); 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-")) { if (!menu && !name.startsWith("context-")) {
LYXERR0("requested context menu not found: " << fromqstr(name)); LYXERR0("requested context menu not found: " << fromqstr(name));
return 0; return 0;
} }
menu = new Menu(&view, name, true); menu = new Menu(&view, name, true);
d->name_map_[name] = menu; d->name_map_[&view][name] = menu;
return menu; return menu;
} }

View File

@ -37,6 +37,7 @@ public:
/// ///
Menu(GuiView * gv, QString const & name, bool top_level); Menu(GuiView * gv, QString const & name, bool top_level);
///
~Menu(); ~Menu();
private Q_SLOTS: private Q_SLOTS:
@ -71,7 +72,7 @@ public:
void read(Lexer &); void read(Lexer &);
/// ///
void updateMenu(QString const & name); void updateMenu(Menu * qmenu);
private: private:
/// Use the Pimpl idiom to hide the internals. /// Use the Pimpl idiom to hide the internals.