]> git.lyx.org Git - lyx.git/blobdiff - src/CutAndPaste.cpp
simplification
[lyx.git] / src / CutAndPaste.cpp
index f7aca651f0880e1095c18f9fd36f743cec2e8b99..998bd9d9d72ec5393a3785bac032b388dc8cddd5 100644 (file)
@@ -46,7 +46,9 @@
 #include "mathed/InsetMath.h"
 #include "mathed/MathSupport.h"
 
+#include "support/limited_stack.h"
 #include "support/lstrings.h"
+#include "support/docstream.h"
 
 #include "frontends/Clipboard.h"
 #include "frontends/Selection.h"
@@ -195,7 +197,7 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
                // Set the inset owner of this paragraph.
                tmpbuf->setInsetOwner(pars[pit].inInset());
                for (pos_type i = 0; i < tmpbuf->size(); ++i) {
-                       if (tmpbuf->getChar(i) == Paragraph::META_INSET &&
+                       if (tmpbuf->isInset(i) &&
                            !pars[pit].insetAllowed(tmpbuf->getInset(i)->lyxCode()))
                                // do not track deletion of invalid insets
                                tmpbuf->eraseChar(i--, false);
@@ -376,8 +378,7 @@ void copySelectionHelper(Buffer const & buf, ParagraphList & pars,
                // This is invalid outside of ERT, so we need to change it
                // to the buffer language.
                if (it->ownerCode() == ERT_CODE || it->ownerCode() == LISTINGS_CODE) {
-                       it->changeLanguage(buf.params(), latex_language,
-                                          buf.getLanguage());
+                       it->changeLanguage(buf.params(), latex_language, buf.language());
                }
                it->setInsetOwner(0);
        }
@@ -444,27 +445,28 @@ void switchBetweenClasses(TextClassPtr const & c1,
        // character styles
        InsetIterator const i_end = inset_iterator_end(in);
        for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) {
-               if (it->lyxCode() == FLEX_CODE) {
-                       InsetFlex & inset =
-                               static_cast<InsetFlex &>(*it);
-                       string const name = inset.params().name;
-                       InsetLayout const il = 
-                               tclass2.insetlayout(from_utf8(name));
-                       inset.setLayout(il);
-                       if (il.labelstring == from_utf8("UNDEFINED")) {
-                               // The flex inset is undefined in tclass2
-                               docstring const s = bformat(_(
-                                       "Flex inset %1$s is "
-                                       "undefined because of class "
-                                       "conversion from\n%2$s to %3$s"),
-                                        from_utf8(name), from_utf8(tclass1.name()),
-                                        from_utf8(tclass2.name()));
-                               // To warn the user that something had to be done.
-                               errorlist.push_back(ErrorItem(
-                                       _("Undefined flex inset"),
-                                       s, it.paragraph().id(), it.pos(), it.pos() + 1));
-                       } 
-               }
+               InsetCollapsable * inset = it->asInsetCollapsable();
+               if (!inset)
+                       continue;
+               if (inset->lyxCode() != FLEX_CODE)
+                       // FIXME: Should we verify all InsetCollapsable?
+                       continue;
+               docstring const name = inset->name();
+               InsetLayout const & il = tclass2.insetlayout(name);
+               inset->setLayout(il);
+               if (il.labelstring != from_utf8("UNDEFINED"))
+                       continue;
+               // The flex inset is undefined in tclass2
+               docstring const s = bformat(_(
+                       "Flex inset %1$s is "
+                       "undefined because of class "
+                       "conversion from\n%2$s to %3$s"),
+                       name, from_utf8(tclass1.name()),
+                       from_utf8(tclass2.name()));
+               // To warn the user that something had to be done.
+               errorlist.push_back(ErrorItem(
+                               _("Undefined flex inset"),
+                               s, it.paragraph().id(), it.pos(), it.pos() + 1));
        }
 }
 
@@ -672,9 +674,8 @@ void saveSelection(Cursor & cur)
        if (cur.selection() 
            && cur.selBegin() == cur.bv().cursor().selBegin()
            && cur.selEnd() == cur.bv().cursor().selEnd()) {
-               LYXERR(Debug::ACTION) << BOOST_CURRENT_FUNCTION << ": `"
-                          << to_utf8(cur.selectionAsString(true)) << "'."
-                          << endl;
+               LYXERR(Debug::ACTION, BOOST_CURRENT_FUNCTION << ": `"
+                          << to_utf8(cur.selectionAsString(true)) << "'.");
                copySelectionToStack(cur, selectionBuffer);
        }
 }