X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiView.cpp;h=63bd54ec63c476087b971512b96e55f65fe1eb06;hb=d2a96bcdc369b52ae6fb52c5a612bcd9f665231b;hp=215cdeb16057b5ea6f52b38dcaa8b94a2d03b8d7;hpb=f1d25c23f8b18c98fd7e27e6aa3d2114163a347c;p=lyx.git diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 215cdeb160..63bd54ec63 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -24,6 +24,7 @@ #include "GuiToolbar.h" #include "GuiToolbars.h" #include "Menus.h" +#include "TocModel.h" #include "qt_helpers.h" @@ -54,7 +55,7 @@ #include "ToolbarBackend.h" #include "version.h" -#include "support/assert.h" +#include "support/lassert.h" #include "support/debug.h" #include "support/FileName.h" #include "support/filetools.h" @@ -270,6 +271,9 @@ public: Timeout autosave_timeout_; /// flag against a race condition due to multiclicks, see bug #1119 bool in_show_; + + /// + TocModels toc_models_; }; @@ -346,6 +350,12 @@ GuiView::~GuiView() } +TocModels & GuiView::tocModels() +{ + return d.toc_models_; +} + + void GuiView::setFocus() { if (d.current_work_area_) @@ -393,8 +403,8 @@ void GuiView::closeEvent(QCloseEvent * close_event) continue; } - std::vector const & ids = guiApp->viewIds(); - for (size_type i = 0; i != ids.size(); ++i) { + QVector const ids = guiApp->viewIds(); + for (int i = 0; i != ids.size(); ++i) { if (id_ == ids[i]) continue; if (guiApp->view(ids[i]).workArea(*b)) { @@ -423,7 +433,7 @@ void GuiView::closeEvent(QCloseEvent * close_event) // Save toolbars configuration if (isFullScreen()) { d.toolbars_->toggleFullScreen(!isFullScreen()); - updateToolbars(); + updateDialogs(); } // Make sure the timer time out will not trigger a statusbar update. @@ -538,14 +548,14 @@ void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa) this, SLOT(updateWindowTitle(GuiWorkArea *))); updateWindowTitle(wa); - updateToc(); - // Buffer-dependent dialogs should be updated or - // hidden. This should go here because some dialogs (eg ToC) - // require bv_->text. - updateBufferDependent(true); - updateToolbars(); - updateLayoutList(); - updateStatusBar(); + structureChanged(); + + // The document settings needs to be reinitialised. + updateDialog("document", ""); + + // Buffer-dependent dialogs must be updated. This is done here because + // some dialogs require buffer()->text. + updateDialogs(); } @@ -561,6 +571,11 @@ void GuiView::on_lastWorkAreaRemoved() QTimer::singleShot(0, this, SLOT(close())); } } +#else + structureChanged(); + // The document settings needs to be reinitialised. + updateDialog("document", ""); + updateDialogs(); #endif } @@ -613,10 +628,10 @@ bool GuiView::event(QEvent * e) connectBuffer(bv.buffer()); // The document structure, name and dialogs might have // changed in another view. - updateBufferDependent(true); - updateToolbars(); - updateLayoutList(); - updateStatusBar(); + structureChanged(); + // The document settings needs to be reinitialised. + updateDialog("document", ""); + updateDialogs(); } else { setWindowTitle(qt_("LyX")); setWindowIconText(qt_("LyX")); @@ -626,12 +641,23 @@ bool GuiView::event(QEvent * e) } case QEvent::ShortcutOverride: { + + if (isFullScreen() && menuBar()->isHidden()) { + QKeyEvent * ke = static_cast(e); + // FIXME: we should also try to detect special LyX shortcut such as + // Alt-P and Alt-M. Right now there is a hack in + // GuiWorkArea::processKeySym() that hides again the menubar for + // those cases. + if (ke->modifiers() & Qt::AltModifier && ke->key() != Qt::Key_Alt) + menuBar()->show(); + return QMainWindow::event(e); + } + if (d.current_work_area_) // Nothing special to do. return QMainWindow::event(e); QKeyEvent * ke = static_cast(e); - // Let Qt handle menu access and the Tab keys to navigate keys to navigate // between controls. if (ke->modifiers() & Qt::AltModifier || ke->key() == Qt::Key_Tab @@ -765,11 +791,6 @@ GuiWorkArea const * GuiView::currentWorkArea() const void GuiView::setCurrentWorkArea(GuiWorkArea * wa) { LASSERT(wa, /**/); - - // Changing work area can result from opening a file so - // update the toc in any case. - updateToc(); - d.current_work_area_ = wa; for (int i = 0; i != d.splitter_->count(); ++i) { if (d.tabWorkArea(i)->setCurrentWorkArea(wa)) @@ -844,9 +865,6 @@ void GuiView::updateToolbars() d.toolbars_->update(math, table, review, mathmacrotemplate); } else d.toolbars_->update(false, false, false, false); - - // update read-only status of open dialogs. - checkStatus(); } @@ -921,6 +939,15 @@ void GuiView::errors(string const & error_type) } +void GuiView::structureChanged() +{ + d.toc_models_.reset(view()); + // Navigator needs more than a simple update in this case. It needs to be + // rebuilt. + updateDialog("toc", ""); +} + + void GuiView::updateDialog(string const & name, string const & data) { if (!isDialogVisible(name)) @@ -932,7 +959,7 @@ void GuiView::updateDialog(string const & name, string const & data) Dialog * const dialog = it->second.get(); if (dialog->isVisibleView()) - dialog->updateData(data); + dialog->initialiseParams(data); } @@ -942,12 +969,6 @@ BufferView * GuiView::view() } -void GuiView::updateToc() -{ - updateDialog("toc", ""); -} - - void GuiView::autoSave() { LYXERR(Debug::INFO, "Running autoSave()"); @@ -964,9 +985,8 @@ void GuiView::resetAutosaveTimers() } -FuncStatus GuiView::getStatus(FuncRequest const & cmd) +bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag) { - FuncStatus flag; bool enable = true; Buffer * buf = buffer(); @@ -1056,10 +1076,6 @@ FuncStatus GuiView::getStatus(FuncRequest const & cmd) } case LFUN_INSET_APPLY: { - if (!buf) { - enable = false; - break; - } string const name = cmd.getArg(0); Inset * inset = getOpenInset(name); if (inset) { @@ -1072,7 +1088,7 @@ FuncStatus GuiView::getStatus(FuncRequest const & cmd) flag |= fs; } else { FuncRequest fr(LFUN_INSET_INSERT, cmd.argument()); - flag |= getStatus(fr); + flag |= lyx::getStatus(fr); } enable = flag.enabled(); break; @@ -1097,16 +1113,13 @@ FuncStatus GuiView::getStatus(FuncRequest const & cmd) break; default: - if (!view()) { - enable = false; - break; - } + return false; } if (!enable) flag.enabled(false); - return flag; + return true; } @@ -1660,10 +1673,11 @@ bool GuiView::closeBuffer(Buffer & buf, bool tolastopened) bool GuiView::dispatch(FuncRequest const & cmd) { - BufferView * bv = view(); + BufferView * bv = view(); // By default we won't need any update. if (bv) bv->cursor().updateFlags(Update::None); + bool dispatched = true; switch(cmd.action) { case LFUN_BUFFER_IMPORT: @@ -1834,6 +1848,7 @@ bool GuiView::dispatch(FuncRequest const & cmd) } case LFUN_INSET_APPLY: { + view()->cursor().recordUndoFullDocument(); string const name = cmd.getArg(0); Inset * inset = getOpenInset(name); if (inset) { @@ -1892,10 +1907,18 @@ bool GuiView::dispatch(FuncRequest const & cmd) break; default: - return false; + dispatched = false; + break; } - return true; + if (isFullScreen()) { + if (menuBar()->isVisible()) + menuBar()->hide(); + if (statusBar()->isVisible()) + statusBar()->hide(); + } + + return dispatched; } @@ -1987,9 +2010,7 @@ void GuiView::restartCursor() d.current_work_area_->startBlinkingCursor(); // Take this occasion to update the other GUI elements. - updateLayoutList(); - updateToolbars(); - updateStatusBar(); + updateDialogs(); } @@ -2147,44 +2168,22 @@ void GuiView::hideAll() const } -void GuiView::updateBufferDependent(bool switched) const +void GuiView::updateDialogs() { map::const_iterator it = d.dialogs_.begin(); map::const_iterator end = d.dialogs_.end(); for(; it != end; ++it) { Dialog * dialog = it->second.get(); - if (!dialog->isVisibleView()) - continue; - if (switched && dialog->isBufferDependent()) { - if (dialog->initialiseParams("")) - dialog->updateView(); - else - dialog->hideView(); - } else { - // A bit clunky, but the dialog will request - // that the kernel provides it with the necessary - // data. - dialog->updateDialog(); - } - } -} - - -void GuiView::checkStatus() -{ - map::const_iterator it = d.dialogs_.begin(); - map::const_iterator end = d.dialogs_.end(); - - for(; it != end; ++it) { - Dialog * const dialog = it->second.get(); if (dialog && dialog->isVisibleView()) dialog->checkStatus(); } + updateToolbars(); + updateLayoutList(); + updateStatusBar(); } - // will be replaced by a proper factory... Dialog * createGuiAbout(GuiView & lv); Dialog * createGuiBibitem(GuiView & lv);