]> git.lyx.org Git - features.git/commitdiff
Cheap fix for #6554. When we save a Buffer to a new location, we check
authorRichard Heck <rgheck@comcast.net>
Tue, 9 Mar 2010 03:25:47 +0000 (03:25 +0000)
committerRichard Heck <rgheck@comcast.net>
Tue, 9 Mar 2010 03:25:47 +0000 (03:25 +0000)
the included insets and make sure that the files they reference are
still where they are supposed to be.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33686 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Buffer.h
src/frontends/qt4/GuiView.cpp

index 8f3355b6b7a43a1f3777e49cb81b3d719266497b..9a3d86af66fe60abe68f087507440e18d42e6098 100644 (file)
@@ -3920,4 +3920,41 @@ bool Buffer::reload()
 }
 
 
+// FIXME We could do better here, but it is complicated. What would be
+// nice is to offer either (a) to save the child buffer to an appropriate
+// location, so that it would "move with the master", or else (b) to update
+// the InsetInclude so that it pointed to the same file. But (a) is a bit
+// complicated, because the code for this lives in GuiView.
+void Buffer::checkChildBuffers()
+{
+       Impl::BufferPositionMap::iterator it = d->children_positions.begin();
+       Impl::BufferPositionMap::iterator const en = d->children_positions.end();
+       for (; it != en; ++it) {
+               DocIterator dit = it->second;
+               Buffer * cbuf = const_cast<Buffer *>(it->first);
+               if (!cbuf || !theBufferList().isLoaded(cbuf))
+                       continue;
+               Inset * inset = dit.nextInset();
+               LASSERT(inset && inset->lyxCode() == INCLUDE_CODE, continue);
+               InsetInclude * inset_inc = static_cast<InsetInclude *>(inset);
+               docstring const & incfile = inset_inc->getParam("filename");
+               string oldloc = cbuf->absFileName();
+               string newloc = makeAbsPath(to_utf8(incfile),
+                               onlyPath(absFileName())).absFilename();
+               if (oldloc == newloc)
+                       continue;
+               // the location of the child file is incorrect.
+               Alert::warning(_("Included File Invalid"),
+                               bformat(_("Saving this document to a new location has made the file:\n"
+                               "  %1$s\n"
+                               "inaccessible. You will need to update the included filename."),
+                               from_utf8(oldloc)));
+               cbuf->setParent(0);
+               inset_inc->setChildBuffer(0);
+       }
+       // invalidate cache of children
+       d->children_positions.clear();
+       d->position_to_children.clear();
+}
+
 } // namespace lyx
index 4e372c296db673da061099e3c6cf27b9612069b2..7f19fd1f58e55f159e435f31f76589ac978c07dc 100644 (file)
@@ -561,6 +561,8 @@ public:
        /// \return progress if a new word was found.
        int spellCheck(DocIterator & from, DocIterator & to,
                WordLangTuple & word_lang, docstring_list & suggestions) const;
+       ///
+       void checkChildBuffers();
 
 private:
        ///
index b8b8d2cd99a1c31bbb5d1f72b9eeb0dcce731b03..a2a5eaf746e02d45572a65d95fe2ce6559ce45d1 100644 (file)
@@ -2083,6 +2083,7 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
                        fname.changeExtension(".lyx");
        }
 
+       // fname is now the new Buffer location.
        if (FileName(fname).exists()) {
                docstring const file = makeDisplayPath(fname.absFilename(), 30);
                docstring text = bformat(_("The document %1$s already "
@@ -2119,6 +2120,11 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
                return false;
        }
 
+       // the file has now been saved to the new location.
+       // we need to check that the locations of child buffers
+       // are still valid.
+       b.checkChildBuffers();
+
        return true;
 }