diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 01672acfe6..dfb06a39c0 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -1211,10 +1211,8 @@ void GuiApplication::restoreGuiSession() // do not add to the lastfile list since these files are restored from // last session, and should be already there (regular files), or should // not be added at all (help files). - // Note that we open them in reverse order. This is because we close - // buffers also in reverse order (aesthetically motivated). - for (size_t i = lastopened.size(); i > 0; --i) { - FileName const & file_name = lastopened[i - 1].file_name; + for (size_t i = 0; i < lastopened.size(); ++i) { + FileName const & file_name = lastopened[i].file_name; if (d->views_.empty() || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) { boost::crc_32_type crc; @@ -1224,7 +1222,7 @@ void GuiApplication::restoreGuiSession() } current_view_->loadDocument(file_name, false); - if (lastopened[i - 1].active) + if (lastopened[i].active) active_file = file_name; } diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 6821bbdd59..762af8bcc0 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -544,6 +544,8 @@ void GuiView::closeEvent(QCloseEvent * close_event) LYXERR(Debug::DEBUG, "GuiView::closeEvent()"); closing_ = true; + writeSession(); + // it can happen that this event arrives without selecting the view, // e.g. when clicking the close button on a background window. setFocus(); @@ -1875,6 +1877,19 @@ bool GuiView::closeBuffer() } +void GuiView::writeSession() const { + GuiWorkArea const * active_wa = currentMainWorkArea(); + for (int i = 0; i < d.splitter_->count(); ++i) { + TabWorkArea * twa = d.tabWorkArea(i); + for (int j = 0; j < twa->count(); ++j) { + GuiWorkArea * wa = static_cast(twa->widget(j)); + Buffer & buf = wa->bufferView().buffer(); + theSession().lastOpened().add(buf.fileName(), wa == active_wa); + } + } +} + + bool GuiView::closeBufferAll() { // First close all workareas. This will make diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 5661df2656..21ebdf81b8 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -314,6 +314,8 @@ private: bool closeBufferAll(); /// closes all workareas bool closeWorkAreaAll(); + /// write all open workareas into the session file + void writeSession() const; /// is the buffer in this workarea also shown in another tab ? /// This tab can either be in the same view or in another one. bool inMultiTabs(GuiWorkArea * wa);