]> git.lyx.org Git - features.git/commitdiff
Fix bug http://bugzilla.lyx.org/show_bug.cgi?id=5328
authorAbdelrazak Younes <younes@lyx.org>
Wed, 8 Oct 2008 14:03:15 +0000 (14:03 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Wed, 8 Oct 2008 14:03:15 +0000 (14:03 +0000)
* Paragraph::insertInset(): check if inset insertion is allowed before insertion.

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

src/Paragraph.cpp
src/Paragraph.h
src/paragraph_funcs.cpp

index 385d5b0fc5a9c545b41b7a966fe7b7e1a0030d6c..34a1c6aa5cdfd24eebf05a35195f2c14d7bf1221 100644 (file)
@@ -449,17 +449,23 @@ void Paragraph::Private::insertChar(pos_type pos, char_type c,
 }
 
 
-void Paragraph::insertInset(pos_type pos, Inset * inset,
+bool Paragraph::insertInset(pos_type pos, Inset * inset,
                                   Change const & change)
 {
        LASSERT(inset, /**/);
        LASSERT(pos >= 0 && pos <= size(), /**/);
 
+       // Paragraph::insertInset() can be used in cut/copy/paste operation where
+       // d->inset_owner_ is not set yet.
+       if (d->inset_owner_ && d->inset_owner_->insetAllowed(inset->lyxCode()))
+               return false;
+
        d->insertChar(pos, META_INSET, change);
        LASSERT(d->text_[pos] == META_INSET, /**/);
 
        // Add a new entry in the insetlist_.
        d->insetlist_.insert(inset, pos);
+       return true;
 }
 
 
@@ -1303,12 +1309,13 @@ void Paragraph::insertChar(pos_type pos, char_type c,
 }
 
 
-void Paragraph::insertInset(pos_type pos, Inset * inset,
+bool Paragraph::insertInset(pos_type pos, Inset * inset,
                            Font const & font, Change const & change)
 {
-       insertInset(pos, inset, change);
+       bool const success = insertInset(pos, inset, change);
        // Set the font/language of the inset...
        setFont(pos, font);
+       return success;
 }
 
 
index 6e0657d0f2eeda474dff529dd32b2fab01495201..06318200c92aa0720111828ee95c270386b6b301 100644 (file)
@@ -304,12 +304,15 @@ public:
        ///
        void insertChar(pos_type pos, char_type c,
                        Font const &, Change const & change);
-       ///
-       void insertInset(pos_type pos, Inset * inset,
+       /// Insert \p inset at position \p pos with \p change traking status.
+       /// \return true if successful.
+       bool insertInset(pos_type pos, Inset * inset,
                         Change const & change);
-       ///
-       void insertInset(pos_type pos, Inset * inset,
-                        Font const &, Change const & change);
+       /// Insert \p inset at position \p pos with \p change traking status and
+       /// \p font.
+       /// \return true if successful.
+       bool insertInset(pos_type pos, Inset * inset,
+                        Font const & font, Change const & change);
        ///
        Inset * getInset(pos_type pos);
        ///
index 600d361bd720ced8849199e4c97ea6791421702f..42b95330bff8075f4f664a66b9a59efd13c4dbf1 100644 (file)
@@ -46,13 +46,7 @@ static bool moveItem(Paragraph & fromPar, pos_type fromPos,
                        // the inset is not in the paragraph any more
                        tmpInset = fromPar.releaseInset(fromPos);
                }
-
-               if (!toPar.inInset().insetAllowed(tmpInset->lyxCode())) {
-                       delete tmpInset;
-                       return false;
-               }
-
-               toPar.insertInset(toPos, tmpInset, tmpFont, tmpChange);
+               return toPar.insertInset(toPos, tmpInset, tmpFont, tmpChange);
        } else {
                fromPar.eraseChar(fromPos, false);
                toPar.insertChar(toPos, tmpChar, tmpFont, tmpChange);