mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
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:
parent
316a17f414
commit
9722c8f1ea
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user