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("!"));
58 std::vector<docstring> const levels_plain =
59 getVectorFromString(ods2.str(), from_ascii("!"));
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 // remove remaining \'s for the sorting part
75 docstring const ppart =
76 subst(*it2, from_ascii("\\"), docstring());
79 i += ppart.size() + 1;
81 docstring const tpart = *it;
84 if (it2 < levels_plain.end())
93 int InsetIndex::docbook(odocstream & os, OutputParams const & runparams) const
95 os << "<indexterm><primary>";
96 int const i = InsetText::docbook(os, runparams);
97 os << "</primary></indexterm>";
102 void InsetIndex::write(ostream & os) const
104 os << to_utf8(name()) << "\n";
105 InsetCollapsable::write(os);
109 void InsetIndex::addToToc(DocIterator const & cpit)
111 DocIterator pit = cpit;
112 pit.push_back(CursorSlice(*this));
114 Toc & toc = buffer().tocBackend().toc("index");
116 str = getNewLabel(str);
117 toc.push_back(TocItem(pit, 0, str));
118 // Proceed with the rest of the inset.
119 InsetCollapsable::addToToc(cpit);
123 /////////////////////////////////////////////////////////////////////
127 ///////////////////////////////////////////////////////////////////////
129 InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
130 : InsetCommand(p, string())
134 ParamInfo const & InsetPrintIndex::findInfo(string const & /* cmdName */)
136 static ParamInfo param_info_;
137 if (param_info_.empty())
138 param_info_.add("name", ParamInfo::LATEX_REQUIRED);
143 docstring InsetPrintIndex::screenLabel() const
149 void InsetPrintIndex::validate(LaTeXFeatures & features) const
151 features.require("makeidx");
155 InsetCode InsetPrintIndex::lyxCode() const
157 return INDEX_PRINT_CODE;