Add a global accessible function loadIfNeeded().

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31705 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2009-10-24 14:57:28 +00:00
parent 316a17f414
commit 9722c8f1ea
2 changed files with 27 additions and 0 deletions

View File

@ -249,4 +249,27 @@ int countChars(DocIterator const & from, DocIterator const & to,
return chars + blanks;
}
Buffer * loadIfNeeded(FileName const & fname)
{
Buffer * buffer = theBufferList().getBuffer(fname);
if (!buffer) {
if (!fname.exists())
return 0;
buffer = theBufferList().newBuffer(fname.absFilename());
if (!buffer)
// Buffer creation is not possible.
return 0;
if (!buffer->loadLyXFile(fname)) {
//close the buffer we just opened
theBufferList().release(buffer);
return 0;
}
}
return buffer;
}
} // namespace lyx

View File

@ -42,6 +42,10 @@ Buffer * newFile(std::string const & filename, std::string const & templatename,
Buffer * newUnnamedFile(support::FileName const & path,
std::string const & prefix, std::string const & templatename = "");
/// Load the file with name \c fname, and returns the buffer. If the
/// file was already loaded it just returns the associated buffer.
Buffer * loadIfNeeded(support::FileName const & fname);
/// Count the number of words in the text between these two iterators
int countWords(DocIterator const & from, DocIterator const & to);