* 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
// 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();

View File

@ -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);
}

View File

@ -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_;
};

View File

@ -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;
}

View File

@ -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.

View File

@ -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);
}

View File

@ -63,7 +63,7 @@ public:
bool searchMenu(FuncRequest const & func,
std::vector<docstring> & 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);