]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetIndex.cpp
InsetTabular.cpp: fix #6585 also for wrapped floats - thanks Vincent
[lyx.git] / src / insets / InsetIndex.cpp
index 8f4b3d99e4da7ccde957d650ad7c3d531c0f9db3..233495bea137aa484929782e24f13f1a4aa589af 100644 (file)
@@ -23,7 +23,6 @@
 #include "IndicesList.h"
 #include "LaTeXFeatures.h"
 #include "Lexer.h"
-#include "MetricsInfo.h"
 #include "output_latex.h"
 #include "output_xhtml.h"
 #include "sgml.h"
@@ -37,6 +36,7 @@
 #include "frontends/alert.h"
 
 #include <ostream>
+#include <algorithm>
 
 using namespace std;
 using namespace lyx::support;
@@ -153,15 +153,19 @@ 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())
+       if (!cmd.empty()) {
                os << "|" << cmd;
+               i += count_char(cmd, '\n');
+       }
        os << '}';
        return i;
 }
@@ -182,7 +186,7 @@ docstring InsetIndex::xhtml(XHTMLStream & xs, OutputParams const &) const
        // our own interior paragraph, which doesn't get printed
        std::string const magic = paragraphs().front().magicLabel();
        std::string const attr = "id='" + magic + "'";
-       xs << CompTag("a", attr);
+       xs << html::CompTag("a", attr);
        return docstring();
 }
 
@@ -197,7 +201,7 @@ bool InsetIndex::showInsetDialog(BufferView * bv) const
 
 void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY: {
                if (cmd.getArg(0) == "changetype") {
@@ -207,6 +211,9 @@ void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
                InsetIndexParams params;
                InsetIndex::string2params(to_utf8(cmd.argument()), params);
                params_.index = params.index;
+               // what we really want here is a TOC update, but that means
+               // a full buffer update
+               cur.forceBufferUpdate();
                break;
        }
 
@@ -224,7 +231,7 @@ void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
 bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
                FuncStatus & flag) const
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY:
                if (cmd.getArg(0) == "changetype") {
@@ -366,6 +373,7 @@ void InsetIndex::validate(LaTeXFeatures & features) const
            && !params_.index.empty()
            && params_.index != "idx")
                features.require("splitidx");
+       InsetCollapsable::validate(features);
 }
 
 
@@ -417,7 +425,7 @@ void InsetIndexParams::read(Lexer & lex)
 ///////////////////////////////////////////////////////////////////////
 
 InsetPrintIndex::InsetPrintIndex(Buffer * buf, InsetCommandParams const & p)
-       : InsetCommand(buf, p, "index_print")
+       : InsetCommand(buf, p)
 {}
 
 
