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