]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetIndex.cpp
#7379 avoid the wrap spell check question when buffer is empty
[lyx.git] / src / insets / InsetIndex.cpp
index 603c865f7877507affad7a347e62e3334fa4bfc9..fe50bf4fea7ccd5b050cbfe7fb2991a8e045c2e7 100644 (file)
@@ -57,8 +57,7 @@ InsetIndex::InsetIndex(Buffer * buf, InsetIndexParams const & params)
 {}
 
 
-int InsetIndex::latex(odocstream & os,
-                     OutputParams const & runparams_in) const
+void InsetIndex::latex(otexstream & os, OutputParams const & runparams_in) const
 {
        OutputParams runparams(runparams_in);
        runparams.inIndexEntry = true;
@@ -72,11 +71,12 @@ int InsetIndex::latex(odocstream & os,
                os << "\\index";
                os << '{';
        }
-       int i = 0;
 
        // get contents of InsetText as LaTeX and plaintext
+       TexRow texrow;
        odocstringstream ourlatex;
-       InsetText::latex(ourlatex, runparams);
+       otexstream ots(ourlatex, texrow);
+       InsetText::latex(ots, runparams);
        odocstringstream ourplain;
        InsetText::plaintext(ourplain, runparams);
        docstring latexstr = ourlatex.str();
@@ -155,21 +155,17 @@ int InsetIndex::latex(odocstream & os,
                                subst(spart2, from_ascii("\\"), docstring());
                        os << ppart;
                        os << '@';
-                       i += count_char(ppart, '\n');
                }
                docstring const tpart = *it;
                os << tpart;
-               i += count_char(tpart, '\n');
                if (it2 < levels_plain.end())
                        ++it2;
        }
        // write the bit that followed "|"
        if (!cmd.empty()) {
                os << "|" << cmd;
-               i += count_char(cmd, '\n');
        }
        os << '}';
-       return i;
 }
 
 
@@ -207,11 +203,13 @@ void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_INSET_MODIFY: {
                if (cmd.getArg(0) == "changetype") {
+                       cur.recordUndoInset(ATOMIC_UNDO, this);
                        params_.index = from_utf8(cmd.getArg(1));
                        break;
                }
                InsetIndexParams params;
                InsetIndex::string2params(to_utf8(cmd.argument()), params);
+               cur.recordUndoInset(ATOMIC_UNDO, this);
                params_.index = params.index;
                // what we really want here is a TOC update, but that means
                // a full buffer update
@@ -354,12 +352,13 @@ void InsetIndex::string2params(string const & in, InsetIndexParams & params)
 }
 
 
-void InsetIndex::addToToc(DocIterator const & cpit)
+void InsetIndex::addToToc(DocIterator const & cpit) const
 {
        DocIterator pit = cpit;
-       pit.push_back(CursorSlice(*this));
-       docstring const item = text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS);
-       buffer().tocBackend().toc("index").push_back(TocItem(pit, 0, item));
+       pit.push_back(CursorSlice(const_cast<InsetIndex &>(*this)));
+       docstring str;
+       text().forToc(str, TOC_ENTRY_LENGTH);
+       buffer().tocBackend().toc("index").push_back(TocItem(pit, 0, str));
        // Proceed with the rest of the inset.
        InsetCollapsable::addToToc(cpit);
 }
@@ -375,7 +374,7 @@ void InsetIndex::validate(LaTeXFeatures & features) const
 }
 
 
-docstring InsetIndex::contextMenu(BufferView const &, int, int) const
+docstring InsetIndex::contextMenuName() const
 {
        return from_ascii("context-index");
 }
@@ -478,6 +477,7 @@ void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
                                cmd = subst(cmd, "printindex", "printsubindex");
                        else
                                cmd = subst(cmd, "printsubindex", "printindex");
+                       cur.recordUndo();
                        setCmdName(cmd);
                        break;
                } else if (cmd.argument() == from_ascii("check-printindex*")) {
@@ -485,6 +485,7 @@ void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
                        if (suffixIs(cmd, '*'))
                                break;
                        cmd += '*';
+                       cur.recordUndo();
                        setParam("type", docstring());
                        setCmdName(cmd);
                        break;
@@ -552,16 +553,15 @@ bool InsetPrintIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-int InsetPrintIndex::latex(odocstream & os, OutputParams const & runparams_in) const
+void InsetPrintIndex::latex(otexstream & os, OutputParams const & runparams_in) const
 {
        if (!buffer().masterBuffer()->params().use_indices) {
                if (getParam("type") == from_ascii("idx"))
                        os << "\\printindex{}";
-               return 0;
+               return;
        }
        OutputParams runparams = runparams_in;
        os << getCommand(runparams);
-       return 0;
 }
 
 
@@ -573,7 +573,7 @@ void InsetPrintIndex::validate(LaTeXFeatures & features) const
 }
 
 
-docstring InsetPrintIndex::contextMenu(BufferView const &, int, int) const
+docstring InsetPrintIndex::contextMenuName() const
 {
        return buffer().masterBuffer()->params().use_indices ?
                from_ascii("context-indexprint") : docstring();