]> git.lyx.org Git - features.git/blobdiff - src/Text3.cpp
Convenience LFUN to split an environment
[features.git] / src / Text3.cpp
index 9400526c84d3271d7e10aa5688eb857e002424ab..cdc1bd488bc4d0c45f7fe2ae55ccd534050f0b07 100644 (file)
@@ -295,6 +295,8 @@ static bool doInsertInset(Cursor & cur, Text * text,
                        // Merge multiple paragraphs -- hack
                        while (cur.lastpit() > 0)
                                mergeParagraph(bparams, cur.text()->paragraphs(), 0);
+                       if (cmd.action() == LFUN_FLEX_INSERT)
+                               return true;
                        Cursor old = cur;
                        cur.leaveInset(*inset);
                        if (cmd.action() == LFUN_PREVIEW_INSERT
@@ -1372,10 +1374,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                if (change_layout)
                        setLayout(cur, layout);
 
-               Layout::LaTeXArgMap args = tclass[layout].latexargs();
-               Layout::LaTeXArgMap itemargs = tclass[layout].itemargs();
-               if (!itemargs.empty())
-                       args.insert(itemargs.begin(), itemargs.end());
+               Layout::LaTeXArgMap args = tclass[layout].args();
                Layout::LaTeXArgMap::const_iterator lait = args.begin();
                Layout::LaTeXArgMap::const_iterator const laend = args.end();
                for (; lait != laend; ++lait) {
@@ -1389,6 +1388,28 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                break;
        }
 
+       case LFUN_ENVIRONMENT_SPLIT: {
+               Paragraph const & para = cur.paragraph();
+               docstring const layout = para.layout().name();
+               if (cur.pos() > 0) {
+                       FuncRequest cmd(LFUN_PARAGRAPH_BREAK);
+                       lyx::dispatch(cmd);
+               }
+               bool const morecont = cur.lastpos() > cur.pos();
+               FuncRequest cmd2(LFUN_LAYOUT, "Separator");
+               lyx::dispatch(cmd2);
+               FuncRequest cmd3(LFUN_PARAGRAPH_BREAK, "inverse");
+               lyx::dispatch(cmd3);
+               if (morecont) {
+                       FuncRequest cmd4(LFUN_DOWN);
+                       lyx::dispatch(cmd4);
+               }
+               FuncRequest cmd5(LFUN_LAYOUT, layout);
+               lyx::dispatch(cmd5);
+
+               break;
+       }
+
        case LFUN_CLIPBOARD_PASTE:
                cap::replaceSelection(cur);
                pasteClipboardText(cur, bv->buffer().errorList("Paste"),
@@ -1699,7 +1720,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_CAPTION_INSERT:
        case LFUN_FOOTNOTE_INSERT:
        case LFUN_NOTE_INSERT:
-       case LFUN_FLEX_INSERT:
        case LFUN_BOX_INSERT:
        case LFUN_BRANCH_INSERT:
        case LFUN_PHANTOM_INSERT:
@@ -1720,6 +1740,37 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                cur.forceBufferUpdate();
                break;
 
+       case LFUN_FLEX_INSERT: {
+               // Open the inset, and move the current selection
+               // inside it.
+               bool const sel = cur.selection();
+               doInsertInset(cur, this, cmd, true, true);
+               // Insert auto-insert arguments
+               bool autoargs = false;
+               Layout::LaTeXArgMap args = cur.inset().getLayout().latexargs();
+               Layout::LaTeXArgMap::const_iterator lait = args.begin();
+               Layout::LaTeXArgMap::const_iterator const laend = args.end();
+               for (; lait != laend; ++lait) {
+                       Layout::latexarg arg = (*lait).second;
+                       if (arg.autoinsert) {
+                               // The cursor might have been invalidated by the replaceSelection.
+                               cur.buffer()->changed(true);
+                               FuncRequest cmd(LFUN_ARGUMENT_INSERT, (*lait).first);
+                               lyx::dispatch(cmd);
+                               autoargs = true;
+                       }
+               }
+               if (!autoargs) {
+                       if (sel)
+                               cur.leaveInset(cur.inset());
+                       cur.posForward();
+               }
+               // Some insets are numbered, others are shown in the outline pane so
+               // let's update the labels and the toc backend.
+               cur.forceBufferUpdate();
+               break;
+       }
+
        case LFUN_TABULAR_INSERT:
                // if there were no arguments, just open the dialog
                if (doInsertInset(cur, this, cmd, false, true))
@@ -2539,10 +2590,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                        break;
                }
                Layout const & lay = cur.paragraph().layout();
-               Layout::LaTeXArgMap args = lay.latexargs();
-               Layout::LaTeXArgMap itemargs = lay.itemargs();
-               if (!itemargs.empty())
-                       args.insert(itemargs.begin(), itemargs.end());
+               Layout::LaTeXArgMap args = lay.args();
                Layout::LaTeXArgMap::const_iterator const lait =
                                args.find(arg);
                if (lait != args.end()) {
@@ -2837,7 +2885,17 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_LAYOUT:
                enable = !cur.inset().forcePlainLayout();
                break;
-               
+       
+       case LFUN_ENVIRONMENT_SPLIT: {
+               if (!cur.buffer()->params().documentClass().hasLayout(from_ascii("Separator"))
+                   || !cur.paragraph().layout().isEnvironment()) {
+                       enable = false;
+                       break;
+               }
+               enable = true;
+               break;
+       }
+
        case LFUN_LAYOUT_PARAGRAPH:
        case LFUN_PARAGRAPH_PARAMS:
        case LFUN_PARAGRAPH_PARAMS_APPLY: