]> git.lyx.org Git - lyx.git/blob - src/insets/InsetIndex.cpp
* src/InsetIndex: further corrections od LaTeX output.
[lyx.git] / src / insets / InsetIndex.cpp
1 /**
2  * \file InsetIndex.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10 #include <config.h>
11
12 #include "InsetIndex.h"
13
14 #include "Buffer.h"
15 #include "DispatchResult.h"
16 #include "FuncRequest.h"
17 #include "FuncStatus.h"
18 #include "LaTeXFeatures.h"
19 #include "MetricsInfo.h"
20 #include "sgml.h"
21 #include "TocBackend.h"
22
23 #include "support/docstream.h"
24 #include "support/gettext.h"
25 #include "support/lstrings.h"
26
27 #include <ostream>
28
29 using namespace std;
30 using namespace lyx::support;
31
32 namespace lyx {
33
34 /////////////////////////////////////////////////////////////////////
35 //
36 // InsetIndex
37 //
38 ///////////////////////////////////////////////////////////////////////
39
40
41 InsetIndex::InsetIndex(Buffer const & buf)
42         : InsetCollapsable(buf)
43 {}
44
45
46 int InsetIndex::latex(odocstream & os,
47                           OutputParams const & runparams) const
48 {
49         os << "\\index";
50         os << '{';
51         odocstringstream ods;
52         int i = InsetText::latex(ods, runparams);
53         bool sorted = false;
54         // correctly sort macros and formatted strings
55         // if we do find a command, prepend a plain text
56         // version of the content to get sorting right,
57         // e.g. \index{LyX@\LyX}, \index{text@\textbf{text}}
58         // Don't do that if the user entered '@' himself, though.
59         if (contains(ods.str(), '\\') && !contains(ods.str(), '@')) {
60                 odocstringstream odss;
61                 if (InsetText::plaintext(odss, runparams) > 0) {
62                         // remove remaining \'s for the sorting part
63                         os << subst(odss.str(), from_ascii("\\"), docstring());
64                         os << '@';
65                         sorted = true;
66                 }
67         }
68         // if a hierarchy tag '!' is used, ommit this in the post-@ part.
69         if (sorted && contains(ods.str(), '!')) {
70                 string dummy;
71                 // FIXME unicode
72                 os << from_utf8(rsplit(to_utf8(ods.str()), dummy, '!'));
73         } else
74                 i = InsetText::latex(os, runparams);
75         os << '}';
76         return i;
77 }
78
79
80 int InsetIndex::docbook(odocstream & os, OutputParams const & runparams) const
81 {
82         os << "<indexterm><primary>";
83         int const i = InsetText::docbook(os, runparams);
84         os << "</primary></indexterm>";
85         return i;
86 }
87
88
89 void InsetIndex::write(ostream & os) const
90 {
91         os << to_utf8(name()) << "\n";
92         InsetCollapsable::write(os);
93 }
94
95
96 void InsetIndex::addToToc(ParConstIterator const & cpit) const
97 {
98         ParConstIterator pit = cpit;
99         pit.push_back(*this);
100
101         Toc & toc = buffer().tocBackend().toc("index");
102         docstring str;
103         str = getNewLabel(str);
104         toc.push_back(TocItem(pit, 0, str));
105 }
106
107
108 /////////////////////////////////////////////////////////////////////
109 //
110 // InsetPrintIndex
111 //
112 ///////////////////////////////////////////////////////////////////////
113
114 InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
115         : InsetCommand(p, string())
116 {}
117
118
119 ParamInfo const & InsetPrintIndex::findInfo(string const & /* cmdName */)
120 {
121         static ParamInfo param_info_;
122         if (param_info_.empty())
123                 param_info_.add("name", ParamInfo::LATEX_REQUIRED);
124         return param_info_;
125 }
126
127
128 docstring InsetPrintIndex::screenLabel() const
129 {
130         return _("Index");
131 }
132
133
134 void InsetPrintIndex::validate(LaTeXFeatures & features) const
135 {
136         features.require("makeidx");
137 }
138
139
140 InsetCode InsetPrintIndex::lyxCode() const
141 {
142         return INDEX_PRINT_CODE;
143 }
144
145 } // namespace lyx