From a54850d7622f63d6ca39aaa2c211d959c295f232 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Wed, 25 Jun 2008 18:03:38 +0000 Subject: [PATCH] GuiApplication::resetGui(): reset as many things as possible, including menus and toolbars (not sure about Mac global menubar yet). This means that except for already opened dialog, all ui rc settings are taken into account without the need to restart. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25390 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiApplication.cpp | 26 +++++++++++++++++++++++--- src/frontends/qt4/GuiView.cpp | 10 ++++++---- src/frontends/qt4/Menus.cpp | 9 +++++++++ src/frontends/qt4/Menus.h | 7 +++++-- src/frontends/qt4/Toolbars.cpp | 6 ++++++ src/frontends/qt4/Toolbars.h | 3 +++ 6 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 4b452848fb..ec4784c55c 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -898,6 +898,19 @@ bool GuiApplication::dispatch(FuncRequest const & cmd) void GuiApplication::resetGui() { + // Set the language defined by the user. + LyX::ref().setRcGuiLanguage(); + + // Read menus + if (!readUIFile(toqstr(lyxrc.ui_file))) + // Gives some error box here. + return; + + // init the global menubar on Mac. This must be done after the session + // was recovered to know the "last files". + if (d->global_menubar_) + d->menus_.fillMenuBar(d->global_menubar_, 0, true); + QHash::iterator it; for (it = d->views_.begin(); it != d->views_.end(); ++it) (*it)->resetDialogs(); @@ -1328,9 +1341,16 @@ bool GuiApplication::readUIFile(QString const & name, bool include) // Ensure that a file is read only once (prevents include loops) static QStringList uifiles; if (uifiles.contains(name)) { - LYXERR(Debug::INIT, "UI file '" << name << "' has been read already. " - << "Is this an include loop?"); - return false; + if (!include) { + // We are reading again the top uifile so reset the safeguard: + uifiles.clear(); + d->menus_.reset(); + d->toolbars_.reset(); + } else { + LYXERR(Debug::INIT, "UI file '" << name << "' has been read already. " + << "Is this an include loop?"); + return false; + } } LYXERR(Debug::INIT, "About to read " << name << "..."); diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 25f5b13a60..6ddf0f33ae 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -404,6 +404,7 @@ void GuiView::constructToolbars() for (; it != d.toolbars_.end(); ++it) delete it->second; d.toolbars_.clear(); + d.layout_ = 0; // extracts the toolbars from the backend Toolbars::Infos::iterator cit = guiApp->toolbars().begin(); @@ -2150,14 +2151,15 @@ void GuiView::resetDialogs() { // Make sure that no LFUN uses any LyXView. theLyXFunc().setLyXView(0); - // FIXME: the "math panels" toolbar takes an awful lot of time to - // initialise so we don't do that for the time being. - //initToolbars(); - guiApp->menus().fillMenuBar(menuBar(), this); + saveLayout(); + menuBar()->clear(); + constructToolbars(); + guiApp->menus().fillMenuBar(menuBar(), this, true); if (d.layout_) d.layout_->updateContents(true); // Now update controls with current buffer. theLyXFunc().setLyXView(this); + restoreLayout(); restartCursor(); } diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index c124469e82..c6fc734585 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -1453,11 +1453,20 @@ MenuDefinition & Menus::Impl::getMenu(QString const & name) Menus::Menus() : d(new Impl) {} + Menus::~Menus() { delete d; } + +void Menus::reset() +{ + delete d; + d = new Impl; +} + + void Menus::read(Lexer & lex) { enum { diff --git a/src/frontends/qt4/Menus.h b/src/frontends/qt4/Menus.h index 5e438670fa..531eb3b400 100644 --- a/src/frontends/qt4/Menus.h +++ b/src/frontends/qt4/Menus.h @@ -59,6 +59,9 @@ class Menus public: Menus(); ~Menus(); + + /// + void reset(); /// bool searchMenu(FuncRequest const & func, @@ -78,8 +81,8 @@ public: private: /// Use the Pimpl idiom to hide the internals. struct Impl; - /// The pointer never changes although *d's contents may. - Impl * const d; + /// + Impl * d; }; } // namespace frontend diff --git a/src/frontends/qt4/Toolbars.cpp b/src/frontends/qt4/Toolbars.cpp index b1d6a41336..3a335fe495 100644 --- a/src/frontends/qt4/Toolbars.cpp +++ b/src/frontends/qt4/Toolbars.cpp @@ -190,6 +190,12 @@ ToolbarInfo & ToolbarInfo::read(Lexer & lex) // ///////////////////////////////////////////////////////////////////////// +void Toolbars::reset() +{ + toolbar_info_.clear(); + toolbar_visibility_.clear(); +} + void Toolbars::readToolbars(Lexer & lex) { diff --git a/src/frontends/qt4/Toolbars.h b/src/frontends/qt4/Toolbars.h index 0932a6861d..6ecc738ad9 100644 --- a/src/frontends/qt4/Toolbars.h +++ b/src/frontends/qt4/Toolbars.h @@ -112,6 +112,9 @@ public: Toolbars() {} + /// + void reset(); + /// iterator for all toolbars Infos::const_iterator begin() const { return toolbar_info_.begin(); } -- 2.39.2