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