Fix crash when the Outline dialog is opened on an empty document. This was caused by the commented out updateLabels() in LyXFunc::menuNew().

* Text: new empty() method.

* buffer_funcs.cpp:updateLabels(): return early in case of empty document.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19566 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-08-14 16:59:59 +00:00
parent 8a221dc70c
commit 8f83eab31f
4 changed files with 25 additions and 2 deletions

View File

@ -1998,7 +1998,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
Buffer * const b = newFile(filename, templname, !name.empty());
if (b) {
//updateLabels(*b);
updateLabels(*b);
lyx_view_->setBuffer(b);
}
}

View File

@ -344,6 +344,13 @@ void readParagraph(Buffer const & buf, Paragraph & par, Lexer & lex,
} // namespace anon
bool Text::empty() const
{
return pars_.empty() || (pars_.size() == 1 && pars_[0].empty()
// FIXME: Should we consider the labeled type as empty too?
&& pars_[0].layout()->labeltype == LABEL_NO_LABEL);
}
double Text::spacing(Buffer const & buffer,
Paragraph const & par) const

View File

@ -49,6 +49,11 @@ public:
/// constructor
explicit Text();
/// \return true if there's no content at all.
/// \warning a non standard layout on an empty paragraph doesn't
// count as empty.
bool empty() const;
///
Font getFont(Buffer const & buffer, Paragraph const & par,
pos_type pos) const;

View File

@ -578,6 +578,8 @@ void updateLabels(Buffer const & buf, ParIterator & parit)
}
// FIXME: buf should should be const because updateLabels() modifies
// the contents of the paragraphs.
void updateLabels(Buffer const & buf, bool childonly)
{
Buffer const * const master = buf.getMasterBuffer();
@ -595,11 +597,20 @@ void updateLabels(Buffer const & buf, bool childonly)
textclass.counters().reset();
}
Buffer & cbuf = const_cast<Buffer &>(buf);
if (buf.text().empty()) {
// FIXME: we don't call continue with updateLabels() here because
// it crashes on newly created documents. But the TocBackend needs to
// be initialised nonetheless so we update the tocBackend manually.
cbuf.tocBackend().update();
return;
}
// do the real work
ParIterator parit = par_iterator_begin(buf.inset());
updateLabels(buf, parit);
Buffer & cbuf = const_cast<Buffer &>(buf);
cbuf.tocBackend().update();
if (!childonly)
cbuf.structureChanged();