]> git.lyx.org Git - lyx.git/blob - src/insets/InsetNomencl.cpp
Rationalize lyxCode().
[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 "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 docstring const InsetNomencl::getScreenLabel(Buffer const &) const
38 {
39         return _("Nom");
40 }
41
42
43 int InsetNomencl::docbook(Buffer const &, odocstream & os,
44                 OutputParams const &) const
45 {
46         os << "<glossterm linkend=\"" << nomenclature_entry_id << "\">"
47            << sgml::escapeString(getParam("symbol"))
48            << "</glossterm>";
49         return 0;
50 }
51
52
53 int InsetNomencl::docbookGlossary(odocstream & os) const
54 {
55         os << "<glossentry id=\"" << nomenclature_entry_id << "\">\n"
56            << "<glossterm>"
57            << sgml::escapeString(getParam("symbol"))
58            << "</glossterm>\n"
59            << "<glossdef><para>"
60            << sgml::escapeString(getParam("description"))
61            << "</para></glossdef>\n"
62            <<"</glossentry>\n";
63         return 4;
64 }
65
66
67 void InsetNomencl::validate(LaTeXFeatures & features) const
68 {
69         features.require("nomencl");
70 }
71
72
73 InsetPrintNomencl::InsetPrintNomencl(InsetCommandParams const & p)
74         : InsetCommand(p, string())
75 {}
76
77
78 docstring const InsetPrintNomencl::getScreenLabel(Buffer const &) const
79 {
80         return _("Nomenclature");
81 }
82
83
84 int InsetPrintNomencl::docbook(Buffer const & buf, odocstream & os,
85                 OutputParams const &) const
86 {
87         os << "<glossary>\n";
88         int newlines = 2;
89         for (InsetIterator it = inset_iterator_begin(buf.inset()); it;) {
90                 if (it->lyxCode() == NOMENCL_CODE) {
91                         newlines += static_cast<InsetNomencl const &>(*it).docbookGlossary(os);
92                         ++it;
93                 } else if(it->lyxCode() == NOTE_CODE &&
94                           static_cast<InsetNote const &>(*it).params().type == InsetNoteParams::Note) {
95                         // Don't output anything nested in note insets
96                         size_t const depth = it.depth();
97                         ++it;
98                         while (it.depth() > depth)
99                                 ++it;
100                 } else {
101                         ++it;
102                 }
103         }
104         os << "</glossary>\n";
105         return newlines;
106 }
107
108
109 void InsetPrintNomencl::validate(LaTeXFeatures & features) const
110 {
111         features.require("nomencl");
112 }
113
114
115 InsetCode InsetPrintNomencl::lyxCode() const
116 {
117         return NOMENCL_PRINT_CODE;
118 }
119
120
121 } // namespace lyx