]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
do what the FIXME suggested
[lyx.git] / src / Text3.cpp
index 303eaf9f66d6432a46f0c1accd1d3a2de9b27d68..52f0e0dda6a616d6cde70cd5934266a9363244ce 100644 (file)
@@ -220,7 +220,7 @@ static bool doInsertInset(Cursor & cur, Text * text,
        if (insetText && !insetText->allowMultiPar() || cur.lastpit() == 0) {
                // reset first par to default
                cur.text()->paragraphs().begin()
-                       ->setEmptyOrDefaultLayout(bparams.textClass());
+                       ->setEmptyOrDefaultLayout(bparams.documentClass());
                cur.pos() = 0;
                cur.pit() = 0;
                // Merge multiple paragraphs -- hack
@@ -229,8 +229,8 @@ static bool doInsertInset(Cursor & cur, Text * text,
        } else {
                // reset surrounding par to default
                docstring const layoutname = insetText->useEmptyLayout()
-                       ? bparams.textClass().emptyLayoutName()
-                       : bparams.textClass().defaultLayoutName();
+                       ? bparams.documentClass().emptyLayoutName()
+                       : bparams.documentClass().defaultLayoutName();
                cur.leaveInset(*inset);
                text->setLayout(cur, layoutname);
        }
@@ -266,27 +266,28 @@ static void outline(OutlineOp mode, Cursor & cur)
        ParagraphList::iterator finish = start;
        ParagraphList::iterator end = pars.end();
 
-       TextClass const & tc = buf.params().textClass();
+       DocumentClass const & tc = buf.params().documentClass();
 
        int const thistoclevel = start->layout()->toclevel;
        int toclevel;
+
+       // Move out (down) from this section header
+       if (finish != end)
+               ++finish;
+       // Seek the one (on same level) below
+       for (; finish != end; ++finish) {
+               toclevel = finish->layout()->toclevel;
+               if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel) {
+                       break;
+               }
+       }
+
        switch (mode) {
                case OutlineUp: {
-                       // Move out (down) from this section header
-                       if (finish != end)
-                               ++finish;
-                       // Seek the one (on same level) below
-                       for (; finish != end; ++finish) {
-                               toclevel = finish->layout()->toclevel;
-                               if (toclevel != Layout::NOT_IN_TOC
-                                   && toclevel <= thistoclevel) {
-                                       break;
-                               }
-                       }
                        ParagraphList::iterator dest = start;
                        // Move out (up) from this header
                        if (dest == bgn)
-                               break;
+                               return;
                        // Search previous same-level header above
                        do {
                                --dest;
@@ -296,7 +297,7 @@ static void outline(OutlineOp mode, Cursor & cur)
                                    || toclevel > thistoclevel));
                        // Not found; do nothing
                        if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
-                               break;
+                               return;
                        pit_type const newpit = distance(bgn, dest);
                        pit_type const len = distance(start, finish);
                        pit_type const deletepit = pit + len;
@@ -305,30 +306,10 @@ static void outline(OutlineOp mode, Cursor & cur)
                        start = boost::next(pars.begin(), deletepit);
                        pit = newpit;
                        pars.erase(start, finish);
-                       break;
+                       return;
                }
                case OutlineDown: {
-                       // Go down out of current header:
-                       if (finish != end)
-                               ++finish;
-                       // Find next same-level header:
-                       for (; finish != end; ++finish) {
-                               toclevel = finish->layout()->toclevel;
-                               if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
-                                       break;
-                       }
                        ParagraphList::iterator dest = finish;
-                       // Go one down from *this* header:
-                       if (dest != end)
-                               ++dest;
-                       else
-                               break;
-                       // Go further down to find header to insert in front of:
-                       for (; dest != end; ++dest) {
-                               toclevel = dest->layout()->toclevel;
-                               if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
-                                       break;
-                       }
                        // One such was found:
                        pit_type newpit = distance(bgn, dest);
                        pit_type const len = distance(start, finish);
@@ -337,32 +318,44 @@ static void outline(OutlineOp mode, Cursor & cur)
                        start = boost::next(bgn, pit);
                        pit = newpit - len;
                        pars.erase(start, finish);
-                       break;
+                       return;
                }
-               case OutlineIn:
-                       buf.undo().recordUndo(cur);
-                       for (size_t i = 0; i != tc.layoutCount(); ++i) {
-                               LayoutPtr const & lt = tc.layout(i);
-                               if (lt->toclevel == thistoclevel + 1 &&
-                                   start->layout()->labeltype == lt->labeltype) {
-                                       start->setLayout(lt);
-                                       break;
+               case OutlineIn: {
+                       pit_type const len = distance(start, finish);
+                       buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
+                       for (; start != finish; ++start) {
+                               toclevel = start->layout()->toclevel;
+                               if (toclevel == Layout::NOT_IN_TOC)
+                                       continue;
+                               for (size_t i = 0; i != tc.layoutCount(); ++i) {
+                                       LayoutPtr const & lt = tc.layout(i);
+                                       if (lt->toclevel == toclevel + 1 &&
+                                           start->layout()->labeltype == lt->labeltype) {
+                                               start->setLayout(lt);
+                                               break;
+                                       }
                                }
                        }
-                       break;
-               case OutlineOut:
-                       buf.undo().recordUndo(cur);
-                       for (size_t i = 0; i != tc.layoutCount(); ++i) {
-                               LayoutPtr const & lt = tc.layout(i);
-                               if (lt->toclevel == thistoclevel - 1 &&
-                                   start->layout()->labeltype == lt->labeltype) {
-                                       start->setLayout(lt);
-                                       break;
+                       return;
+               }
+               case OutlineOut: {
+                       pit_type const len = distance(start, finish);
+                       buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
+                       for (; start != finish; ++start) {
+                               toclevel = start->layout()->toclevel;
+                               if (toclevel == Layout::NOT_IN_TOC)
+                                       continue;
+                               for (size_t i = 0; i != tc.layoutCount(); ++i) {
+                                       LayoutPtr const & lt = tc.layout(i);
+                                       if (lt->toclevel == toclevel - 1 &&
+                                               start->layout()->labeltype == lt->labeltype) {
+                                                       start->setLayout(lt);
+                                                       break;
+                                       }
                                }
                        }
-                       break;
-               default:
-                       break;
+                       return;
+               }
        }
 }
 
@@ -387,7 +380,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
        BufferView * bv = &cur.bv();
        TextMetrics & tm = bv->textMetrics(this);
-       if (!tm.has(cur.pit()))
+       if (!tm.contains(cur.pit()))
                lyx::dispatch(FuncRequest(LFUN_SCREEN_RECENTER));
 
        // FIXME: We use the update flag to indicates wether a singlePar or a
@@ -861,7 +854,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        */
                        if (cur.selection())
                                cutSelection(cur, true, false);
-                       insertInset(cur, inset);
+                       cur.insert(inset);
                        cur.posForward();
                }
                break;
@@ -942,7 +935,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        pasteFromStack(cur, bv->buffer().errorList("Paste"),
                                       convert<unsigned int>(arg));
                } else {
-                       Clipboard::GraphicsType type;
+                       Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
                        if (arg == "pdf")
                                type = Clipboard::PdfGraphicsType;
                        else if (arg == "png")
@@ -1011,7 +1004,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
                Paragraph const & para = cur.paragraph();
                docstring const old_layout = para.layout()->name();
-               TextClass const & tclass = bv->buffer().params().textClass();
+               DocumentClass const & tclass = bv->buffer().params().documentClass();
 
                if (layout.empty())
                        layout = tclass.defaultLayoutName();
@@ -1342,7 +1335,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        }
 #if 0
        case LFUN_LIST_INSERT:
-       case LFUN_THEOREM_INSERT:
 #endif
        case LFUN_CAPTION_INSERT:
        case LFUN_FOOTNOTE_INSERT:
@@ -1384,7 +1376,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                cur.posForward();
                ParagraphList & pars = cur.text()->paragraphs();
 
-               TextClass const & tclass = bv->buffer().params().textClass();
+               DocumentClass const & tclass = bv->buffer().params().documentClass();
 
                // add a separate paragraph for the caption inset
                pars.push_back(Paragraph());
@@ -1675,7 +1667,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_FLOAT_LIST: {
-               TextClass const & tclass = bv->buffer().params().textClass();
+               DocumentClass const & tclass = bv->buffer().params().documentClass();
                if (tclass.floats().typeExist(to_utf8(cmd.argument()))) {
                        cur.recordUndo();
                        if (cur.selection())
@@ -1933,9 +1925,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_LIST_INSERT:
                code = LIST_CODE;
                break;
-       case LFUN_THEOREM_INSERT:
-               code = THEOREM_CODE;
-               break;
 #endif
        case LFUN_CAPTION_INSERT:
                code = CAPTION_CODE;
@@ -1946,7 +1935,8 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_FLEX_INSERT: {
                code = FLEX_CODE;
                string s = cmd.getArg(0);
-               InsetLayout il =  cur.buffer().params().textClass().insetLayout(from_utf8(s));
+               InsetLayout il = 
+                       cur.buffer().params().documentClass().insetLayout(from_utf8(s));
                if (il.lyxtype() != "charstyle" &&
                    il.lyxtype() != "custom" &&
                    il.lyxtype() != "element" &&