]> git.lyx.org Git - lyx.git/blob - src/insets/InsetNomencl.cpp
The last commit was, uhh, not what I intended.
[lyx.git] / src / insets / InsetNomencl.cpp
1 /**
2  * \file InsetNomencl.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  * \author O. U. Baran
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11 #include <config.h>
12
13 #include "InsetNomencl.h"
14 #include "InsetNote.h"
15
16 #include "Buffer.h"
17 #include "DispatchResult.h"
18 #include "FuncRequest.h"
19 #include "InsetIterator.h"
20 #include "LaTeXFeatures.h"
21 #include "MetricsInfo.h"
22 #include "sgml.h"
23
24 #include "support/docstream.h"
25 #include "support/gettext.h"
26 #include "support/lstrings.h"
27
28 using namespace std;
29 using namespace lyx::support;
30
31 namespace lyx {
32
33
34 /////////////////////////////////////////////////////////////////////
35 //
36 // InsetNomencl
37 //
38 /////////////////////////////////////////////////////////////////////
39
40 InsetNomencl::InsetNomencl(InsetCommandParams const & p)
41         : InsetCommand(p, "nomenclature"),
42           nomenclature_entry_id(sgml::uniqueID(from_ascii("nomen")))
43 {}
44
45
46 ParamInfo const & InsetNomencl::findInfo(string const & /* cmdName */)
47 {
48         static ParamInfo param_info_;
49         if (param_info_.empty()) {
50                 param_info_.add("prefix", ParamInfo::LATEX_OPTIONAL);
51                 param_info_.add("symbol", ParamInfo::LATEX_REQUIRED);
52                 param_info_.add("description", ParamInfo::LATEX_REQUIRED);
53         }
54         return param_info_;
55 }
56
57
58 docstring InsetNomencl::screenLabel() const
59 {
60         size_t const maxLabelChars = 25;
61
62         docstring label = _("Nom: ") + getParam("symbol");
63         if (label.size() > maxLabelChars) {
64                 label.erase(maxLabelChars - 3);
65                 label += "...";
66         }
67         return label;
68 }
69
70
71 docstring InsetNomencl::toolTip(BufferView const & /*bv*/, int /*x*/, int /*y*/) const
72 {
73         docstring tip = _("Nomenclature Symbol: ") + getParam("symbol") + "\n";
74         tip += _("Description: ") + "\t"
75                 + subst(getParam("description"), from_ascii("\\\\"), from_ascii("\n\t"));
76         if (!getParam("prefix").empty())
77                 tip += "\n" + _("Sorting: ") + getParam("prefix");
78         return tip;
79 }
80
81
82
83 int InsetNomencl::docbook(odocstream & os, OutputParams const &) const
84 {
85         os << "<glossterm linkend=\"" << nomenclature_entry_id << "\">"
86            << sgml::escapeString(getParam("symbol"))
87            << "</glossterm>";
88         return 0;
89 }
90
91
92 int InsetNomencl::docbookGlossary(odocstream & os) const
93 {
94         os << "<glossentry id=\"" << nomenclature_entry_id << "\">\n"
95            << "<glossterm>"
96            << sgml::escapeString(getParam("symbol"))
97            << "</glossterm>\n"
98            << "<glossdef><para>"
99            << sgml::escapeString(getParam("description"))
100            << "</para></glossdef>\n"
101            <<"</glossentry>\n";
102         return 4;
103 }
104
105
106 void InsetNomencl::validate(LaTeXFeatures & features) const
107 {
108         features.require("nomencl");
109 }
110
111
112 /////////////////////////////////////////////////////////////////////
113 //
114 // InsetPrintNomencl
115 //
116 /////////////////////////////////////////////////////////////////////
117
118 InsetPrintNomencl::InsetPrintNomencl(InsetCommandParams const & p)
119         : InsetCommand(p, string())
120 {}
121
122
123 ParamInfo const & InsetPrintNomencl::findInfo(string const & /* cmdName */)
124 {
125         static ParamInfo param_info_;
126         if (param_info_.empty()) {
127                 param_info_.add("labelwidth", ParamInfo::LATEX_REQUIRED);
128         }
129         return param_info_;
130 }
131
132
133 docstring InsetPrintNomencl::screenLabel() const
134 {
135         return _("Nomenclature");
136 }
137
138
139 int InsetPrintNomencl::docbook(odocstream & os, OutputParams const &) const
140 {
141         os << "<glossary>\n";
142         int newlines = 2;
143         InsetIterator it = inset_iterator_begin(buffer().inset());
144         while (it) {
145                 if (it->lyxCode() == NOMENCL_CODE) {
146                         newlines += static_cast<InsetNomencl const &>(*it).docbookGlossary(os);
147                         ++it;
148                 } else if (!it->producesOutput()) {
149                         // Ignore contents of insets that are not in output
150                         size_t const depth = it.depth();
151                         ++it;
152                         while (it.depth() > depth)
153                                 ++it;
154                 } else {
155                         ++it;
156                 }
157         }
158         os << "</glossary>\n";
159         return newlines;
160 }
161
162
163 void InsetPrintNomencl::validate(LaTeXFeatures & features) const
164 {
165         features.require("nomencl");
166 }
167
168
169 InsetCode InsetPrintNomencl::lyxCode() const
170 {
171         return NOMENCL_PRINT_CODE;
172 }
173
174
175 } // namespace lyx