]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
* GuiToolbar.cpp:
[lyx.git] / src / Text3.cpp
index 1e5ec37f817c40037eb390d93589e8d3435622ad..3671170eaf1007af8930085bed4db8dd1d1e64d0 100644 (file)
@@ -208,7 +208,8 @@ static bool doInsertInset(Cursor & cur, Text * text,
 
        bool gotsel = false;
        if (cur.selection()) {
-               lyx::dispatch(FuncRequest(LFUN_CUT));
+               cutSelection(cur, false, pastesel);
+               cur.clearSelection();
                gotsel = true;
        }
        text->insertInset(cur, inset);
@@ -219,23 +220,27 @@ static bool doInsertInset(Cursor & cur, Text * text,
        if (!gotsel || !pastesel)
                return true;
 
-       lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
+       pasteFromStack(cur, cur.buffer().errorList("Paste"), 0);
+       cur.buffer().errors("Paste");
+       cur.clearSelection(); // bug 393
+       cur.finishUndo();
        InsetText * insetText = dynamic_cast<InsetText *>(inset);
        if (insetText && !insetText->allowMultiPar() || cur.lastpit() == 0) {
                // reset first par to default
                cur.text()->paragraphs().begin()
-                       ->setEmptyOrDefaultLayout(bparams.documentClass());
+                       ->setPlainOrDefaultLayout(bparams.documentClass());
                cur.pos() = 0;
                cur.pit() = 0;
                // Merge multiple paragraphs -- hack
                while (cur.lastpit() > 0)
                        mergeParagraph(bparams, cur.text()->paragraphs(), 0);
+               cur.leaveInset(*inset);
        } else {
+               cur.leaveInset(*inset);
                // reset surrounding par to default
-               docstring const layoutname = insetText->useEmptyLayout()
+               docstring const layoutname = insetText->usePlainLayout()
                        ? bparams.documentClass().emptyLayoutName()
                        : bparams.documentClass().defaultLayoutName();
-               cur.leaveInset(*inset);
                text->setLayout(cur, layoutname);
        }
 
@@ -1007,10 +1012,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                if (layout.empty())
                        layout = tclass.defaultLayoutName();
 
-               if (para.forceEmptyLayout()) 
+               if (para.forcePlainLayout()) 
                        // in this case only the empty layout is allowed
                        layout = tclass.emptyLayoutName();
-               else if (para.useEmptyLayout()) {
+               else if (para.usePlainLayout()) {
                        // in this case, default layout maps to empty layout 
                        if (layout == tclass.defaultLayoutName())
                                layout = tclass.emptyLayoutName();
@@ -1338,18 +1343,18 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        }
 
        case LFUN_INFO_INSERT: {
-               Inset * inset = createInset(cur.bv().buffer(), cmd);
-               if (!inset)
-                       break;
-               // if an empty inset is created (cmd.argument() is empty)
-               // use current selection as parameter.
+               Inset * inset;
                if (cmd.argument().empty() && cur.selection()) {
-                       // use selected text as info to avoid a separate UI
+                       // if command argument is empty use current selection as parameter.
                        docstring ds = cur.selectionAsString(false);
                        cutSelection(cur, true, false);
-                       static_cast<InsetInfo *>(inset)->setInfo(to_utf8(ds));
-                       static_cast<InsetInfo *>(inset)->updateInfo();
+                       FuncRequest cmd0(cmd, ds);
+                       inset = createInset(cur.bv().buffer(), cmd0);
+               } else {
+                       inset = createInset(cur.bv().buffer(), cmd);
                }
+               if (!inset)
+                       break;
                insertInset(cur, inset);
                cur.posForward();
                break;
@@ -1360,12 +1365,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_FLEX_INSERT:
        case LFUN_BOX_INSERT:
        case LFUN_BRANCH_INSERT:
-       case LFUN_BIBITEM_INSERT:
        case LFUN_ERT_INSERT:
        case LFUN_LISTING_INSERT:
        case LFUN_MARGINALNOTE_INSERT:
        case LFUN_OPTIONAL_INSERT:
-       case LFUN_ENVIRONMENT_INSERT:
        case LFUN_INDEX_INSERT:
                // Open the inset, and move the current selection
                // inside it.
@@ -1399,7 +1402,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                // add a separate paragraph for the caption inset
                pars.push_back(Paragraph());
                pars.back().setInsetOwner(pars[0].inInset());
-               pars.back().setEmptyOrDefaultLayout(tclass);
+               pars.back().setPlainOrDefaultLayout(tclass);
                int cap_pit = pars.size() - 1;
 
                // if an empty inset was created, we create an additional empty
@@ -1408,7 +1411,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                if (!content) {
                        pars.push_back(Paragraph());
                        pars.back().setInsetOwner(pars[0].inInset());
-                       pars.back().setEmptyOrDefaultLayout(tclass);
+                       pars.back().setPlainOrDefaultLayout(tclass);
                }
 
                // reposition the cursor to the caption
@@ -1467,7 +1470,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                mathDispatch(cur, cmd, true);
                break;
 
-       case LFUN_MATH_IMPORT_SELECTION:
        case LFUN_MATH_MODE:
                if (cmd.argument() == "on")
                        // don't pass "on" as argument
@@ -1583,14 +1585,14 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                break;
        }
 
-       case LFUN_FONT_FREE_APPLY:
+       case LFUN_TEXTSTYLE_APPLY:
                toggleAndShow(cur, this, freefont, toggleall);
                cur.message(_("Character set"));
                break;
 
        // Set the freefont using the contents of \param data dispatched from
        // the frontends and apply it at the current cursor location.
-       case LFUN_FONT_FREE_UPDATE: {
+       case LFUN_TEXTSTYLE_UPDATE: {
                Font font;
                bool toggle;
                if (font.fromString(to_utf8(cmd.argument()), toggle)) {
@@ -1692,7 +1694,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                breakParagraph(cur);
                        }
 
-                       docstring const laystr = cur.inset().useEmptyLayout() ?
+                       docstring const laystr = cur.inset().usePlainLayout() ?
                                tclass.emptyLayoutName() :
                                tclass.defaultLayoutName();
                        setLayout(cur, laystr);
@@ -1867,11 +1869,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                flag.setOnOff(cur.paragraph().params().startOfAppendix());
                break;
 
-       case LFUN_BIBITEM_INSERT:
-               enable = (cur.paragraph().layout().labeltype == LABEL_BIBLIO
-                         && cur.pos() == 0);
-               break;
-
        case LFUN_DIALOG_SHOW_NEW_INSET:
                if (cmd.argument() == "bibitem")
                        code = BIBITEM_CODE;
@@ -1982,9 +1979,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                enable = cur.paragraph().insetList().count(OPTARG_CODE)
                        < cur.paragraph().layout().optionalargs;
                break;
-       case LFUN_ENVIRONMENT_INSERT:
-               code = BOX_CODE;
-               break;
        case LFUN_INDEX_INSERT:
                code = INDEX_CODE;
                break;
@@ -2127,7 +2121,9 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_OUTLINE_DOWN:
        case LFUN_OUTLINE_IN:
        case LFUN_OUTLINE_OUT:
-               enable = (cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC);
+               // FIXME: LyX is not ready for outlining within inset.
+               enable = isMainText(cur.bv().buffer())
+                       && cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC;
                break;
 
        case LFUN_NEWLINE_INSERT:
@@ -2194,7 +2190,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_LINE_INSERT:
        case LFUN_NEWPAGE_INSERT:
        case LFUN_MATH_DISPLAY:
-       case LFUN_MATH_IMPORT_SELECTION:
        case LFUN_MATH_MODE:
        case LFUN_MATH_MACRO:
        case LFUN_MATH_MATRIX:
@@ -2207,8 +2202,8 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_FONT_UNDERLINE:
        case LFUN_FONT_SIZE:
        case LFUN_LANGUAGE:
-       case LFUN_FONT_FREE_APPLY:
-       case LFUN_FONT_FREE_UPDATE:
+       case LFUN_TEXTSTYLE_APPLY:
+       case LFUN_TEXTSTYLE_UPDATE:
        case LFUN_LAYOUT_PARAGRAPH:
        case LFUN_PARAGRAPH_UPDATE:
        case LFUN_ACCENT_UMLAUT: