]> git.lyx.org Git - lyx.git/blob - src/insets/InsetNomencl.cpp
* src/inset/InsetNomencl.cpp:
[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
27 using namespace std;
28
29 namespace lyx {
30
31
32 /////////////////////////////////////////////////////////////////////
33 //
34 // InsetPrintNomencl
35 //
36 /////////////////////////////////////////////////////////////////////
37
38 InsetNomencl::InsetNomencl(InsetCommandParams const & p)
39         : InsetCommand(p, "nomenclature"),
40           nomenclature_entry_id(sgml::uniqueID(from_ascii("nomen")))
41 {}
42
43
44 ParamInfo const & InsetNomencl::findInfo(string const & /* cmdName */)
45 {
46         static ParamInfo param_info_;
47         if (param_info_.empty()) {
48                 param_info_.add("prefix", ParamInfo::LATEX_OPTIONAL);
49                 param_info_.add("symbol", ParamInfo::LATEX_REQUIRED);
50                 param_info_.add("description", ParamInfo::LATEX_REQUIRED);
51         }
52         return param_info_;
53 }
54
55
56 docstring InsetNomencl::screenLabel() const
57 {
58         size_t const maxLabelChars = 25;
59
60         docstring label = _("Nom: ") + getParam("symbol");
61         if (label.size() > maxLabelChars) {
62                 label.erase(maxLabelChars - 3);
63                 label += "...";
64         }
65         return label;
66 }
67
68
69 int InsetNomencl::docbook(odocstream & os, OutputParams const &) const
70 {
71         os << "<glossterm linkend=\"" << nomenclature_entry_id << "\">"
72            << sgml::escapeString(getParam("symbol"))
73            << "</glossterm>";
74         return 0;
75 }
76
77
78 int InsetNomencl::docbookGlossary(odocstream & os) const
79 {
80         os << "<glossentry id=\"" << nomenclature_entry_id << "\">\n"
81            << "<glossterm>"
82            << sgml::escapeString(getParam("symbol"))
83            << "</glossterm>\n"
84            << "<glossdef><para>"
85            << sgml::escapeString(getParam("description"))
86            << "</para></glossdef>\n"
87            <<"</glossentry>\n";
88         return 4;
89 }
90
91
92 void InsetNomencl::validate(LaTeXFeatures & features) const
93 {
94         features.require("nomencl");
95 }
96
97
98 /////////////////////////////////////////////////////////////////////
99 //
100 // InsetPrintNomencl
101 //
102 /////////////////////////////////////////////////////////////////////
103
104 InsetPrintNomencl::InsetPrintNomencl(InsetCommandParams const & p)
105         : InsetCommand(p, string())
106 {}
107
108
109 ParamInfo const & InsetPrintNomencl::findInfo(string const & /* cmdName */)
110 {
111         static ParamInfo param_info_;
112         if (param_info_.empty()) {
113                 param_info_.add("labelwidth", ParamInfo::LATEX_REQUIRED);
114         }
115         return param_info_;
116 }
117
118
119 docstring InsetPrintNomencl::screenLabel() const
120 {
121         return _("Nomenclature");
122 }
123
124
125 int InsetPrintNomencl::docbook(odocstream & os, OutputParams const &) const
126 {
127         os << "<glossary>\n";
128         int newlines = 2;
129         InsetIterator it = inset_iterator_begin(buffer().inset());
130         while (it) {
131                 if (it->lyxCode() == NOMENCL_CODE) {
132                         newlines += static_cast<InsetNomencl const &>(*it).docbookGlossary(os);
133                         ++it;
134                 } else if (!it->producesOutput()) {
135                         // Ignore contents of insets that are not in output
136                         size_t const depth = it.depth();
137                         ++it;
138                         while (it.depth() > depth)
139                                 ++it;
140                 } else {
141                         ++it;
142                 }
143         }
144         os << "</glossary>\n";
145         return newlines;
146 }
147
148
149 void InsetPrintNomencl::validate(LaTeXFeatures & features) const
150 {
151         features.require("nomencl");
152 }
153
154
155 InsetCode InsetPrintNomencl::lyxCode() const
156 {
157         return NOMENCL_PRINT_CODE;
158 }
159
160
161 } // namespace lyx