]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
moveColumn now also swaps column_info
[lyx.git] / src / Text3.cpp
index 2893e080f92800e49360e3af0bf3b8078cacb8b3..1dead38685eacf92e009e88d1cd8f4fcc6a9cf0b 100644 (file)
@@ -148,7 +148,7 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
 #endif
                cur.insert(new InsetMathHull(cur.buffer(), hullSimple));
 #ifdef ENABLE_ASSERTIONS
-               LASSERT(old_pos == cur.pos(), /**/);
+               LATTEST(old_pos == cur.pos());
 #endif
                cur.nextInset()->edit(cur, true);
                // don't do that also for LFUN_MATH_MODE
@@ -488,7 +488,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        // at the end?
        cur.noScreenUpdate();
 
-       LASSERT(cur.text() == this, /**/);
+       LBUFERR(this == cur.text());
        CursorSlice const oldTopSlice = cur.top();
        bool const oldBoundary = cur.boundary();
        bool const oldSelection = cur.selection();
@@ -567,7 +567,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                finishChange(cur, false);
                break;
 
-       case LFUN_LINE_DELETE:
+       case LFUN_LINE_DELETE_FORWARD:
                if (cur.selection())
                        cutSelection(cur, true, false);
                else
@@ -648,12 +648,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                // provide it with two different cursors.
                                Cursor dummy = cur;
                                dummy.pos() = dummy.pit() = 0;
-                               if (cur.bv().checkDepm(dummy, cur)) {
+                               if (cur.bv().checkDepm(dummy, cur))
                                        cur.forceBufferUpdate();
-                                       // DEPM may have requested a screen update
-                                       cur.screenUpdateFlags(
-                                               cur.screenUpdate() | dummy.screenUpdate());
-                               }
                        }
                }
                break;
@@ -679,12 +675,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                Cursor dummy = cur;
                                dummy.pos() = cur.lastpos();
                                dummy.pit() = cur.lastpit();
-                               if (cur.bv().checkDepm(dummy, cur)) {
+                               if (cur.bv().checkDepm(dummy, cur))
                                        cur.forceBufferUpdate();
-                                       // DEPM may have requested a screen update
-                                       cur.screenUpdateFlags(
-                                               cur.screenUpdate() | dummy.screenUpdate());
-                               }
                        }
                }
                break;
@@ -867,12 +859,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                // provide it with two different cursors.
                                Cursor dummy = cur;
                                dummy.pos() = dummy.pit() = 0;
-                               if (cur.bv().checkDepm(dummy, cur)) {
+                               if (cur.bv().checkDepm(dummy, cur))
                                        cur.forceBufferUpdate();
-                                       // DEPM may have requested a screen update
-                                       cur.screenUpdateFlags(
-                                               cur.screenUpdate() | dummy.screenUpdate());
-                               }
                        }
                }
                break;
@@ -921,12 +909,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                Cursor dummy = cur;
                                dummy.pos() = cur.lastpos();
                                dummy.pit() = cur.lastpit();
-                               if (cur.bv().checkDepm(dummy, cur)) {
+                               if (cur.bv().checkDepm(dummy, cur))
                                        cur.forceBufferUpdate();
-                                       // DEPM may have requested a screen update
-                                       cur.screenUpdateFlags(
-                                               cur.screenUpdate() | dummy.screenUpdate());
-                               }
                        }
                }
                break;
