]> git.lyx.org Git - features.git/blob - src/insets/InsetIndex.cpp
some index fixes:
[features.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         InsetText::latex(ods, runparams);
53         // correctly sort macros and formatted strings
54         // if we do find a command, prepend a plain text
55         // version of the content to get sorting right,
56         // e.g. \index{LyX@\LyX}, \index{text@\textbf{text}}
57         // Don't do that if the user entered '@' himself, though.
58         if (contains(ods.str(), '\\') && !contains(ods.str(), '@')) {
59                 if (InsetText::plaintext(os, runparams) > 0)
60                         os << '@';
61         }
62         int i = InsetText::latex(os, runparams);
63         os << '}';
64         return i;
65 }
66
67
68 int InsetIndex::docbook(odocstream & os, OutputParams const & runparams) const
69 {
70         os << "<indexterm><primary>";
71         int const i = InsetText::docbook(os, runparams);
72         os << "</primary></indexterm>";
73         return i;
74 }
75
76
77 void InsetIndex::write(ostream & os) const
78 {
79         os << to_utf8(name()) << "\n";
80         InsetCollapsable::write(os);
81 }
82
83
84 void InsetIndex::addToToc(ParConstIterator const & cpit) const
85 {
86         ParConstIterator pit = cpit;
87         pit.push_back(*this);
88
89         Toc & toc = buffer().tocBackend().toc("index");
90         docstring str;
91         str = getNewLabel(str);
92         toc.push_back(TocItem(pit, 0, str));
93 }
94
95
96 /////////////////////////////////////////////////////////////////////
97 //
98 // InsetPrintIndex
99 //
100 ///////////////////////////////////////////////////////////////////////
101
102 InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
103         : InsetCommand(p, string())
104 {}
105
106
107 ParamInfo const & InsetPrintIndex::findInfo(string const & /* cmdName */)
108 {
109         static ParamInfo param_info_;
110         if (param_info_.empty())
111                 param_info_.add("name", ParamInfo::LATEX_REQUIRED);
112         return param_info_;
113 }
114
115
116 docstring InsetPrintIndex::screenLabel() const
117 {
118         return _("Index");
119 }
120
121
122 void InsetPrintIndex::validate(LaTeXFeatures & features) const
123 {
124         features.require("makeidx");
125 }
126
127
128 InsetCode InsetPrintIndex::lyxCode() const
129 {
130         return INDEX_PRINT_CODE;
131 }
132
133 } // namespace lyx