]> git.lyx.org Git - features.git/commitdiff
Fix crash when the Outline dialog is opened on an empty document. This was caused...
authorAbdelrazak Younes <younes@lyx.org>
Tue, 14 Aug 2007 16:59:59 +0000 (16:59 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Tue, 14 Aug 2007 16:59:59 +0000 (16:59 +0000)
* 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
src/Text.cpp
src/Text.h
src/buffer_funcs.cpp

index cc3d5fe0269e45950ad167677c4c926699e5bec9..5c104dcc56ba26fae54609e84a83a74cd7c4d24a 100644 (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);
        }
 }
index 3fd04c724f69f9c6c689f516b25af67ac1cf90eb..abd71961a68822cd04248846a84cafc51042a880 100644 (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
index a8ee899dca36537cce030cc69e5dfa1c13b8cfc5..7e154388a9f0e18ee5cfcdab7c450d75a008dcce 100644 (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;
index 84b037e67cf960ce8e312731804979e2f5bd375d..85044361a79141df1c57f597808ce4dd6bf7ddd8 100644 (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();