New function BufferList::newInternalBuffer

This solves the problem that newBuffer() already use Buffer::isInternal
but there was no chance to set it yet.

(cherry picked from commit 6cf1847b31)
This commit is contained in:
Vincent van Ravesteijn 2012-05-12 14:11:56 +02:00
parent 0b60b468c4
commit c9cbd538b8
4 changed files with 33 additions and 11 deletions

View File

@ -104,7 +104,29 @@ void BufferList::release(Buffer * buf)
} }
Buffer * BufferList::newInternalBuffer(string const & s)
{
Buffer * const buf = createNewBuffer(s, false);
if (buf) {
buf->setInternal(true);
binternal.push_back(buf);
}
return buf;
}
Buffer * BufferList::newBuffer(string const & s, bool const ronly) Buffer * BufferList::newBuffer(string const & s, bool const ronly)
{
Buffer * const buf = createNewBuffer(s, ronly);
if (buf) {
LYXERR(Debug::INFO, "Assigning to buffer " << bstore.size());
bstore.push_back(buf);
}
return buf;
}
Buffer * BufferList::createNewBuffer(string const & s, bool ronly)
{ {
auto_ptr<Buffer> tmpbuf; auto_ptr<Buffer> tmpbuf;
try { try {
@ -119,12 +141,6 @@ Buffer * BufferList::newBuffer(string const & s, bool const ronly)
} }
} }
tmpbuf->params().useClassDefaults(); 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(); return tmpbuf.release();
} }

View File

@ -47,10 +47,14 @@ public:
iterator end(); iterator end();
const_iterator end() const; const_iterator end() const;
/// create a new buffer /// create a new buffer and add it to the buffer list
/// \return 0 if the Buffer creation is not possible for whatever reason. /// \return 0 if the Buffer creation is not possible for whatever reason.
Buffer * newBuffer(std::string const & s, bool ronly = false); Buffer * newBuffer(std::string const & s, bool ronly = false);
/// create an internal buffer and add it to the internal buffer list
/// \return 0 if the Buffer creation is not possible for whatever reason.
Buffer * newInternalBuffer(std::string const & s);
/// delete a buffer /// delete a buffer
void release(Buffer * b); void release(Buffer * b);
@ -120,6 +124,10 @@ public:
//@} //@}
private: private:
/// create a new buffer
/// \return 0 if the Buffer creation is not possible for whatever reason.
Buffer * createNewBuffer(std::string const & s, bool ronly);
/// noncopiable /// noncopiable
BufferList(BufferList const &); BufferList(BufferList const &);
void operator=(BufferList const &); void operator=(BufferList const &);

View File

@ -469,9 +469,8 @@ void putClipboard(ParagraphList const & paragraphs,
// a DocumentClass, via new, that is never deleted. If we were to go to // a DocumentClass, via new, that is never deleted. If we were to go to
// some kind of garbage collection there, or a shared_ptr, then this // some kind of garbage collection there, or a shared_ptr, then this
// would not be needed. // would not be needed.
static Buffer * buffer = theBufferList().newBuffer( static Buffer * buffer = theBufferList().newInternalBuffer(
FileName::tempName("clipboard.internal").absFileName()); FileName::tempName("clipboard.internal").absFileName());
buffer->setInternal(true);
buffer->setUnnamed(true); buffer->setUnnamed(true);
buffer->paragraphs() = paragraphs; buffer->paragraphs() = paragraphs;
buffer->inset().setBuffer(*buffer); buffer->inset().setBuffer(*buffer);

View File

@ -1369,9 +1369,8 @@ bool GuiWorkArea::isFullScreen()
EmbeddedWorkArea::EmbeddedWorkArea(QWidget * w): GuiWorkArea(w) EmbeddedWorkArea::EmbeddedWorkArea(QWidget * w): GuiWorkArea(w)
{ {
buffer_ = theBufferList().newBuffer( buffer_ = theBufferList().newInternalBuffer(
support::FileName::tempName("embedded.internal").absFileName()); support::FileName::tempName("embedded.internal").absFileName());
buffer_->setInternal(true);
buffer_->setUnnamed(true); buffer_->setUnnamed(true);
buffer_->setFullyLoaded(true); buffer_->setFullyLoaded(true);
setBuffer(*buffer_); setBuffer(*buffer_);