]> git.lyx.org Git - lyx.git/blobdiff - src/CutAndPaste.C
more cursor dispatch
[lyx.git] / src / CutAndPaste.C
index 3e787f98083ea396eacdb4602831abcddfff26c7..522b7d31ef9b44e601bd8fb7fd4e5d5a82abae82 100644 (file)
@@ -15,6 +15,7 @@
 #include "CutAndPaste.h"
 
 #include "buffer.h"
+#include "bufferparams.h"
 #include "errorlist.h"
 #include "gettext.h"
 #include "iterators.h"
 #include "paragraph_funcs.h"
 #include "ParagraphParameters.h"
 
-#include "insets/insetinclude.h"
 #include "insets/insettabular.h"
 
-#include "support/LAssert.h"
 #include "support/lstrings.h"
 
+using lyx::pos_type;
+using lyx::textclass_type;
+
+using lyx::support::bformat;
+
 using std::for_each;
 using std::make_pair;
 using std::pair;
 using std::vector;
-
-using namespace lyx::support;
-using lyx::pos_type;
-using lyx::textclass_type;
+using std::string;
 
 
 typedef limited_stack<pair<ParagraphList, textclass_type> > CutStack;
@@ -48,7 +49,7 @@ CutStack cuts(10);
 } // namespace anon
 
 
-std::vector<string>
+std::vector<string> const
 CutAndPaste::availableSelections(Buffer const & buffer)
 {
        vector<string> selList;
@@ -164,8 +165,8 @@ PitPosPair CutAndPaste::eraseSelection(BufferParams const & params,
 
 namespace {
 
-struct resetOwnerAndChanges {
-       void operator()(Paragraph & p) {
+struct resetOwnerAndChanges : public std::unary_function<Paragraph, void> {
+       void operator()(Paragraph & p) const {
                p.cleanChanges();
                p.setInsetOwner(0);
        }
@@ -177,16 +178,15 @@ bool CutAndPaste::copySelection(ParagraphList::iterator startpit,
                                ParagraphList::iterator endpit,
                                int start, int end, textclass_type tc)
 {
-       Assert(0 <= start && start <= startpit->size());
-       Assert(0 <= end && end <= endpit->size());
-       Assert(startpit != endpit || start <= end);
+       BOOST_ASSERT(0 <= start && start <= startpit->size());
+       BOOST_ASSERT(0 <= end && end <= endpit->size());
+       BOOST_ASSERT(startpit != endpit || start <= end);
 
-       ParagraphList paragraphs;
 
        // Clone the paragraphs within the selection.
        ParagraphList::iterator postend = boost::next(endpit);
 
-       paragraphs.assign(startpit, postend);
+       ParagraphList paragraphs(startpit, postend);
        for_each(paragraphs.begin(), paragraphs.end(), resetOwnerAndChanges());
 
        // Cut out the end of the last paragraph.
@@ -224,7 +224,7 @@ CutAndPaste::pasteSelection(Buffer const & buffer,
        if (!checkPastePossible())
                return make_pair(PitPosPair(pit, pos), pit);
 
-       Assert (pos <= pit->size());
+       BOOST_ASSERT (pos <= pit->size());
 
        // Make a copy of the CaP paragraphs.
        ParagraphList simple_cut_clone = cuts[cut_index].first;
@@ -248,7 +248,7 @@ CutAndPaste::pasteSelection(Buffer const & buffer,
                // this new max depth level so that subsequent
                // paragraphs are aligned correctly to this paragraph
                // at level 0.
-               if ((int(tmpbuf->params().depth()) + depth_delta) < 0)
+               if (int(tmpbuf->params().depth()) + depth_delta < 0)
                        depth_delta = 0;
 
                // Set the right depth so that we are not too deep or shallow.
@@ -265,17 +265,8 @@ CutAndPaste::pasteSelection(Buffer const & buffer,
                tmpbuf->setInsetOwner(pit->inInset());
                for (pos_type i = 0; i < tmpbuf->size(); ++i) {
                        if (tmpbuf->getChar(i) == Paragraph::META_INSET) {
-                               if (!pit->insetAllowed(tmpbuf->getInset(i)->lyxCode())) {
-                                       tmpbuf->erase(i--);
-                               }
-                       } else {
-                               LyXFont f1 = tmpbuf->getFont(buffer.params(), i, outerFont(pit, pars));
-                               LyXFont f2 = f1;
-                               if (!pit->checkInsertChar(f1)) {
+                               if (!pit->insetAllowed(tmpbuf->getInset(i)->lyxCode()))
                                        tmpbuf->erase(i--);
-                               } else if (f1 != f2) {
-                                       tmpbuf->setFont(i, f1);
-                               }
                        }
                }
        }
@@ -296,14 +287,6 @@ CutAndPaste::pasteSelection(Buffer const & buffer,
 
                for (; lit != eit; ++lit) {
                        switch (lit->inset->lyxCode()) {
-                       case InsetOld::INCLUDE_CODE: {
-                               InsetInclude * ii = static_cast<InsetInclude*>(lit->inset);
-                               InsetInclude::Params ip = ii->params();
-                               ip.masterFilename_ = buffer.fileName();
-                               ii->set(ip);
-                               break;
-                       }
-
                        case InsetOld::TABULAR_CODE: {
                                InsetTabular * it = static_cast<InsetTabular*>(lit->inset);
                                it->buffer(const_cast<Buffer*>(&buffer));
@@ -346,7 +329,6 @@ CutAndPaste::pasteSelection(Buffer const & buffer,
        pos = last_paste->size();
 
        // Maybe some pasting.
-#warning CHECK! Are we comparing last_paste to the wrong list here? (Lgb)
        if (boost::next(last_paste) != pars.end() &&
            paste_the_end) {
                if (boost::next(last_paste)->hasSameLayout(*last_paste)) {
@@ -379,7 +361,7 @@ int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1,
                                             ParagraphList & pars,
                                             ErrorList & errorlist)
 {
-       Assert(!pars.empty());
+       BOOST_ASSERT(!pars.empty());
 
        int ret = 0;
        if (c1 == c2)