]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
This is the first of a series of commits that will make InsetLayout a real class.
[lyx.git] / src / Text3.cpp
index 191c291ce51f1a84e3b5f70aba390ca3aa93d8d3..99ec81105b7b7be07f468a6054971d1e71814dd9 100644 (file)
@@ -182,12 +182,14 @@ static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
 static bool doInsertInset(Cursor & cur, Text * text,
        FuncRequest const & cmd, bool edit, bool pastesel)
 {
-       Inset * inset = createInset(cur.bv().buffer(), cmd);
+       Buffer & buffer = cur.bv().buffer();
+       BufferParams const & bparams = buffer.params();
+       Inset * inset = createInset(buffer, cmd);
        if (!inset)
                return false;
 
        if (InsetCollapsable * ci = inset->asInsetCollapsable())
-               ci->setLayout(cur.bv().buffer().params());
+               ci->setLayout(bparams);
 
        cur.recordUndo();
        if (cmd.action == LFUN_INDEX_INSERT) {
@@ -216,23 +218,21 @@ static bool doInsertInset(Cursor & cur, Text * text,
        lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
        InsetText * insetText = dynamic_cast<InsetText *>(inset);
        if (insetText && !insetText->allowMultiPar() || cur.lastpit() == 0) {
-                       // reset first par to default
-                       LayoutPtr const layout = insetText->useEmptyLayout() ?
-                               cur.buffer().params().getTextClass().emptyLayout() :
-                               cur.buffer().params().getTextClass().defaultLayout();
-                       cur.text()->paragraphs().begin()->layout(layout);
-                       cur.pos() = 0;
-                       cur.pit() = 0;
-                       // Merge multiple paragraphs -- hack
-                       while (cur.lastpit() > 0) {
-                               mergeParagraph(cur.buffer().params(),
-                                       cur.text()->paragraphs(), 0);
-                       }
+               // reset first par to default
+               LayoutPtr const layout = insetText->useEmptyLayout()
+                       ? bparams.getTextClass().emptyLayout()
+                       : bparams.getTextClass().defaultLayout();
+               cur.text()->paragraphs().begin()->layout(layout);
+               cur.pos() = 0;
+               cur.pit() = 0;
+               // Merge multiple paragraphs -- hack
+               while (cur.lastpit() > 0)
+                       mergeParagraph(bparams, cur.text()->paragraphs(), 0);
        } else {
                // reset surrounding par to default
-               docstring const layoutname = insetText->useEmptyLayout() ?
-                               cur.buffer().params().getTextClass().emptyLayoutName() :
-                               cur.buffer().params().getTextClass().defaultLayoutName();
+               docstring const layoutname = insetText->useEmptyLayout()
+                       ? bparams.getTextClass().emptyLayoutName()
+                       : bparams.getTextClass().defaultLayoutName();
                cur.leaveInset(*inset);
                text->setLayout(cur, layoutname);
        }
@@ -374,7 +374,7 @@ void Text::number(Cursor & cur)
 {
        FontInfo font = ignore_font;
        font.setNumber(FONT_TOGGLE);
-       toggleAndShow(cur, this, Font(font));
+       toggleAndShow(cur, this, Font(font, ignore_language));
 }
 
 
@@ -1354,13 +1354,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 #endif
        case LFUN_CAPTION_INSERT:
        case LFUN_FOOTNOTE_INSERT:
-               // Open the inset, and move the current selection
-               // inside it.
-               doInsertInset(cur, this, cmd, true, true);
-               cur.posForward();
-               // These insets are numbered.
-               updateLabels(bv->buffer());
-               break;
        case LFUN_NOTE_INSERT:
        case LFUN_FLEX_INSERT:
        case LFUN_BOX_INSERT:
@@ -1371,10 +1364,14 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        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.
                doInsertInset(cur, this, cmd, true, true);
                cur.posForward();
+               // Some insets are numbered, others are shown in the outline pane so
+               // let's update the labels and the toc backend.
+               updateLabels(bv->buffer());
                break;
 
        case LFUN_TABULAR_INSERT:
@@ -1434,11 +1431,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                break;
        }
 
-       case LFUN_INDEX_INSERT:
-               doInsertInset(cur, this, cmd, true, true);
-               cur.posForward();
-               break;
-
        case LFUN_NOMENCL_INSERT: {
                FuncRequest cmd1 = cmd;
                if (cmd.argument().empty())
@@ -1975,10 +1967,10 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                code = FLEX_CODE;
                string s = cmd.getArg(0);
                InsetLayout il =  cur.buffer().params().getTextClass().insetlayout(from_utf8(s));
-               if (il.lyxtype != "charstyle" &&
-                   il.lyxtype != "custom" &&
-                   il.lyxtype != "element" &&
-                   il.lyxtype != "standard")
+               if (il.lyxtype() != "charstyle" &&
+                   il.lyxtype() != "custom" &&
+                   il.lyxtype() != "element" &&
+                   il.lyxtype ()!= "standard")
                        enable = false;
                break;
                }
@@ -2125,7 +2117,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                if (!cmd.argument().empty()) {
                        InsetLayout il = cur.inset().getLayout(cur.buffer().params());
                        enable = cur.inset().lyxCode() == FLEX_CODE
-                                && il.lyxtype == to_utf8(cmd.argument());
+                                && il.lyxtype() == to_utf8(cmd.argument());
                } else {
                        enable = !isMainText(cur.bv().buffer()) 
                                 && cur.inset().nargs() == 1;