]> git.lyx.org Git - features.git/commitdiff
Delete child buffer at InsetInclude destruction.
authorAbdelrazak Younes <younes@lyx.org>
Thu, 6 Mar 2008 20:58:59 +0000 (20:58 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Thu, 6 Mar 2008 20:58:59 +0000 (20:58 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23521 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Buffer.h
src/insets/InsetInclude.cpp
src/insets/InsetInclude.h

index 65b1418140998a52c023f0cd16f45ee2a95338fb..0742c5fad232123ecc50fe2852ad6de8833a5029 100644 (file)
@@ -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<InsetCommand const &>(*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())
index edfdadcf894d4e44ac9e7a2f64a1c632ec903458..33d019b3de1746d886ec1d16ef227b9181261f8d 100644 (file)
@@ -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;
index d2bc2be0f98215a07fedb1f686673c2e4287205d..658d09a747e8cd845764dd990b0daffedca0a6f9 100644 (file)
@@ -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"]);
index db177f17aeb3d6a3d6ebd59669cbe94a2f752838..4159752cb30cb4517781d6872c4fc94c90837405 100644 (file)
@@ -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