X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FBufferList.cpp;h=2348ac610348b28d96634f877a79a87bfefa7962;hb=0899e957c39a0d7157a809059afb08389f205d2d;hp=466c924bdb2db851a29fb013703ddb4870966626;hpb=5a46224f7311067cda747e0cae32d22dd919f179;p=lyx.git diff --git a/src/BufferList.cpp b/src/BufferList.cpp index 466c924bdb..2348ac6103 100644 --- a/src/BufferList.cpp +++ b/src/BufferList.cpp @@ -104,11 +104,33 @@ void BufferList::release(Buffer * buf) } -Buffer * BufferList::newBuffer(string const & s, bool const ronly) +Buffer * BufferList::newInternalBuffer(string const & s) +{ + Buffer * const buf = createNewBuffer(s); + if (buf) { + buf->setInternal(true); + binternal.push_back(buf); + } + return buf; +} + + +Buffer * BufferList::newBuffer(string const & s) +{ + Buffer * const buf = createNewBuffer(s); + if (buf) { + LYXERR(Debug::INFO, "Assigning to buffer " << bstore.size()); + bstore.push_back(buf); + } + return buf; +} + + +Buffer * BufferList::createNewBuffer(string const & s) { auto_ptr tmpbuf; try { - tmpbuf.reset(new Buffer(s, ronly)); + tmpbuf.reset(new Buffer(s)); } catch (ExceptionMessage const & message) { if (message.type_ == ErrorException) { Alert::error(message.title_, message.details_); @@ -119,12 +141,6 @@ Buffer * BufferList::newBuffer(string const & s, bool const ronly) } } tmpbuf->params().useClassDefaults(); - if (tmpbuf->isInternal()) { - binternal.push_back(tmpbuf.get()); - } else { - LYXERR(Debug::INFO, "Assigning to buffer " << bstore.size()); - bstore.push_back(tmpbuf.get()); - } return tmpbuf.release(); } @@ -140,9 +156,12 @@ FileNameList const & BufferList::fileNames() const { static FileNameList nvec; nvec.clear(); - transform(bstore.begin(), bstore.end(), - back_inserter(nvec), - bind(&Buffer::fileName, _1)); + BufferStorage::const_iterator it = bstore.begin(); + BufferStorage::const_iterator end = bstore.end(); + for (; it != end; ++it) { + Buffer * buf = *it; + nvec.push_back(buf->fileName()); + } return nvec; } @@ -177,8 +196,8 @@ Buffer * BufferList::next(Buffer const * buf) const if (bstore.empty()) return 0; - BufferStorage::const_iterator it = find(bstore.begin(), - bstore.end(), buf); + BufferStorage::const_iterator it = + find(bstore.begin(), bstore.end(), buf); LASSERT(it != bstore.end(), /**/); ++it; Buffer * nextbuf = (it == bstore.end()) ? bstore.front() : *it; @@ -192,8 +211,8 @@ Buffer * BufferList::previous(Buffer const * buf) const if (bstore.empty()) return 0; - BufferStorage::const_iterator it = find(bstore.begin(), - bstore.end(), buf); + BufferStorage::const_iterator it = + find(bstore.begin(), bstore.end(), buf); LASSERT(it != bstore.end(), /**/); Buffer * previousbuf = (it == bstore.begin()) ? bstore.back() : *(it - 1); @@ -202,18 +221,21 @@ Buffer * BufferList::previous(Buffer const * buf) const void BufferList::updateIncludedTeXfiles(string const & masterTmpDir, - OutputParams const & runparams) + OutputParams const & runparams_in) { + OutputParams runparams = runparams_in; + runparams.is_child = true; BufferStorage::iterator it = bstore.begin(); BufferStorage::iterator end = bstore.end(); for (; it != end; ++it) { if (!(*it)->isDepClean(masterTmpDir)) { string writefile = addName(masterTmpDir, (*it)->latexName()); (*it)->makeLaTeXFile(FileName(writefile), masterTmpDir, - runparams, false); + runparams, Buffer::OnlyBody); (*it)->markDepClean(masterTmpDir); } } + runparams.is_child = false; } @@ -243,25 +265,43 @@ bool BufferList::exists(FileName const & fname) const namespace { + struct equivalent_to : public binary_function { bool operator()(FileName const & x, FileName const & y) const { return equivalent(x, y); } }; + } -Buffer * BufferList::getBuffer(support::FileName const & fname) const +Buffer * BufferList::getBuffer(support::FileName const & fname, bool internal) const { // 1) cheap test, using string comparison of file names BufferStorage::const_iterator it = find_if(bstore.begin(), bstore.end(), lyx::bind(equal_to(), lyx::bind(&Buffer::fileName, _1), fname)); if (it != bstore.end()) - return *it; + return *it; // 2) possibly expensive test, using equivalence test of file names it = find_if(bstore.begin(), bstore.end(), lyx::bind(equivalent_to(), lyx::bind(&Buffer::fileName, _1), fname)); - return it != bstore.end() ? (*it) : 0; + if (it != bstore.end()) + return *it; + + if (internal) { + // 1) cheap test, using string comparison of file names + BufferStorage::const_iterator it = find_if(binternal.begin(), binternal.end(), + lyx::bind(equal_to(), lyx::bind(&Buffer::fileName, _1), fname)); + if (it != binternal.end()) + return *it; + // 2) possibly expensive test, using equivalence test of file names + it = find_if(binternal.begin(), binternal.end(), + lyx::bind(equivalent_to(), lyx::bind(&Buffer::fileName, _1), fname)); + if (it != binternal.end()) + return *it; + } + + return 0; } @@ -292,12 +332,12 @@ Buffer * BufferList::getBufferFromTmp(string const & s) } -void BufferList::setCurrentAuthor(docstring const & name, docstring const & email) +void BufferList::recordCurrentAuthor(Author const & author) { BufferStorage::iterator it = bstore.begin(); BufferStorage::iterator end = bstore.end(); for (; it != end; ++it) - (*it)->params().authors().record(0, Author(name, email)); + (*it)->params().authors().recordCurrentAuthor(author); }