From 258cca4b3be2353a5c4f9a677e7f03246411e3d1 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Thu, 6 Mar 2008 20:58:59 +0000 Subject: [PATCH] Delete child buffer at InsetInclude destruction. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23521 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 33 ++------------------- src/Buffer.h | 2 -- src/insets/InsetInclude.cpp | 58 +++++++++++++++++-------------------- src/insets/InsetInclude.h | 8 +---- 4 files changed, 31 insertions(+), 70 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 65b1418140..0742c5fad2 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -265,16 +265,9 @@ Buffer::~Buffer() // GuiView already destroyed gui_ = 0; - Buffer const * master = masterBuffer(); - if (master != this && use_gui) { - // We are closing buf which was a child document so we - // must update the labels and section numbering of its master - // Buffer. - updateLabels(*master); - master->updateMacros(); - } - - resetChildDocuments(false); + // clear references to children in macro tables + d->children_positions.clear(); + d->position_to_children.clear(); if (!d->temppath.destroyDirectory()) { Alert::warning(_("Could not remove temporary directory"), @@ -2359,26 +2352,6 @@ void Buffer::autoSave() const } -void Buffer::resetChildDocuments(bool close_them) const -{ - if (text().empty()) - return; - - for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) { - if (it->lyxCode() != INCLUDE_CODE) - continue; - InsetCommand const & inset = static_cast(*it); - InsetCommandParams const & ip = inset.params(); - - resetParentBuffer(this, ip, close_them); - } - - // clear references to children in macro tables - d->children_positions.clear(); - d->position_to_children.clear(); -} - - string Buffer::bufferFormat() const { if (isDocBook()) diff --git a/src/Buffer.h b/src/Buffer.h index edfdadcf89..33d019b3de 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -434,8 +434,6 @@ public: /// void autoSave() const; - /// - void resetChildDocuments(bool close_them) const; /// return the format of the buffer on a string std::string bufferFormat() const; diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index d2bc2be0f9..658d09a747 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -167,6 +167,33 @@ InsetInclude::InsetInclude(InsetInclude const & other) } +InsetInclude::~InsetInclude() +{ + if (isVerbatim(params()) || isListings(params())) + return; + + + string const parent_filename = buffer().absFileName(); + FileName const included_file = makeAbsPath(to_utf8(params()["filename"]), + onlyPath(parent_filename)); + + if (!isLyXFilename(included_file.absFilename())) + return; + + Buffer * child = theBufferList().getBuffer(included_file.absFilename()); + // File not opened, nothing to close. + if (!child) + return; + + // Child document has a different parent, don't close it. + if (child->parent() != &buffer()) + return; + + //close the buffer. + theBufferList().release(child); +} + + ParamInfo const & InsetInclude::findInfo(string const & /* cmdName */) { // FIXME @@ -344,37 +371,6 @@ Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params) } -void resetParentBuffer(Buffer const * parent, InsetCommandParams const & params, - bool close_it) -{ - if (isVerbatim(params) || isListings(params)) - return; - - string const parent_filename = parent->absFileName(); - FileName const included_file = makeAbsPath(to_utf8(params["filename"]), - onlyPath(parent_filename)); - - if (!isLyXFilename(included_file.absFilename())) - return; - - Buffer * child = theBufferList().getBuffer(included_file.absFilename()); - // File not opened, nothing to close. - if (!child) - return; - - // Child document has a different parent, don't close it. - if (child->parent() != parent) - return; - - //close the buffer. - child->setParent(0); - if (close_it) - theBufferList().release(child); - else - updateLabels(*child); -} - - int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const { string incfile = to_utf8(params()["filename"]); diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h index db177f17ae..4159752cb3 100644 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -35,6 +35,7 @@ class InsetInclude : public InsetCommand { public: /// InsetInclude(InsetCommandParams const &); + ~InsetInclude(); /// Override these InsetButton methods if Previewing void metrics(MetricsInfo & mi, Dimension & dim) const; @@ -124,16 +125,9 @@ private: mutable docstring listings_label_; }; -/// return the child buffer if the file is a LyX doc and is loaded -Buffer * getChildBuffer(Buffer const & buffer, InsetCommandParams const & params); - /// return loaded Buffer or zero if the file loading did not proceed. Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params); -/// -void resetParentBuffer(Buffer const * parent, InsetCommandParams const & params, - bool close_it); - } // namespace lyx #endif // INSETINCLUDE_H -- 2.39.2