]> git.lyx.org Git - features.git/blob - src/insets/InsetNomencl.cpp
c3e7aefb2d57178f34641796a3f0b1b4e97b7430
[features.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 "gettext.h"
20 #include "InsetIterator.h"
21 #include "LaTeXFeatures.h"
22 #include "MetricsInfo.h"
23 #include "sgml.h"
24
25
26 namespace lyx {
27
28 using std::string;
29
30
31 InsetNomencl::InsetNomencl(InsetCommandParams const & p)
32         : InsetCommand(p, "nomenclature"),
33           nomenclature_entry_id(sgml::uniqueID(from_ascii("nomen")))
34 {}
35
36
37 CommandInfo const * InsetNomencl::findInfo(std::string const & /* cmdName */)
38 {
39         static const char * const paramnames[] = {"prefix", "symbol", "description", ""};
40         static const bool isoptional[] = {true, false, false};
41         static const CommandInfo info = {3, paramnames, isoptional};
42         return &info;
43 }
44
45
46 docstring const InsetNomencl::getScreenLabel(Buffer const &) const
47 {
48         return _("Nom");
49 }
50
51
52 int InsetNomencl::docbook(Buffer const &, odocstream & os,
53                 OutputParams const &) const
54 {
55         os << "<glossterm linkend=\"" << nomenclature_entry_id << "\">"
56            << sgml::escapeString(getParam("symbol"))
57            << "</glossterm>";
58         return 0;
59 }
60
61
62 int InsetNomencl::docbookGlossary(odocstream & os) const
63 {
64         os << "<glossentry id=\"" << nomenclature_entry_id << "\">\n"
65            << "<glossterm>"
66            << sgml::escapeString(getParam("symbol"))
67            << "</glossterm>\n"
68            << "<glossdef><para>"
69            << sgml::escapeString(getParam("description"))
70            << "</para></glossdef>\n"
71            <<"</glossentry>\n";
72         return 4;
73 }
74
75
76 void InsetNomencl::validate(LaTeXFeatures & features) const
77 {
78         features.require("nomencl");
79 }
80
81
82 InsetPrintNomencl::InsetPrintNomencl(InsetCommandParams const & p)
83         : InsetCommand(p, string())
84 {}
85
86
87 CommandInfo const * InsetPrintNomencl::findInfo(std::string const & /* cmdName */)
88 {
89                 static const char * const paramnames[] = {"labelwidth", ""};
90                 static const bool isoptional[] = {true};
91                 static const CommandInfo info = {1, paramnames, isoptional};
92                 return &info;
93 }
94
95
96 docstring const InsetPrintNomencl::getScreenLabel(Buffer const &) const
97 {
98         return _("Nomenclature");
99 }
100
101
102 int InsetPrintNomencl::docbook(Buffer const & buf, odocstream & os,
103                 OutputParams const &) const
104 {
105         os << "<glossary>\n";
106         int newlines = 2;
107         for (InsetIterator it = inset_iterator_begin(buf.inset()); it;) {
108                 if (it->lyxCode() == NOMENCL_CODE) {
109                         newlines += static_cast<InsetNomencl const &>(*it).docbookGlossary(os);
110                         ++it;
111                 } else if(it->lyxCode() == NOTE_CODE &&
112                           static_cast<InsetNote const &>(*it).params().type == InsetNoteParams::Note) {
113                         // Don't output anything nested in note insets
114                         size_t const depth = it.depth();
115                         ++it;
116                         while (it.depth() > depth)
117                                 ++it;
118                 } else {
119                         ++it;
120                 }
121         }
122         os << "</glossary>\n";
123         return newlines;
124 }
125
126
127 void InsetPrintNomencl::validate(LaTeXFeatures & features) const
128 {
129         features.require("nomencl");
130 }
131
132
133 InsetCode InsetPrintNomencl::lyxCode() const
134 {
135         return NOMENCL_PRINT_CODE;
136 }
137
138
139 } // namespace lyx