From d95aaa0e5b42913ba64062a4e51009555fb324d5 Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Fri, 8 Jan 2010 02:15:56 +0000 Subject: [PATCH] Move reloadBuffer from GuiView to Buffer. This fixes bug #6314: reloading master document makes emergencies of modified children. Now also the version control handling could be moved to Buffer as well, and the hack in ensureBufferClean is removed. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32875 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 22 ++++++++++++++++++++++ src/Buffer.h | 2 ++ src/frontends/qt4/GuiView.cpp | 34 +++------------------------------- src/frontends/qt4/GuiView.h | 1 - 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 0610520442..63dee570eb 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -3766,4 +3766,26 @@ int Buffer::spellCheck(DocIterator & from, DocIterator & to, return progress; } + +bool Buffer::reload() +{ + setBusy(true); + // e.g., read-only status could have changed due to version control + d->filename.refresh(); + docstring const disp_fn = makeDisplayPath(d->filename.absFilename()); + + bool const success = loadLyXFile(d->filename); + if (success) { + updateLabels(); + changed(true); + errors("Parse"); + message(bformat(_("Document %1$s reloaded."), disp_fn)); + } else { + message(bformat(_("Could not reload document %1$s."), disp_fn)); + } + setBusy(false); + return success; +} + + } // namespace lyx diff --git a/src/Buffer.h b/src/Buffer.h index 6b13ee0622..67e09ba49e 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -186,6 +186,8 @@ public: /// Loads LyX file \c filename into buffer, * and return success bool loadLyXFile(support::FileName const & s); + /// Reloads the LyX file + bool reload(); /// Fill in the ErrorList with the TeXErrors void bufferErrors(TeXErrors const &, ErrorList &) const; diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 32ddfdc230..d777ff6e7b 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -2315,7 +2315,7 @@ bool GuiView::saveBufferIfNeeded(Buffer & buf, bool hiding) buf.removeAutosaveFile(); if (hiding) // revert all changes - buf.loadLyXFile(buf.fileName()); + buf.reload(); buf.markClean(); break; case 2: @@ -2412,35 +2412,7 @@ static bool ensureBufferClean(Buffer * buffer) void GuiView::reloadBuffer() { Buffer * buf = &documentBufferView()->buffer(); - reloadBuffer(buf); -} - - -void GuiView::reloadBuffer(Buffer * buf) -{ - FileName filename = buf->fileName(); - // e.g., read-only status could have changed due to version control - filename.refresh(); - Buffer const * parent = buf->parent(); - // The user has already confirmed that the changes, if any, should - // be discarded. So we just release the Buffer and don't call closeBuffer(); - theBufferList().release(buf); - buf = loadDocument(filename); - docstring const disp_fn = makeDisplayPath(filename.absFilename()); - docstring str; - if (buf) { - // re-allocate master if necessary - if (parent && theBufferList().isLoaded(parent) - && buf->parent() != parent) - buf->setParent(parent); - buf->updateLabels(); - setBuffer(buf); - buf->errors("Parse"); - str = bformat(_("Document %1$s reloaded."), disp_fn); - } else { - str = bformat(_("Could not reload document %1$s"), disp_fn); - } - message(str); + buf->reload(); } @@ -2457,7 +2429,7 @@ void GuiView::checkExternallyModifiedBuffers() int const ret = Alert::prompt(_("Reload externally changed document?"), text, 0, 1, _("&Reload"), _("&Cancel")); if (!ret) - reloadBuffer(*bit); + (*bit)->reload(); } } } diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 44d491e80c..3a49d3447c 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -357,7 +357,6 @@ private: Dialog * build(std::string const & name); /// void reloadBuffer(); - void reloadBuffer(Buffer * buf); /// void dispatchVC(FuncRequest const & cmd); /// -- 2.39.5