From 8f83eab31f18602108b740c3d2a1ef32b95eb19d Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 14 Aug 2007 16:59:59 +0000 Subject: [PATCH] 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 --- src/LyXFunc.cpp | 2 +- src/Text.cpp | 7 +++++++ src/Text.h | 5 +++++ src/buffer_funcs.cpp | 13 ++++++++++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index cc3d5fe026..5c104dcc56 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -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); } } diff --git a/src/Text.cpp b/src/Text.cpp index 3fd04c724f..abd71961a6 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -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 diff --git a/src/Text.h b/src/Text.h index a8ee899dca..7e154388a9 100644 --- a/src/Text.h +++ b/src/Text.h @@ -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; diff --git a/src/buffer_funcs.cpp b/src/buffer_funcs.cpp index 84b037e67c..85044361a7 100644 --- a/src/buffer_funcs.cpp +++ b/src/buffer_funcs.cpp @@ -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(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(buf); cbuf.tocBackend().update(); if (!childonly) cbuf.structureChanged(); -- 2.39.5