diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 7e2f25f5df..a290de8d95 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -105,10 +105,11 @@ namespace { // This function runs "configure" and then rereads lyx.defaults to // reconfigure the automatic settings. -void reconfigure(LyXView & lv, string const & option) +void reconfigure(LyXView * lv, string const & option) { // emit message signal. - lv.message(_("Running configure...")); + if (lv) + lv->message(_("Running configure...")); // Run configure in user lyx directory PathChanger p(package().user_support()); @@ -118,7 +119,8 @@ void reconfigure(LyXView & lv, string const & option) int ret = one.startscript(Systemcall::Wait, configure_command); p.pop(); // emit message signal. - lv.message(_("Reloading configuration...")); + if (lv) + lv->message(_("Reloading configuration...")); lyxrc.read(libFileSearch(string(), "lyxrc.defaults")); // Re-read packages.lst LaTeXFeatures::getAvailable(); @@ -293,7 +295,8 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state) if (keysym.isModifier()) { LYXERR(Debug::KEY, "isModifier true"); - lyx_view_->restartCursor(); + if (lyx_view_) + lyx_view_->restartCursor(); return; } @@ -384,7 +387,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl; FuncStatus flag; - Buffer * buf = lyx_view_? lyx_view_->buffer() : 0; + Buffer * buf = lyx_view_ ? lyx_view_->buffer() : 0; if (cmd.action == LFUN_NOACTION) { flag.message(from_utf8(N_("Nothing to do"))); @@ -1039,9 +1042,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd) break; case LFUN_RECONFIGURE: - BOOST_ASSERT(lyx_view_); // argument is any additional parameter to the configure.py command - reconfigure(*lyx_view_, argument); + reconfigure(lyx_view_, argument); break; case LFUN_HELP_OPEN: { @@ -1659,8 +1661,11 @@ void LyXFunc::dispatch(FuncRequest const & cmd) // Nothing more to do. return; + // Everything below is only for active lyx_view_ + if (lyx_view_ == 0) + break; + // Let the current LyXView dispatch its own actions. - BOOST_ASSERT(lyx_view_); if (lyx_view_->dispatch(cmd)) { if (lyx_view_->view()) updateFlags = lyx_view_->view()->cursor().result().update(); diff --git a/src/frontends/qt4/Action.cpp b/src/frontends/qt4/Action.cpp index 006cf3a9fa..724d9daf8b 100644 --- a/src/frontends/qt4/Action.cpp +++ b/src/frontends/qt4/Action.cpp @@ -25,10 +25,10 @@ namespace lyx { namespace frontend { -Action::Action(GuiView & lyxView, QIcon const & icon, +Action::Action(GuiView * lyxView, QIcon const & icon, QString const & text, FuncRequest const & func, - QString const & tooltip) - : QAction(&lyxView), func_(func), lyxView_(lyxView) + QString const & tooltip, QObject * parent) + : QAction(parent), func_(func), lyxView_(lyxView) { // only Qt/Mac handles that setMenuRole(NoRole); @@ -62,7 +62,10 @@ void Action::update() void Action::action() { //LYXERR(Debug::ACTION, "calling LyXFunc::dispatch: func_: "); - theLyXFunc().setLyXView(&lyxView_); + + if (lyxView_) + theLyXFunc().setLyXView(lyxView_); + lyx::dispatch(func_); triggered(this); } diff --git a/src/frontends/qt4/Action.h b/src/frontends/qt4/Action.h index 7376a433d2..11a862b788 100644 --- a/src/frontends/qt4/Action.h +++ b/src/frontends/qt4/Action.h @@ -34,8 +34,8 @@ class Action : public QAction Q_OBJECT public: - Action(GuiView & lyxView, QIcon const & icon, QString const & text, - FuncRequest const & func, QString const & tooltip); + Action(GuiView * lyxView, QIcon const & icon, QString const & text, + FuncRequest const & func, QString const & tooltip, QObject * parent); void update(); @@ -48,7 +48,7 @@ private Q_SLOTS: private: FuncRequest const & func_ ; - GuiView & lyxView_; + GuiView * lyxView_; }; diff --git a/src/frontends/qt4/GuiToolbar.cpp b/src/frontends/qt4/GuiToolbar.cpp index f5563faa00..577d109433 100644 --- a/src/frontends/qt4/GuiToolbar.cpp +++ b/src/frontends/qt4/GuiToolbar.cpp @@ -839,9 +839,8 @@ GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner) Action * GuiToolbar::addItem(ToolbarItem const & item) { - Action * act = new Action(owner_, - getIcon(item.func_, false), - toqstr(item.label_), item.func_, toqstr(item.label_)); + Action * act = new Action(&owner_, getIcon(item.func_, false), + toqstr(item.label_), item.func_, toqstr(item.label_), this); actions_.append(act); return act; } diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 1f4ffe114d..4ff601ef91 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -278,7 +278,7 @@ GuiView::GuiView(int id) d.toolbars_ = new GuiToolbars(*this); // Fill up the menu bar. - guiApp->menus().fillMenuBar(this); + guiApp->menus().fillMenuBar(menuBar(), this); setCentralWidget(d.stack_widget_); @@ -2024,7 +2024,7 @@ void GuiView::resetDialogs() // FIXME: the "math panels" toolbar takes an awful lot of time to // initialise so we don't do that for the time being. //d.toolbars_->init(); - guiApp->menus().fillMenuBar(this); + guiApp->menus().fillMenuBar(menuBar(), this); if (d.layout_) d.layout_->updateContents(true); // Now update controls with current buffer. diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 27b2f98090..4ea1e0d27c 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -1114,8 +1114,8 @@ void Menu::Impl::populate(QMenu & qMenu, MenuDefinition const & menu) populate(*subMenu, m->submenu()); } else { // we have a MenuItem::Command - qMenu.addAction(new Action(*view, QIcon(), label(*m), m->func(), - QString())); + qMenu.addAction(new Action(view, QIcon(), label(*m), + m->func(), QString(), &qMenu)); } } } @@ -1167,10 +1167,10 @@ struct Menus::Impl { ViewFormats, ExportFormats, UpdateFormats, Branches */ void expand(MenuDefinition const & frommenu, MenuDefinition & tomenu, - Buffer const *) const; + Buffer const *) const; /// Initialize specific MACOS X menubar - void macxMenuBarInit(GuiView * view); + void macxMenuBarInit(GuiView * view, QMenuBar * qmb); /// Mac special menu. /** This defines a menu whose entries list the FuncRequests @@ -1211,7 +1211,7 @@ struct Menus::Impl { that this menubar will be used also when one of LyX' dialogs has focus. (JMarc) */ -void Menus::Impl::macxMenuBarInit(GuiView * view) +void Menus::Impl::macxMenuBarInit(GuiView * view, QMenuBar * qmb) { // The Mac menubar initialisation must be done only once! static bool done = false; @@ -1260,12 +1260,12 @@ void Menus::Impl::macxMenuBarInit(GuiView * view) // add the entries to a QMenu that will eventually be empty // and therefore invisible. - QMenu * qMenu = view->menuBar()->addMenu("special"); + QMenu * qMenu = qmb->addMenu("special"); MenuDefinition::const_iterator cit = specialmenu_.begin(); MenuDefinition::const_iterator end = specialmenu_.end(); for (size_t i = 0 ; cit != end ; ++cit, ++i) { - Action * action = new Action(*view, QIcon(), cit->label(), - cit->func(), QString()); + Action * action = new Action(view, QIcon(), cit->label(), + cit->func(), QString(), qMenu); action->setMenuRole(entries[i].role); qMenu->addAction(action); } @@ -1464,14 +1464,14 @@ bool Menus::searchMenu(FuncRequest const & func, } -void Menus::fillMenuBar(GuiView * view) +void Menus::fillMenuBar(QMenuBar * qmb, GuiView * view) { // Clear all menubar contents before filling it. - view->menuBar()->clear(); + qmb->clear(); #ifdef Q_WS_MACX // setup special mac specific menu item - d->macxMenuBarInit(view); + d->macxMenuBarInit(view, qmb); #endif LYXERR(Debug::GUI, "populating menu bar" << fromqstr(d->menubar_.name())); @@ -1487,7 +1487,10 @@ void Menus::fillMenuBar(GuiView * view) } MenuDefinition menu; - d->expand(d->menubar_, menu, view->buffer()); + Buffer * buf = 0; + if (view) + buf = view->buffer(); + d->expand(d->menubar_, menu, buf); MenuDefinition::const_iterator m = menu.begin(); MenuDefinition::const_iterator end = menu.end(); @@ -1537,7 +1540,10 @@ void Menus::updateMenu(Menu * qmenu) } MenuDefinition const & fromLyxMenu = d->getMenu(qmenu->d->name); - d->expand(fromLyxMenu, *qmenu->d->top_level_menu, qmenu->d->view->buffer()); + Buffer * buf = 0; + if (qmenu->d->view) + buf = qmenu->d->view->buffer(); + d->expand(fromLyxMenu, *qmenu->d->top_level_menu, buf); qmenu->d->populate(*qmenu, *qmenu->d->top_level_menu); } diff --git a/src/frontends/qt4/Menus.h b/src/frontends/qt4/Menus.h index 80de0da292..9ba0c10d58 100644 --- a/src/frontends/qt4/Menus.h +++ b/src/frontends/qt4/Menus.h @@ -63,7 +63,7 @@ public: bool searchMenu(FuncRequest const & func, std::vector & names) const; /// - void fillMenuBar(GuiView * view); + void fillMenuBar(QMenuBar * qmb, GuiView * view); /// \return a top-level submenu given its name. Menu * menu(QString const & name, GuiView & view);