]> git.lyx.org Git - lyx.git/commitdiff
* buffer.[Ch]: new function hasParWithId() to help to get rid of a
authorAndré Pönitz <poenitz@gmx.net>
Mon, 5 May 2003 17:28:21 +0000 (17:28 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 5 May 2003 17:28:21 +0000 (17:28 +0000)
  few naked Paragraph *.
* undo_funcs use getParagraphs() instead of getFirstParagraph()

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6935 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/buffer.C
src/buffer.h
src/insets/ChangeLog
src/undo_funcs.C

index bf6a53afafe447561c89a9d9969ea10e3a62dd36..903eb5b7ab4cea902e7b0626952b3067a283ee4c 100644 (file)
@@ -4,6 +4,9 @@
        * iterator.C: 
        * undo_funcs.C: use getParagraphs() instead of getFirstParagraph()
 
+       * buffer.[Ch]: new function hasParWithId() to help to get rid of a
+         few naked Paragraph *.
+
 2003-05-02  Michael Schmitt  <michael.schmitt@teststep.org>
 
        * bufferparams.C: Output warning if a document with missing
index ebf5700814ab863aaa5a863e823595ddc48165a7..faa21353ebae61b0d009b5ef1010382eb32bfe2a 100644 (file)
@@ -2293,6 +2293,25 @@ ParagraphList::iterator Buffer::getParFromID(int id) const
 }
 
 
+bool Buffer::hasParWithID(int id) const
+{
+       ParIterator it(const_cast<Buffer*>(this)->par_iterator_begin());
+       ParIterator end(const_cast<Buffer*>(this)->par_iterator_end());
+
+       if (id < 0) {
+               // John says this is called with id == -1 from undo
+               lyxerr << "hasParWithID(), id: " << id << endl;
+               return 0;
+       }
+
+       for (; it != end; ++it)
+               if ((*it)->id() == id)
+                       return true;
+
+       return false;
+}
+
+
 ParIterator Buffer::par_iterator_begin()
 {
        return ParIterator(&*(paragraphs.begin()));
index 2b324c0fb9b42692f26db65df07430bffdd6598b..c6a2cb8901e50c1fffdd4e708735c2d690200b12 100644 (file)
@@ -123,6 +123,8 @@ public:
                                 LyXFont const &, string const &);
        ///
        ParagraphList::iterator getParFromID(int id) const;
+       /// do we have a paragraph with this id?
+       bool hasParWithID(int id) const;
 
 public:
        /** Save file.
index 992051054362b54fff6c1c36f58ece2f3c0d4f09..8f663e758a6b3c5095ebf11b1aba7facd90371ff 100644 (file)
@@ -5,6 +5,7 @@
        * insettext.[Ch]:
        * insettabular.[Ch]:
        * insetcollapsable.[Ch]: remove unused function firstParagraph()
+       replace getFirstParagraph() by getParagraphs()
 
 2003-05-03  John Levon  <levon@movementarian.org>
 
index 71467a6dafb74501dc97162ff089f66683f14bcb..63cbe37fc91a8a3794116fa191c76df248e8472e 100644 (file)
@@ -46,15 +46,15 @@ LyXCursor const & undoCursor(BufferView * bv)
  * we are so it will return the first paragraph of the buffer or the
  * first paragraph of the textinset we're in.
  */
-Paragraph * firstUndoParagraph(BufferView * bv, int inset_id)
+ParagraphList undoParagraphs(BufferView * bv, int inset_id)
 {
        Inset * inset = bv->buffer()->getInsetFromID(inset_id);
        if (inset) {
                ParagraphList * result = inset->getParagraphs(0);
                if (result && !result->empty())
-                       return &result->front();
+                       return *result;
        }
-       return &bv->text->ownerParagraphs().front();
+       return bv->text->ownerParagraphs();
 }
 
 
@@ -93,7 +93,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
                                num = -1;
                        }
                }
-               t->setCursorIntern(firstUndoParagraph(bv, num), 0);
+               t->setCursorIntern(undoParagraphs(bv, num).begin(), 0);
        }
 
        // Set the right(new) inset-owner of the paragraph if there is any. 
@@ -116,7 +116,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
                if (before)
                        deletepar = before->next();
                else
-                       deletepar = firstUndoParagraph(bv, undo.number_of_inset_id);
+                       deletepar = &undoParagraphs(bv, undo.number_of_inset_id).front();
                // this surprisingly fills the undo! (Andre')
                size_t par = 0;
                while (deletepar && deletepar != behind) {
@@ -152,7 +152,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
                if (before)
                        before->next(undopar);
                else {
-                       int id = firstUndoParagraph(bv, undo.number_of_inset_id)->id();
+                       int id = undoParagraphs(bv, undo.number_of_inset_id).front().id();
                        Paragraph * op = &*bv->buffer()->getParFromID(id);
                        if (op && op->inInset()) {
                                static_cast<InsetText*>(op->inInset())->paragraph(undopar);
@@ -165,7 +165,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
                // have to substitue the second paragraph with the
                // first if the removed one is the first.
                if (!before && behind) {
-                       int id = firstUndoParagraph(bv, undo.number_of_inset_id)->id();
+                       int id = undoParagraphs(bv, undo.number_of_inset_id).front().id();
                        Paragraph * op = &*bv->buffer()->getParFromID(id);
                        if (op && op->inInset()) {
                                static_cast<InsetText*>(op->inInset())->paragraph(behind);
@@ -382,7 +382,7 @@ bool textUndoOrRedo(BufferView * bv,
                if (first && first->next())
                        first = first->next();
                else if (!first)
-                       first = firstUndoParagraph(bv, undo->number_of_inset_id);
+                       first = &*undoParagraphs(bv, undo->number_of_inset_id).begin();
                if (first) {
                        shared_ptr<Undo> u;
                        if (createUndo(bv, undo->kind, first,