* remove the need of an active GuiView

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23718 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stefan Schimanski 2008-03-14 16:33:16 +00:00
parent 3a7c68d3f7
commit 5d112c185c
7 changed files with 47 additions and 34 deletions

View File

@ -105,10 +105,11 @@ namespace {
// This function runs "configure" and then rereads lyx.defaults to // This function runs "configure" and then rereads lyx.defaults to
// reconfigure the automatic settings. // reconfigure the automatic settings.
void reconfigure(LyXView & lv, string const & option) void reconfigure(LyXView * lv, string const & option)
{ {
// emit message signal. // emit message signal.
lv.message(_("Running configure...")); if (lv)
lv->message(_("Running configure..."));
// Run configure in user lyx directory // Run configure in user lyx directory
PathChanger p(package().user_support()); PathChanger p(package().user_support());
@ -118,7 +119,8 @@ void reconfigure(LyXView & lv, string const & option)
int ret = one.startscript(Systemcall::Wait, configure_command); int ret = one.startscript(Systemcall::Wait, configure_command);
p.pop(); p.pop();
// emit message signal. // emit message signal.
lv.message(_("Reloading configuration...")); if (lv)
lv->message(_("Reloading configuration..."));
lyxrc.read(libFileSearch(string(), "lyxrc.defaults")); lyxrc.read(libFileSearch(string(), "lyxrc.defaults"));
// Re-read packages.lst // Re-read packages.lst
LaTeXFeatures::getAvailable(); LaTeXFeatures::getAvailable();
@ -293,7 +295,8 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
if (keysym.isModifier()) { if (keysym.isModifier()) {
LYXERR(Debug::KEY, "isModifier true"); LYXERR(Debug::KEY, "isModifier true");
lyx_view_->restartCursor(); if (lyx_view_)
lyx_view_->restartCursor();
return; return;
} }
@ -384,7 +387,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
//lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl; //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
FuncStatus flag; FuncStatus flag;
Buffer * buf = lyx_view_? lyx_view_->buffer() : 0; Buffer * buf = lyx_view_ ? lyx_view_->buffer() : 0;
if (cmd.action == LFUN_NOACTION) { if (cmd.action == LFUN_NOACTION) {
flag.message(from_utf8(N_("Nothing to do"))); flag.message(from_utf8(N_("Nothing to do")));
@ -1039,9 +1042,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
break; break;
case LFUN_RECONFIGURE: case LFUN_RECONFIGURE:
BOOST_ASSERT(lyx_view_);
// argument is any additional parameter to the configure.py command // argument is any additional parameter to the configure.py command
reconfigure(*lyx_view_, argument); reconfigure(lyx_view_, argument);
break; break;
case LFUN_HELP_OPEN: { case LFUN_HELP_OPEN: {
@ -1659,8 +1661,11 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
// Nothing more to do. // Nothing more to do.
return; return;
// Everything below is only for active lyx_view_
if (lyx_view_ == 0)
break;
// Let the current LyXView dispatch its own actions. // Let the current LyXView dispatch its own actions.
BOOST_ASSERT(lyx_view_);
if (lyx_view_->dispatch(cmd)) { if (lyx_view_->dispatch(cmd)) {
if (lyx_view_->view()) if (lyx_view_->view())
updateFlags = lyx_view_->view()->cursor().result().update(); updateFlags = lyx_view_->view()->cursor().result().update();

View File

@ -25,10 +25,10 @@ namespace lyx {
namespace frontend { namespace frontend {
Action::Action(GuiView & lyxView, QIcon const & icon, Action::Action(GuiView * lyxView, QIcon const & icon,
QString const & text, FuncRequest const & func, QString const & text, FuncRequest const & func,
QString const & tooltip) QString const & tooltip, QObject * parent)
: QAction(&lyxView), func_(func), lyxView_(lyxView) : QAction(parent), func_(func), lyxView_(lyxView)
{ {
// only Qt/Mac handles that // only Qt/Mac handles that
setMenuRole(NoRole); setMenuRole(NoRole);
@ -62,7 +62,10 @@ void Action::update()
void Action::action() void Action::action()
{ {
//LYXERR(Debug::ACTION, "calling LyXFunc::dispatch: func_: "); //LYXERR(Debug::ACTION, "calling LyXFunc::dispatch: func_: ");
theLyXFunc().setLyXView(&lyxView_);
if (lyxView_)
theLyXFunc().setLyXView(lyxView_);
lyx::dispatch(func_); lyx::dispatch(func_);
triggered(this); triggered(this);
} }

View File

@ -34,8 +34,8 @@ class Action : public QAction
Q_OBJECT Q_OBJECT
public: public:
Action(GuiView & lyxView, QIcon const & icon, QString const & text, Action(GuiView * lyxView, QIcon const & icon, QString const & text,
FuncRequest const & func, QString const & tooltip); FuncRequest const & func, QString const & tooltip, QObject * parent);
void update(); void update();
@ -48,7 +48,7 @@ private Q_SLOTS:
private: private:
FuncRequest const & func_ ; FuncRequest const & func_ ;
GuiView & lyxView_; GuiView * lyxView_;
}; };

View File

@ -839,9 +839,8 @@ GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
Action * GuiToolbar::addItem(ToolbarItem const & item) Action * GuiToolbar::addItem(ToolbarItem const & item)
{ {
Action * act = new Action(owner_, Action * act = new Action(&owner_, getIcon(item.func_, false),
getIcon(item.func_, false), toqstr(item.label_), item.func_, toqstr(item.label_), this);
toqstr(item.label_), item.func_, toqstr(item.label_));
actions_.append(act); actions_.append(act);
return act; return act;
} }

View File

@ -278,7 +278,7 @@ GuiView::GuiView(int id)
d.toolbars_ = new GuiToolbars(*this); d.toolbars_ = new GuiToolbars(*this);
// Fill up the menu bar. // Fill up the menu bar.
guiApp->menus().fillMenuBar(this); guiApp->menus().fillMenuBar(menuBar(), this);
setCentralWidget(d.stack_widget_); setCentralWidget(d.stack_widget_);
@ -2024,7 +2024,7 @@ void GuiView::resetDialogs()
// FIXME: the "math panels" toolbar takes an awful lot of time to // FIXME: the "math panels" toolbar takes an awful lot of time to
// initialise so we don't do that for the time being. // initialise so we don't do that for the time being.
//d.toolbars_->init(); //d.toolbars_->init();
guiApp->menus().fillMenuBar(this); guiApp->menus().fillMenuBar(menuBar(), this);
if (d.layout_) if (d.layout_)
d.layout_->updateContents(true); d.layout_->updateContents(true);
// Now update controls with current buffer. // Now update controls with current buffer.

View File

@ -1114,8 +1114,8 @@ void Menu::Impl::populate(QMenu & qMenu, MenuDefinition const & menu)
populate(*subMenu, m->submenu()); populate(*subMenu, m->submenu());
} else { } else {
// we have a MenuItem::Command // we have a MenuItem::Command
qMenu.addAction(new Action(*view, QIcon(), label(*m), m->func(), qMenu.addAction(new Action(view, QIcon(), label(*m),
QString())); m->func(), QString(), &qMenu));
} }
} }
} }
@ -1167,10 +1167,10 @@ struct Menus::Impl {
ViewFormats, ExportFormats, UpdateFormats, Branches ViewFormats, ExportFormats, UpdateFormats, Branches
*/ */
void expand(MenuDefinition const & frommenu, MenuDefinition & tomenu, void expand(MenuDefinition const & frommenu, MenuDefinition & tomenu,
Buffer const *) const; Buffer const *) const;
/// Initialize specific MACOS X menubar /// Initialize specific MACOS X menubar
void macxMenuBarInit(GuiView * view); void macxMenuBarInit(GuiView * view, QMenuBar * qmb);
/// Mac special menu. /// Mac special menu.
/** This defines a menu whose entries list the FuncRequests /** 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 that this menubar will be used also when one of LyX' dialogs has
focus. (JMarc) 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! // The Mac menubar initialisation must be done only once!
static bool done = false; 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 // add the entries to a QMenu that will eventually be empty
// and therefore invisible. // and therefore invisible.
QMenu * qMenu = view->menuBar()->addMenu("special"); QMenu * qMenu = qmb->addMenu("special");
MenuDefinition::const_iterator cit = specialmenu_.begin(); MenuDefinition::const_iterator cit = specialmenu_.begin();
MenuDefinition::const_iterator end = specialmenu_.end(); MenuDefinition::const_iterator end = specialmenu_.end();
for (size_t i = 0 ; cit != end ; ++cit, ++i) { for (size_t i = 0 ; cit != end ; ++cit, ++i) {
Action * action = new Action(*view, QIcon(), cit->label(), Action * action = new Action(view, QIcon(), cit->label(),
cit->func(), QString()); cit->func(), QString(), qMenu);
action->setMenuRole(entries[i].role); action->setMenuRole(entries[i].role);
qMenu->addAction(action); 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. // Clear all menubar contents before filling it.
view->menuBar()->clear(); qmb->clear();
#ifdef Q_WS_MACX #ifdef Q_WS_MACX
// setup special mac specific menu item // setup special mac specific menu item
d->macxMenuBarInit(view); d->macxMenuBarInit(view, qmb);
#endif #endif
LYXERR(Debug::GUI, "populating menu bar" << fromqstr(d->menubar_.name())); LYXERR(Debug::GUI, "populating menu bar" << fromqstr(d->menubar_.name()));
@ -1487,7 +1487,10 @@ void Menus::fillMenuBar(GuiView * view)
} }
MenuDefinition menu; 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 m = menu.begin();
MenuDefinition::const_iterator end = menu.end(); MenuDefinition::const_iterator end = menu.end();
@ -1537,7 +1540,10 @@ void Menus::updateMenu(Menu * qmenu)
} }
MenuDefinition const & fromLyxMenu = d->getMenu(qmenu->d->name); 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); qmenu->d->populate(*qmenu, *qmenu->d->top_level_menu);
} }

View File

@ -63,7 +63,7 @@ public:
bool searchMenu(FuncRequest const & func, bool searchMenu(FuncRequest const & func,
std::vector<docstring> & names) const; std::vector<docstring> & names) const;
/// ///
void fillMenuBar(GuiView * view); void fillMenuBar(QMenuBar * qmb, GuiView * view);
/// \return a top-level submenu given its name. /// \return a top-level submenu given its name.
Menu * menu(QString const & name, GuiView & view); Menu * menu(QString const & name, GuiView & view);