Delete child buffer at InsetInclude destruction.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23521 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-03-06 20:58:59 +00:00
parent a99c5828f8
commit 258cca4b3b
4 changed files with 31 additions and 70 deletions

View 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())

View 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;

View 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"]);

View 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