]> git.lyx.org Git - lyx.git/blob - src/insets/InsetNomencl.cpp
Fix GRAPHICS_EDIT of InsetGraphics
[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 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         return _("Nom");
59 }
60
61
62 int InsetNomencl::docbook(odocstream & os, OutputParams const &) const
63 {
64         os << "<glossterm linkend=\"" << nomenclature_entry_id << "\">"
65            << sgml::escapeString(getParam("symbol"))
66            << "</glossterm>";
67         return 0;
68 }
69
70
71 int InsetNomencl::docbookGlossary(odocstream & os) const
72 {
73         os << "<glossentry id=\"" << nomenclature_entry_id << "\">\n"
74            << "<glossterm>"
75            << sgml::escapeString(getParam("symbol"))
76            << "</glossterm>\n"
77            << "<glossdef><para>"
78            << sgml::escapeString(getParam("description"))
79            << "</para></glossdef>\n"
80            <<"</glossentry>\n";
81         return 4;
82 }
83
84
85 void InsetNomencl::validate(LaTeXFeatures & features) const
86 {
87         features.require("nomencl");
88 }
89
90
91 /////////////////////////////////////////////////////////////////////
92 //
93 // InsetPrintNomencl
94 //
95 /////////////////////////////////////////////////////////////////////
96
97 InsetPrintNomencl::InsetPrintNomencl(InsetCommandParams const & p)
98         : InsetCommand(p, string())
99 {}
100
101
102 ParamInfo const & InsetPrintNomencl::findInfo(string const & /* cmdName */)
103 {
104         static ParamInfo param_info_;
105         if (param_info_.empty()) {
106                 param_info_.add("labelwidth", ParamInfo::LATEX_REQUIRED);
107         }
108         return param_info_;
109 }
110
111
112 docstring InsetPrintNomencl::screenLabel() const
113 {
114         return _("Nomenclature");
115 }
116
117
118 int InsetPrintNomencl::docbook(odocstream & os, OutputParams const &) const
119 {
120         os << "<glossary>\n";
121         int newlines = 2;
122         for (InsetIterator it = inset_iterator_begin(buffer().inset()); it;) {
123                 if (it->lyxCode() == NOMENCL_CODE) {
124                         newlines += static_cast<InsetNomencl const &>(*it).docbookGlossary(os);
125                         ++it;
126                 } else if(it->lyxCode() == NOTE_CODE &&
127                           static_cast<InsetNote const &>(*it).params().type == InsetNoteParams::Note) {
128                         // Don't output anything nested in note insets
129                         size_t const depth = it.depth();
130                         ++it;
131                         while (it.depth() > depth)
132                                 ++it;
133                 } else {
134                         ++it;
135                 }
136         }
137         os << "</glossary>\n";
138         return newlines;
139 }
140
141
142 void InsetPrintNomencl::validate(LaTeXFeatures & features) const
143 {
144         features.require("nomencl");
145 }
146
147
148 InsetCode InsetPrintNomencl::lyxCode() const
149 {
150         return NOMENCL_PRINT_CODE;
151 }
152
153
154 } // namespace lyx