@@ -463,7 +471,7 @@ bool InsetPrintIndex::isCompatibleCommand(string const & s)
 
 void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY: {
                if (cmd.argument() == from_ascii("toggle-subindex")) {
@@ -485,10 +493,9 @@ void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
                }
                InsetCommandParams p(INDEX_PRINT_CODE);
                // FIXME UNICODE
-               InsetCommand::string2params("index_print",
-                       to_utf8(cmd.argument()), p);
+               InsetCommand::string2params(to_utf8(cmd.argument()), p);
                if (p.getCmdName().empty()) {
-                       cur.noUpdate();
+                       cur.noScreenUpdate();
                        break;
                }
                setParams(p);
@@ -505,7 +512,7 @@ void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
 bool InsetPrintIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
        FuncStatus & status) const
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY: {
                if (cmd.argument() == from_ascii("toggle-subindex")) {
@@ -519,8 +526,7 @@ bool InsetPrintIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
                } if (cmd.getArg(0) == "index_print"
                    && cmd.getArg(1) == "CommandInset") {
                        InsetCommandParams p(INDEX_PRINT_CODE);
-                       InsetCommand::string2params("index_print",
-                               to_utf8(cmd.argument()), p);
+                       InsetCommand::string2params(to_utf8(cmd.argument()), p);
                        if (suffixIs(p.getCmdName(), '*')) {
                                status.setEnabled(true);
                                status.setOnOff(false);
@@ -548,14 +554,15 @@ bool InsetPrintIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-int InsetPrintIndex::latex(odocstream & os, OutputParams const &) const
+int InsetPrintIndex::latex(odocstream & os, OutputParams const & runparams_in) const
 {
        if (!buffer().masterBuffer()->params().use_indices) {
                if (getParam("type") == from_ascii("idx"))
                        os << "\\printindex{}";
                return 0;
        }
-       os << getCommand();
+       OutputParams runparams = runparams_in;
+       os << getCommand(runparams);
        return 0;
 }
 
@@ -701,11 +708,11 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
        odocstringstream ods;
        XHTMLStream xs(ods);
 
-       xs << StartTag("div", "class='index'");
-       xs << StartTag(lay.htmltag(), lay.htmlattr()) 
+       xs << html::StartTag("div", "class='index'");
+       xs << html::StartTag(lay.htmltag(), lay.htmlattr()) 
                 << _("Index") 
-                << EndTag(lay.htmltag());
-       xs << StartTag("ul", "class='main'");
+                << html::EndTag(lay.htmltag());
+       xs << html::StartTag("ul", "class='main'");
        Font const dummy;
 
        vector<IndexEntry>::const_iterator eit = entries.begin();
@@ -725,12 +732,12 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
                                // close last entry or entries, depending.
                                if (level == 3) {
                                        // close this sub-sub-entry
-                                       xs << EndTag("li");
+                                       xs << html::EndTag("li");
                                        xs.cr();
                                        // is this another sub-sub-entry within the same sub-entry?
                                        if (!eit->same_sub(last)) {
                                                // close this level
-                                               xs << EndTag("ul");
+                                               xs << html::EndTag("ul");
                                                xs.cr();
                                                level = 2;
                                        }
@@ -742,12 +749,12 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
                                // sub-entry. In that case, we do not want to close anything.
                                if (level == 2 && !eit->same_sub(last)) {
                                        // close sub-entry 
-                                       xs << EndTag("li");
+                                       xs << html::EndTag("li");
                                        xs.cr();
                                        // is this another sub-entry with the same main entry?
                                        if (!eit->same_main(last)) {
                                                // close this level
-                                               xs << EndTag("ul");
+                                               xs << html::EndTag("ul");
                                                xs.cr();
                                                level = 1;
                                        }
@@ -757,7 +764,7 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
                                // close the entry.
                                if (level == 1 && !eit->same_main(last)) {
                                        // close entry
-                                       xs << EndTag("li");
+                                       xs << html::EndTag("li");
                                        xs.cr();
                                }
                        }
@@ -786,7 +793,7 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
        
                        if (level == 3) {
                                // another subsubentry
-                               xs << StartTag("li", "class='subsubentry'") 
+                               xs << html::StartTag("li", "class='subsubentry'") 
                                   << XHTMLStream::NextRaw() << subsub;
                        } else if (level == 2) {
                                // there are two ways we can be here: 
@@ -800,13 +807,13 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
                                // note that in this case, too, though, the sub-entry might already
                                // have a sub-sub-entry.
                                if (eit->sub != last.sub)
-                                       xs << StartTag("li", "class='subentry'") 
+                                       xs << html::StartTag("li", "class='subentry'") 
                                           << XHTMLStream::NextRaw() << sub;
                                if (!subsub.empty()) {
                                        // it's actually a subsubentry, so we need to start that list
                                        xs.cr();
-                                       xs << StartTag("ul", "class='subsubentry'") 
-                                          << StartTag("li", "class='subsubentry'") 
+                                       xs << html::StartTag("ul", "class='subsubentry'") 
+                                          << html::StartTag("li", "class='subsubentry'") 
                                           << XHTMLStream::NextRaw() << subsub;
                                        level = 3;
                                } 
@@ -822,19 +829,19 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
                                // note that in this case, too, though, the main entry might already
                                // have a sub-entry, or even a sub-sub-entry.
                                if (eit->main != last.main)
-                                       xs << StartTag("li", "class='main'") << main;
+                                       xs << html::StartTag("li", "class='main'") << main;
                                if (!sub.empty()) {
                                        // there's a sub-entry, too
                                        xs.cr();
-                                       xs << StartTag("ul", "class='subentry'") 
-                                          << StartTag("li", "class='subentry'") 
+                                       xs << html::StartTag("ul", "class='subentry'") 
+                                          << html::StartTag("li", "class='subentry'") 
                                           << XHTMLStream::NextRaw() << sub;
                                        level = 2;
                                        if (!subsub.empty()) {
                                                // and a sub-sub-entry
                                                xs.cr();
-                                               xs << StartTag("ul", "class='subsubentry'") 
-                                                  << StartTag("li", "class='subsubentry'") 
+                                               xs << html::StartTag("ul", "class='subsubentry'") 
+                                                  << html::StartTag("li", "class='subsubentry'") 
                                                   << XHTMLStream::NextRaw() << subsub;
                                                level = 3;
                                        }
@@ -844,17 +851,17 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
                // finally, then, we can output the index link itself
                string const parattr = "href='#" + par.magicLabel() + "'";
                xs << (entry_number == 0 ? ":" : ",");
-               xs << " " << StartTag("a", parattr)
-                  << ++entry_number << EndTag("a");
+               xs << " " << html::StartTag("a", parattr)
+                  << ++entry_number << html::EndTag("a");
                last = *eit;
        }
        // now we have to close all the open levels
        while (level > 0) {
-               xs << EndTag("li") << EndTag("ul");
+               xs << html::EndTag("li") << html::EndTag("ul");
                xs.cr();
                --level;
        }
-       xs << EndTag("div");
+       xs << html::EndTag("div");
        xs.cr();
        return ods.str();
 }