3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
12 #include "InsetIndex.h"
15 #include "DispatchResult.h"
16 #include "FuncRequest.h"
17 #include "FuncStatus.h"
18 #include "LaTeXFeatures.h"
19 #include "MetricsInfo.h"
21 #include "TocBackend.h"
23 #include "support/docstream.h"
24 #include "support/gettext.h"
25 #include "support/lstrings.h"
30 using namespace lyx::support;
34 /////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////
41 InsetIndex::InsetIndex(Buffer const & buf)
42 : InsetCollapsable(buf)
46 int InsetIndex::latex(odocstream & os,
47 OutputParams const & runparams) const
53 InsetText::latex(ods, runparams);
54 odocstringstream ods2;
55 InsetText::plaintext(ods2, runparams);
56 std::vector<docstring> const levels =
57 getVectorFromString(ods.str(), from_ascii("!"), true);
58 std::vector<docstring> const levels_plain =
59 getVectorFromString(ods2.str(), from_ascii("!"), true);
60 vector<docstring>::const_iterator it = levels.begin();
61 vector<docstring>::const_iterator end = levels.end();
62 vector<docstring>::const_iterator it2 = levels_plain.begin();
63 for (; it != end; ++it) {
64 if (it > levels.begin()) {
68 // correctly sort macros and formatted strings
69 // if we do find a command, prepend a plain text
70 // version of the content to get sorting right,
71 // e.g. \index{LyX@\LyX}, \index{text@\textbf{text}}
72 // Don't do that if the user entered '@' himself, though.
73 if (contains(*it, '\\') && !contains(*it, '@')) {
74 // Plaintext might return nothing (e.g. for ERTs)
76 (it2 < levels_plain.end()
77 && !(*it2).empty()) ? *it2 : *it;
78 // remove remaining \'s for the sorting part
79 docstring const ppart =
80 subst(spart, from_ascii("\\"), docstring());
83 i += ppart.size() + 1;
85 docstring const tpart = *it;
88 if (it2 < levels_plain.end())
97 int InsetIndex::docbook(odocstream & os, OutputParams const & runparams) const
99 os << "<indexterm><primary>";
100 int const i = InsetText::docbook(os, runparams);
101 os << "</primary></indexterm>";
106 void InsetIndex::write(ostream & os) const
108 os << to_utf8(name()) << "\n";
109 InsetCollapsable::write(os);
113 void InsetIndex::addToToc(DocIterator const & cpit)
115 DocIterator pit = cpit;
116 pit.push_back(CursorSlice(*this));
118 Toc & toc = buffer().tocBackend().toc("index");
120 str = getNewLabel(str);
121 toc.push_back(TocItem(pit, 0, str));
122 // Proceed with the rest of the inset.
123 InsetCollapsable::addToToc(cpit);
127 /////////////////////////////////////////////////////////////////////
131 ///////////////////////////////////////////////////////////////////////
133 InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
134 : InsetCommand(p, string())
138 ParamInfo const & InsetPrintIndex::findInfo(string const & /* cmdName */)
140 static ParamInfo param_info_;
141 if (param_info_.empty())
142 param_info_.add("name", ParamInfo::LATEX_REQUIRED);
147 docstring InsetPrintIndex::screenLabel() const
153 void InsetPrintIndex::validate(LaTeXFeatures & features) const
155 features.require("makeidx");
159 InsetCode InsetPrintIndex::lyxCode() const
161 return INDEX_PRINT_CODE;