]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCaption.cpp
Added inset-select-all to emacs bindings
[lyx.git] / src / insets / InsetCaption.cpp
index 6891d6387ef87874946336a178255c86a9355513..8af9827b3ade32b94490b1641fbe4c67dbc6ab25 100644 (file)
@@ -31,6 +31,7 @@
 #include "output_xhtml.h"
 #include "OutputParams.h"
 #include "Paragraph.h"
+#include "ParIterator.h"
 #include "TextClass.h"
 #include "TextMetrics.h"
 #include "TocBackend.h"
@@ -88,12 +89,7 @@ void InsetCaption::cursorPos(BufferView const & bv,
 
 void InsetCaption::setCustomLabel(docstring const & label)
 {
-       if (!isAscii(label) || label.empty())
-               // This must be a user defined layout. We cannot translate
-               // this, since gettext accepts only ascii keys.
-               custom_label_ = label;
-       else
-               custom_label_ = _(to_ascii(label));
+       custom_label_ = translateIfPossible(label);
 }
 
 
@@ -107,7 +103,8 @@ void InsetCaption::addToToc(DocIterator const & cpit, bool output_active) const
 
        Toc & toc = buffer().tocBackend().toc(floattype_);
        docstring str = full_label_;
-       text().forToc(str, TOC_ENTRY_LENGTH);
+       int length = output_active ? INT_MAX : TOC_ENTRY_LENGTH;
+       text().forOutliner(str, length);
        toc.push_back(TocItem(pit, 0, str, output_active));
 
        // Proceed with the rest of the inset.
@@ -202,9 +199,7 @@ void InsetCaption::doDispatch(Cursor & cur, FuncRequest & cmd)
        switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY: {
-               string const first_arg = cmd.getArg(0);
-               bool const change_type = first_arg == "changetype";
-               if (change_type) {
+               if (cmd.getArg(0) == "changetype") {
                        cur.recordUndoInset(ATOMIC_UNDO, this);
                        type_ = cmd.getArg(1);
                        cur.forceBufferUpdate();
@@ -229,12 +224,10 @@ bool InsetCaption::getStatus(Cursor & cur, FuncRequest const & cmd,
                if (first_arg == "changetype") {
                        string const type = cmd.getArg(1);
                        status.setOnOff(type == type_);
-                       bool varia = true;
+                       bool varia = type != "LongTableNoNumber";
                        // check if the immediate parent inset allows caption variation
                        if (cur.depth() > 1) {
-                               if (&cur[cur.depth() - 2].inset()
-                                   && !cur[cur.depth() - 2].inset().allowsCaptionVariation())
-                                       varia = false;
+                               varia = cur[cur.depth() - 2].inset().allowsCaptionVariation(type);
                        }
                        status.setEnabled(varia
                                          && buffer().params().documentClass().hasInsetLayout(
@@ -271,10 +264,10 @@ void InsetCaption::latex(otexstream & os,
        // \caption{...}, later we will make it take advantage
        // of the one of the caption packages. (Lgb)
        OutputParams runparams = runparams_in;
-       // FIXME: actually, it is moving only when there is no
-       // optional argument.
-       runparams.moving_arg = !runparams.inTableCell;
        InsetText::latex(os, runparams);
+       // Backwards compatibility: We always had a linebreak after
+       // the caption (see #8514)
+       os << breakln;
        runparams_in.encoding = runparams.encoding;
 }
 
@@ -312,7 +305,9 @@ docstring InsetCaption::xhtml(XHTMLStream & xs, OutputParams const & rp) const
                string const our_class = "float-caption-" + type_;
                size_t const loc = attr.find("class='");
                if (loc != string::npos)
-                       attr.insert(loc + 1, our_class);
+                       attr.insert(loc + 7, our_class+ " ");
+               else
+                       attr = attr + " class='" + our_class + "'";
        }
        xs << html::StartTag(tag, attr);
        docstring def = getCaptionAsHTML(xs, rp);
@@ -351,8 +346,9 @@ int InsetCaption::getCaptionAsPlaintext(odocstream & os,
 {
        os << full_label_ << ' ';
        odocstringstream ods;
-       return InsetText::plaintext(ods, runparams);
+       int const retval = InsetText::plaintext(ods, runparams);
        os << ods.str();
+       return retval;
 }
 
 
@@ -398,14 +394,19 @@ void InsetCaption::updateBuffer(ParIterator const & it, UpdateType utype)
                                       master.B_(tclass.floats().getType(type).name()));
                }
                docstring sec;
+               docstring const lstring = getLayout().labelstring();
+               docstring const labelstring = isAscii(lstring) ?
+                               master.B_(to_ascii(lstring)) : lstring;
                if (cnts.hasCounter(counter)) {
-                       cnts.step(counter, utype);
+                       // for longtables, we step the counter upstream
+                       if (!cnts.isLongtable())
+                               cnts.step(counter, utype);
                        sec = cnts.theCounter(counter, lang);
                }
-               if (getLayout().labelstring() != master.B_("standard")) {
+               if (labelstring != master.B_("standard")) {
                        if (!sec.empty())
                                sec += from_ascii(" ");
-                       sec += bformat(from_ascii("(%1$s)"), getLayout().labelstring());
+                       sec += bformat(from_ascii("(%1$s)"), labelstring);
                }
                if (!sec.empty())
                        full_label_ = bformat(from_ascii("%1$s %2$s:"), name, sec);