Make getChildBuffer() and loadIfNeeded() methods rather than standalone

functions. Preparatory to another patch.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27687 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2008-11-24 12:40:53 +00:00
parent 78ab480e72
commit aeb997e3f0
3 changed files with 24 additions and 23 deletions

View File

@ -1925,11 +1925,10 @@ void Buffer::updateMacros(DocIterator & it, DocIterator & scope) const
// is it an external file? // is it an external file?
if (iit->inset->lyxCode() == INCLUDE_CODE) { if (iit->inset->lyxCode() == INCLUDE_CODE) {
// get buffer of external file // get buffer of external file
InsetCommand const & inset InsetInclude const & inset
= static_cast<InsetCommand const &>(*iit->inset); = static_cast<InsetInclude const &>(*iit->inset);
InsetCommandParams const & ip = inset.params();
d->macro_lock = true; d->macro_lock = true;
Buffer * child = loadIfNeeded(*this, ip); Buffer * child = inset.loadIfNeeded(*this);
d->macro_lock = false; d->macro_lock = false;
if (!child) if (!child)
continue; continue;

View File

@ -351,31 +351,31 @@ docstring InsetInclude::screenLabel() const
} }
/// return the child buffer if the file is a LyX doc and is loaded Buffer * InsetInclude::getChildBuffer(Buffer const & buffer) const
Buffer * getChildBuffer(Buffer const & buffer, InsetCommandParams const & params)
{ {
if (isVerbatim(params) || isListings(params)) InsetCommandParams const & p = params();
if (isVerbatim(p) || isListings(p))
return 0; return 0;
string const included_file = includedFilename(buffer, params).absFilename(); string const included_file = includedFilename(buffer, p).absFilename();
if (!isLyXFilename(included_file)) if (!isLyXFilename(included_file))
return 0; return 0;
Buffer * childBuffer = loadIfNeeded(buffer, params); Buffer * childBuffer = loadIfNeeded(buffer);
// FIXME: recursive includes // FIXME: recursive includes
return (childBuffer == &buffer) ? 0 : childBuffer; return (childBuffer == &buffer) ? 0 : childBuffer;
} }
/// return true if the file is or got loaded. Buffer * InsetInclude::loadIfNeeded(Buffer const & parent) const
Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params)
{ {
if (isVerbatim(params) || isListings(params)) InsetCommandParams const & p = params();
if (isVerbatim(p) || isListings(p))
return 0; return 0;
string const parent_filename = parent.absFileName(); string const parent_filename = parent.absFileName();
FileName const included_file = makeAbsPath(to_utf8(params["filename"]), FileName const included_file = makeAbsPath(to_utf8(p["filename"]),
onlyPath(parent_filename)); onlyPath(parent_filename));
if (!isLyXFilename(included_file.absFilename())) if (!isLyXFilename(included_file.absFilename()))
@ -466,7 +466,7 @@ int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
isLyXFilename(included_file.absFilename())) { isLyXFilename(included_file.absFilename())) {
//if it's a LyX file and we're inputting or including, //if it's a LyX file and we're inputting or including,
//try to load it so we can write the associated latex //try to load it so we can write the associated latex
if (!loadIfNeeded(buffer(), params())) if (!loadIfNeeded(buffer()))
return false; return false;
Buffer * tmp = theBufferList().getBuffer(included_file); Buffer * tmp = theBufferList().getBuffer(included_file);
@ -626,7 +626,7 @@ int InsetInclude::docbook(odocstream & os, OutputParams const & runparams) const
string const exportfile = changeExtension(incfile, ".sgml"); string const exportfile = changeExtension(incfile, ".sgml");
DocFileName writefile(changeExtension(included_file, ".sgml")); DocFileName writefile(changeExtension(included_file, ".sgml"));
if (loadIfNeeded(buffer(), params())) { if (loadIfNeeded(buffer())) {
Buffer * tmp = theBufferList().getBuffer(FileName(included_file)); Buffer * tmp = theBufferList().getBuffer(FileName(included_file));
string const mangled = writefile.mangledFilename(); string const mangled = writefile.mangledFilename();
@ -689,7 +689,7 @@ void InsetInclude::validate(LaTeXFeatures & features) const
// Here we must do the fun stuff... // Here we must do the fun stuff...
// Load the file in the include if it needs // Load the file in the include if it needs
// to be loaded: // to be loaded:
if (loadIfNeeded(buffer(), params())) { if (loadIfNeeded(buffer())) {
// a file got loaded // a file got loaded
Buffer * const tmp = theBufferList().getBuffer(FileName(included_file)); Buffer * const tmp = theBufferList().getBuffer(FileName(included_file));
// make sure the buffer isn't us // make sure the buffer isn't us
@ -711,7 +711,7 @@ void InsetInclude::validate(LaTeXFeatures & features) const
void InsetInclude::fillWithBibKeys(BiblioInfo & keys, void InsetInclude::fillWithBibKeys(BiblioInfo & keys,
InsetIterator const & /*di*/) const InsetIterator const & /*di*/) const
{ {
if (loadIfNeeded(buffer(), params())) { if (loadIfNeeded(buffer())) {
string const included_file = includedFilename(buffer(), params()).absFilename(); string const included_file = includedFilename(buffer(), params()).absFilename();
Buffer * tmp = theBufferList().getBuffer(FileName(included_file)); Buffer * tmp = theBufferList().getBuffer(FileName(included_file));
BiblioInfo const & newkeys = tmp->localBibInfo(); BiblioInfo const & newkeys = tmp->localBibInfo();
@ -722,7 +722,7 @@ void InsetInclude::fillWithBibKeys(BiblioInfo & keys,
void InsetInclude::updateBibfilesCache() void InsetInclude::updateBibfilesCache()
{ {
Buffer * const tmp = getChildBuffer(buffer(), params()); Buffer * const tmp = getChildBuffer(buffer());
if (tmp) { if (tmp) {
tmp->setParent(0); tmp->setParent(0);
tmp->updateBibfilesCache(); tmp->updateBibfilesCache();
@ -734,7 +734,7 @@ void InsetInclude::updateBibfilesCache()
support::FileNameList const & support::FileNameList const &
InsetInclude::getBibfilesCache(Buffer const & buffer) const InsetInclude::getBibfilesCache(Buffer const & buffer) const
{ {
Buffer * const tmp = getChildBuffer(buffer, params()); Buffer * const tmp = getChildBuffer(buffer);
if (tmp) { if (tmp) {
tmp->setParent(0); tmp->setParent(0);
support::FileNameList const & cache = tmp->getBibfilesCache(); support::FileNameList const & cache = tmp->getBibfilesCache();
@ -888,7 +888,7 @@ void InsetInclude::addToToc(DocIterator const & cpit)
toc.push_back(TocItem(pit, 0, str)); toc.push_back(TocItem(pit, 0, str));
return; return;
} }
Buffer const * const childbuffer = getChildBuffer(buffer(), params()); Buffer const * const childbuffer = getChildBuffer(buffer());
if (!childbuffer) if (!childbuffer)
return; return;
@ -909,7 +909,7 @@ void InsetInclude::addToToc(DocIterator const & cpit)
void InsetInclude::updateLabels(ParIterator const & it) void InsetInclude::updateLabels(ParIterator const & it)
{ {
Buffer const * const childbuffer = getChildBuffer(buffer(), params()); Buffer const * const childbuffer = getChildBuffer(buffer());
if (childbuffer) { if (childbuffer) {
childbuffer->updateLabels(true); childbuffer->updateLabels(true);
return; return;

View File

@ -95,6 +95,10 @@ public:
static bool isCompatibleCommand(std::string const & s); static bool isCompatibleCommand(std::string const & s);
/// ///
docstring contextMenu(BufferView const & bv, int x, int y) const; docstring contextMenu(BufferView const & bv, int x, int y) const;
/// \return the child buffer if the file is a LyX doc and is loaded
Buffer * getChildBuffer(Buffer const & buffer) const;
/// \return loaded Buffer or zero if the file loading did not proceed.
Buffer * loadIfNeeded(Buffer const & parent) const;
protected: protected:
InsetInclude(InsetInclude const &); InsetInclude(InsetInclude const &);
/// ///
@ -128,8 +132,6 @@ private:
InsetLabel * label_; InsetLabel * label_;
}; };
/// return loaded Buffer or zero if the file loading did not proceed.
Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params);
} // namespace lyx } // namespace lyx