2 * \file InsetNomencl.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
13 #include "InsetNomencl.h"
14 #include "InsetNote.h"
17 #include "DispatchResult.h"
18 #include "FuncRequest.h"
19 #include "InsetIterator.h"
20 #include "LaTeXFeatures.h"
21 #include "MetricsInfo.h"
24 #include "support/docstream.h"
25 #include "support/gettext.h"
26 #include "support/lstrings.h"
29 using namespace lyx::support;
34 /////////////////////////////////////////////////////////////////////
38 /////////////////////////////////////////////////////////////////////
40 InsetNomencl::InsetNomencl(InsetCommandParams const & p)
41 : InsetCommand(p, "nomenclature"),
42 nomenclature_entry_id(sgml::uniqueID(from_ascii("nomen")))
46 ParamInfo const & InsetNomencl::findInfo(string const & /* cmdName */)
48 static ParamInfo param_info_;
49 if (param_info_.empty()) {
50 param_info_.add("prefix", ParamInfo::LATEX_OPTIONAL);
51 param_info_.add("symbol", ParamInfo::LATEX_REQUIRED);
52 param_info_.add("description", ParamInfo::LATEX_REQUIRED);
58 docstring InsetNomencl::screenLabel() const
60 size_t const maxLabelChars = 25;
62 docstring label = _("Nom: ") + getParam("symbol");
63 if (label.size() > maxLabelChars) {
64 label.erase(maxLabelChars - 3);
71 docstring InsetNomencl::toolTip(BufferView const & /*bv*/, int /*x*/, int /*y*/) const
73 docstring tip = _("Nomenclature Symbol: ") + getParam("symbol") + "\n";
74 tip += _("Description: ") + "\t"
75 + subst(getParam("description"), from_ascii("\\\\"), from_ascii("\n\t"));
76 if (!getParam("prefix").empty())
77 tip += "\n" + _("Sorting: ") + getParam("prefix");
83 int InsetNomencl::docbook(odocstream & os, OutputParams const &) const
85 os << "<glossterm linkend=\"" << nomenclature_entry_id << "\">"
86 << sgml::escapeString(getParam("symbol"))
92 int InsetNomencl::docbookGlossary(odocstream & os) const
94 os << "<glossentry id=\"" << nomenclature_entry_id << "\">\n"
96 << sgml::escapeString(getParam("symbol"))
99 << sgml::escapeString(getParam("description"))
100 << "</para></glossdef>\n"
106 void InsetNomencl::validate(LaTeXFeatures & features) const
108 features.require("nomencl");
112 /////////////////////////////////////////////////////////////////////
116 /////////////////////////////////////////////////////////////////////
118 InsetPrintNomencl::InsetPrintNomencl(InsetCommandParams const & p)
119 : InsetCommand(p, string())
123 ParamInfo const & InsetPrintNomencl::findInfo(string const & /* cmdName */)
125 static ParamInfo param_info_;
126 if (param_info_.empty()) {
127 param_info_.add("labelwidth", ParamInfo::LATEX_REQUIRED);
133 docstring InsetPrintNomencl::screenLabel() const
135 return _("Nomenclature");
139 int InsetPrintNomencl::docbook(odocstream & os, OutputParams const &) const
141 os << "<glossary>\n";
143 InsetIterator it = inset_iterator_begin(buffer().inset());
145 if (it->lyxCode() == NOMENCL_CODE) {
146 newlines += static_cast<InsetNomencl const &>(*it).docbookGlossary(os);
148 } else if (!it->producesOutput()) {
149 // Ignore contents of insets that are not in output
150 size_t const depth = it.depth();
152 while (it.depth() > depth)
158 os << "</glossary>\n";
163 void InsetPrintNomencl::validate(LaTeXFeatures & features) const
165 features.require("nomencl");
169 InsetCode InsetPrintNomencl::lyxCode() const
171 return NOMENCL_PRINT_CODE;