@@ -1097,7 +1081,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        /*
                        Paragraph & par = pars_[cur.pit()];
                        if (inset->lyxCode() == LABEL_CODE
-                               && par.layout().labeltype == LABEL_COUNTER) {
+                               && !par.layout().counter.empty() {
                                // Go to the end of the paragraph
                                // Warning: Because of Change-Tracking, the last
                                // position is 'size()' and not 'size()-1':
@@ -1236,23 +1220,30 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_PASTE: {
                cur.message(_("Paste"));
-               LASSERT(cur.selBegin().idx() == cur.selEnd().idx(), /**/);
+               LASSERT(cur.selBegin().idx() == cur.selEnd().idx(), break);
                cap::replaceSelection(cur);
 
                // without argument?
                string const arg = to_utf8(cmd.argument());
                if (arg.empty()) {
+                       bool tryGraphics = true;
                        if (theClipboard().isInternal())
                                pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
-                       else if (theClipboard().hasGraphicsContents() 
-                                    && !theClipboard().hasTextContents())
+                       else if (theClipboard().hasTextContents()) {
+                               if (pasteClipboardText(cur, bv->buffer().errorList("Paste"),
+                                                      true, Clipboard::AnyTextType))
+                                       tryGraphics = false;
+                       }
+                       if (tryGraphics && theClipboard().hasGraphicsContents())
                                pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
-                       else
-                               pasteClipboardText(cur, bv->buffer().errorList("Paste"));
                } else if (isStrUnsignedInt(arg)) {
                        // we have a numerical argument
                        pasteFromStack(cur, bv->buffer().errorList("Paste"),
                                       convert<unsigned int>(arg));
+               } else if (arg == "html" || arg == "latex") {
+                       Clipboard::TextType type = (arg == "html") ?
+                               Clipboard::HtmlTextType : Clipboard::LaTeXTextType;
+                       pasteClipboardText(cur, bv->buffer().errorList("Paste"), true, type);
                } else {
                        Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
                        if (arg == "pdf")
@@ -1267,9 +1258,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                type = Clipboard::EmfGraphicsType;
                        else if (arg == "wmf")
                                type = Clipboard::WmfGraphicsType;
-
                        else
-                               LASSERT(false, /**/);
+                               // We used to assert, but couldn't the argument come from, say, the
+                               // minibuffer and just be mistyped?
+                               LYXERR0("Unrecognized graphics type: " << arg);
 
                        pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
                }
@@ -1386,10 +1378,32 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        }
 
        case LFUN_ENVIRONMENT_SPLIT: {
+               bool const outer = cmd.argument() == "outer";
                Paragraph const & para = cur.paragraph();
-               docstring const layout = para.layout().name();
+               docstring layout = para.layout().name();
+               depth_type split_depth = cur.paragraph().params().depth();
+               if (outer) {
+                       // check if we have an environment in our nesting hierarchy
+                       pit_type pit = cur.pit();
+                       Paragraph cpar = pars_[pit];
+                       while (true) {
+                               if (pit == 0 || cpar.params().depth() == 0)
+                                       break;
+                               --pit;
+                               cpar = pars_[pit];
+                               if (cpar.params().depth() < split_depth
+                                   && cpar.layout().isEnvironment()) {
+                                               layout = cpar.layout().name();
+                                               split_depth = cpar.params().depth();
+                               }
+                       }
+               }
                if (cur.pos() > 0)
                        lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK));
+               if (outer) {
+                       while (cur.paragraph().params().depth() > split_depth)
+                               lyx::dispatch(FuncRequest(LFUN_DEPTH_DECREMENT));
+               }
                bool const morecont = cur.lastpos() > cur.pos();
                lyx::dispatch(FuncRequest(LFUN_LAYOUT, "Separator"));
                lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
@@ -1653,7 +1667,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                break;
        }
 
