]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
Fix scons and a file inclusion problem in ControlCommand.h
[lyx.git] / src / Text3.cpp
index d8607c4e36e63359ff17769463d7dd9f90a63fcf..960f19d1621f8e7b7205acead670481087a42c1a 100644 (file)
@@ -35,6 +35,7 @@
 #include "gettext.h"
 #include "Intl.h"
 #include "Language.h"
+#include "Layout.h"
 #include "LyXAction.h"
 #include "LyXFunc.h"
 #include "Lexer.h"
@@ -49,6 +50,7 @@
 #include "frontends/Clipboard.h"
 #include "frontends/Selection.h"
 
+#include "insets/InsetCollapsable.h"
 #include "insets/InsetCommand.h"
 #include "insets/InsetFloatList.h"
 #include "insets/InsetNewline.h"
@@ -85,10 +87,6 @@ using cap::replaceSelection;
 using support::isStrUnsignedInt;
 using support::token;
 
-namespace frontend {
-extern docstring current_layout;
-}
-
 // globals...
 static Font freefont(Font::ALL_IGNORE);
 static bool toggleall = false;
@@ -191,23 +189,32 @@ static bool doInsertInset(Cursor & cur, Text * text,
                return false;
 
        recordUndo(cur);
-       bool gotsel = false;
-       if (cur.selection()) {
-               lyx::dispatch(FuncRequest(LFUN_CUT));
-               gotsel = true;
-       }
-       text->insertInset(cur, inset);
-
-       if (edit)
-               inset->edit(cur, true);
-
-       if (gotsel && pastesel) {
-               lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
-               // reset first par to default
-               if (cur.lastpit() != 0 || cur.lastpos() != 0) {
-                       LayoutPtr const layout =
-                               cur.buffer().params().getTextClass().defaultLayout();
-                       cur.text()->paragraphs().begin()->layout(layout);
+       if (cmd.action == LFUN_INDEX_INSERT) {
+               docstring ds = support::subst(text->getStringToIndex(cur), '\n', ' ');
+               text->insertInset(cur, inset);
+               if (edit)
+                       inset->edit(cur, true);
+               // Now put this into inset
+               static_cast<InsetCollapsable *>(inset)->text_.insertStringAsParagraphs(cur, ds);
+       } else {
+               bool gotsel = false;
+               if (cur.selection()) {
+                       lyx::dispatch(FuncRequest(LFUN_CUT));
+                       gotsel = true;
+               }
+               text->insertInset(cur, inset);
+
+               if (edit)
+                       inset->edit(cur, true);
+
+               if (gotsel && pastesel) {
+                       lyx::dispatch(FuncRequest(LFUN_PASTE, "0"));
+                       // reset first par to default
+                       if (cur.lastpit() != 0 || cur.lastpos() != 0) {
+                               LayoutPtr const layout =
+                                       cur.buffer().params().getTextClass().defaultLayout();
+                               cur.text()->paragraphs().begin()->layout(layout);
+                       }
                }
        }
        return true;
@@ -771,6 +778,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                docstring layout = cmd.argument();
                LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
 
+               docstring const old_layout = cur.paragraph().layout()->name();
+
                // Derive layout number from given argument (string)
                // and current buffer's textclass (number)
                TextClass const & tclass = bv->buffer().params().getTextClass();
@@ -791,7 +800,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        break;
                }
 
-               bool change_layout = (frontend::current_layout != layout);
+               bool change_layout = (old_layout != layout);
 
                if (!change_layout && cur.selection() &&
                        cur.selBegin().pit() != cur.selEnd().pit())
@@ -799,7 +808,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        pit_type spit = cur.selBegin().pit();
                        pit_type epit = cur.selEnd().pit() + 1;
                        while (spit != epit) {
-                               if (pars_[spit].layout()->name() != frontend::current_layout) {
+                               if (pars_[spit].layout()->name() != old_layout) {
                                        change_layout = true;
                                        break;
                                }
@@ -807,11 +816,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        }
                }
 
-               if (change_layout) {
+               if (change_layout)
                        setLayout(cur, layout);
-                       // inform the GUI that the layout has changed.
-                       bv->layoutChanged(layout);
-               }
+
                break;
        }
 
@@ -1176,6 +1183,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        }
 
        case LFUN_INDEX_INSERT:
+               doInsertInset(cur, this, cmd, true, true);
+               cur.posRight();
+               break;
        case LFUN_NOMENCL_INSERT: {
                Inset * inset = createInset(&cur.bv(), cmd);
                if (!inset)