-       case LFUN_HYPERLINK_INSERT: {
+       case LFUN_HREF_INSERT: {
                InsetCommandParams p(HYPERLINK_CODE);
                docstring content;
                if (cur.selection()) {
@@ -1921,7 +1935,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                cap::replaceSelection(cur);
                cur.insert(new InsetMathHull(cur.buffer(), hullSimple));
                checkAndActivateInset(cur, true);
-               LASSERT(cur.inMathed(), /**/);
+               LASSERT(cur.inMathed(), break);
                cur.dispatch(cmd);
                break;
        }
@@ -1989,14 +2003,14 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                break;
        }
 
-       case LFUN_FONT_UULINE: {
+       case LFUN_FONT_UNDERUNDERLINE: {
                Font font(ignore_font, ignore_language);
                font.fontInfo().setUuline(FONT_TOGGLE);
                toggleAndShow(cur, this, font);
                break;
        }
 
-       case LFUN_FONT_UWAVE: {
+       case LFUN_FONT_UNDERWAVE: {
                Font font(ignore_font, ignore_language);
                font.fontInfo().setUwave(FONT_TOGGLE);
                toggleAndShow(cur, this, font);
@@ -2372,7 +2386,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                        FuncStatus & flag) const
 {
-       LASSERT(cur.text() == this, /**/);
+       LBUFERR(this == cur.text());
 
        FontInfo const & fontinfo = cur.real_current_font.fontInfo();
        bool enable = true;
@@ -2527,13 +2541,12 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        }
        case LFUN_CAPTION_INSERT: {
                code = CAPTION_CODE;
-               bool varia = true;
+               string arg = cmd.getArg(0);
+               bool varia = arg != "LongTableNoNumber";
                if (cur.depth() > 0) {
-                       if (&cur[cur.depth() - 1].inset()
-                           && !cur[cur.depth() - 1].inset().allowsCaptionVariation())
-                               varia = false;
+                       if (&cur[cur.depth() - 1].inset())
+                               varia = cur[cur.depth() - 1].inset().allowsCaptionVariation(arg);
                }
-               string arg = cmd.getArg(0);
                // not allowed in description items,
                // and in specific insets
                enable = !inDescriptionItem(cur)
@@ -2654,7 +2667,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                // not allowed in description items
                enable = !inDescriptionItem(cur);
                break;
-       case LFUN_HYPERLINK_INSERT:
+       case LFUN_HREF_INSERT:
                if (cur.selIsMultiCell() || cur.selIsMultiLine()) {
                        enable = false;
                        break;
@@ -2773,6 +2786,20 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                        break;
                }
 
+               // explicit text type?
+               if (arg == "html") {
+                       // Do not enable for PlainTextType, since some tidying in the
+                       // frontend is needed for HTML, which is too unsafe for plain text.
+                       enable = theClipboard().hasTextContents(Clipboard::HtmlTextType);
+                       break;
+               } else if (arg == "latex") {
+                       // LaTeX is usually not available on the clipboard with
+                       // the correct MIME type, but in plain text.
+                       enable = theClipboard().hasTextContents(Clipboard::PlainTextType) ||
+                                theClipboard().hasTextContents(Clipboard::LaTeXTextType);
+                       break;
+               }
+
                // explicit graphics type?
                Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
                if ((arg == "pdf" && (type = Clipboard::PdfGraphicsType))
@@ -2887,8 +2914,28 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                break;
        
        case LFUN_ENVIRONMENT_SPLIT: {
-               if (cur.paragraph().layout().isEnvironment()
-                   && cur.buffer()->params().documentClass().hasLayout(from_ascii("Separator"))) {
+               if (!cur.buffer()->params().documentClass().hasLayout(from_ascii("Separator"))) {
+                       enable = false;
+                       break;
+               }
+               if (cmd.argument() == "outer") {
+                       // check if we have an environment in our nesting hierarchy
+                       bool res = false;
+                       depth_type const current_depth = cur.paragraph().params().depth();
+                       pit_type pit = cur.pit();
+                       Paragraph cpar = pars_[pit];
+                       while (true) {
+                               if (pit == 0 || cpar.params().depth() == 0)
+                                       break;
+                               --pit;
+                               cpar = pars_[pit];
+                               if (cpar.params().depth() < current_depth)
+                                       res = cpar.layout().isEnvironment();
+                       }
+                       enable = res;
+                       break;
+               }
+               else if (cur.paragraph().layout().isEnvironment()) {
                        enable = true;
                        break;
                }
@@ -2926,8 +2973,8 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_FONT_STATE:
        case LFUN_FONT_UNDERLINE:
        case LFUN_FONT_STRIKEOUT:
-       case LFUN_FONT_UULINE:
-       case LFUN_FONT_UWAVE:
+       case LFUN_FONT_UNDERUNDERLINE:
+       case LFUN_FONT_UNDERWAVE:
        case LFUN_TEXTSTYLE_APPLY:
        case LFUN_TEXTSTYLE_UPDATE:
                enable = !cur.paragraph().isPassThru();
@@ -2935,7 +2982,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
 
        case LFUN_WORD_DELETE_FORWARD:
        case LFUN_WORD_DELETE_BACKWARD:
-       case LFUN_LINE_DELETE:
+       case LFUN_LINE_DELETE_FORWARD:
        case LFUN_WORD_FORWARD:
        case LFUN_WORD_BACKWARD:
        case LFUN_WORD_RIGHT: