2006-11-04 17:55:36 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetNomencl.cpp
|
2006-11-04 17:55:36 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2006-11-04 17:55:36 +00:00
|
|
|
* \author O. U. Baran
|
2009-05-21 19:33:09 +00:00
|
|
|
* \author Uwe Stöhr
|
|
|
|
* \author Jürgen Spitzmüller
|
2006-11-04 17:55:36 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetNomencl.h"
|
|
|
|
#include "InsetNote.h"
|
2006-11-04 17:55:36 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "DispatchResult.h"
|
2009-05-22 09:25:31 +00:00
|
|
|
#include "Font.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2009-05-22 16:26:15 +00:00
|
|
|
#include "FuncStatus.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "InsetIterator.h"
|
2009-05-21 19:33:09 +00:00
|
|
|
#include "InsetList.h"
|
2006-11-04 17:55:36 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2009-05-22 16:26:15 +00:00
|
|
|
#include "Length.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "MetricsInfo.h"
|
2006-11-04 17:55:36 +00:00
|
|
|
#include "sgml.h"
|
|
|
|
|
2009-05-22 09:25:31 +00:00
|
|
|
#include "frontends/FontMetrics.h"
|
|
|
|
|
2007-11-01 22:17:22 +00:00
|
|
|
#include "support/docstream.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/gettext.h"
|
2008-08-23 15:02:44 +00:00
|
|
|
#include "support/lstrings.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2008-08-23 15:02:44 +00:00
|
|
|
using namespace lyx::support;
|
2006-11-04 17:55:36 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2008-08-23 15:02:44 +00:00
|
|
|
// InsetNomencl
|
2008-02-27 20:43:16 +00:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-11-04 17:55:36 +00:00
|
|
|
InsetNomencl::InsetNomencl(InsetCommandParams const & p)
|
2006-11-10 21:13:17 +00:00
|
|
|
: InsetCommand(p, "nomenclature"),
|
2007-04-29 22:21:00 +00:00
|
|
|
nomenclature_entry_id(sgml::uniqueID(from_ascii("nomen")))
|
2006-11-04 17:55:36 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-02-23 22:01:02 +00:00
|
|
|
ParamInfo const & InsetNomencl::findInfo(string const & /* cmdName */)
|
2007-10-25 04:13:56 +00:00
|
|
|
{
|
2008-02-23 22:01:02 +00:00
|
|
|
static ParamInfo param_info_;
|
|
|
|
if (param_info_.empty()) {
|
Per Abdel's suggestion that we focus on bug-fixing at this point, this will be the last patch in this series for a bit. But I wanted to get this done before I forget what it is I was doing, so here it is.
The idea behind this patch is to make real key-value support for InsetCommand parameters possible. This should be particularly useful for the listings version of InsetInclude, though we would need some kind of UI for it before it would really be helpful. (See below for some thoughts.) This doesn't substantially change anything else, though some things do get re-arranged a bit.
Basically, the idea is this. First, we introduce a whole range of parameter types: Normal LaTeX optional and required parameters; ones for LyX's internal use (like embed); and finally, in connection with keyval, ones that represent keys and ones that represent optional and required arguments where the keyval stuff will appear. (I'm assuming here that there will always be exactly one of those, and that it will accept only keyval-type material.) The parameters themselves are stored in a map, so it's really only the output routines that need to care about the different types of parameters.
Regarding the frontend, it seems to me that something like the following would work:
(i) scan the parameter list for LATEX_KEY type parameters
(ii) the dialog will have a series of lines, each of which has a combo box listing the acceptable keys and a QLineEdit for entering its value, as well as a "delete" button of some sort for removing this key and its value
(iii) there should be an "add line" button to add a new line, activated only when all other lines are filled with values
Probably not even too hard.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23235 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-25 22:13:45 +00:00
|
|
|
param_info_.add("prefix", ParamInfo::LATEX_OPTIONAL);
|
|
|
|
param_info_.add("symbol", ParamInfo::LATEX_REQUIRED);
|
|
|
|
param_info_.add("description", ParamInfo::LATEX_REQUIRED);
|
2008-02-23 22:01:02 +00:00
|
|
|
}
|
|
|
|
return param_info_;
|
2007-10-25 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring InsetNomencl::screenLabel() const
|
2006-11-04 17:55:36 +00:00
|
|
|
{
|
2008-08-22 16:12:29 +00:00
|
|
|
size_t const maxLabelChars = 25;
|
|
|
|
|
|
|
|
docstring label = _("Nom: ") + getParam("symbol");
|
|
|
|
if (label.size() > maxLabelChars) {
|
|
|
|
label.erase(maxLabelChars - 3);
|
|
|
|
label += "...";
|
|
|
|
}
|
|
|
|
return label;
|
2006-11-04 17:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-23 15:02:44 +00:00
|
|
|
docstring InsetNomencl::toolTip(BufferView const & /*bv*/, int /*x*/, int /*y*/) const
|
|
|
|
{
|
|
|
|
docstring tip = _("Nomenclature Symbol: ") + getParam("symbol") + "\n";
|
|
|
|
tip += _("Description: ") + "\t"
|
|
|
|
+ subst(getParam("description"), from_ascii("\\\\"), from_ascii("\n\t"));
|
|
|
|
if (!getParam("prefix").empty())
|
|
|
|
tip += "\n" + _("Sorting: ") + getParam("prefix");
|
|
|
|
return tip;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetNomencl::docbook(odocstream & os, OutputParams const &) const
|
2006-11-04 17:55:36 +00:00
|
|
|
{
|
2007-04-29 22:21:00 +00:00
|
|
|
os << "<glossterm linkend=\"" << nomenclature_entry_id << "\">"
|
2006-11-04 17:55:36 +00:00
|
|
|
<< sgml::escapeString(getParam("symbol"))
|
2006-11-10 15:45:42 +00:00
|
|
|
<< "</glossterm>";
|
2006-11-04 17:55:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-10 15:45:42 +00:00
|
|
|
int InsetNomencl::docbookGlossary(odocstream & os) const
|
|
|
|
{
|
2007-04-29 22:21:00 +00:00
|
|
|
os << "<glossentry id=\"" << nomenclature_entry_id << "\">\n"
|
2006-11-10 15:45:42 +00:00
|
|
|
<< "<glossterm>"
|
|
|
|
<< sgml::escapeString(getParam("symbol"))
|
|
|
|
<< "</glossterm>\n"
|
|
|
|
<< "<glossdef><para>"
|
|
|
|
<< sgml::escapeString(getParam("description"))
|
|
|
|
<< "</para></glossdef>\n"
|
|
|
|
<<"</glossentry>\n";
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-04 17:55:36 +00:00
|
|
|
void InsetNomencl::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
features.require("nomencl");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// InsetPrintNomencl
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-11-04 17:55:36 +00:00
|
|
|
InsetPrintNomencl::InsetPrintNomencl(InsetCommandParams const & p)
|
2009-05-22 16:26:15 +00:00
|
|
|
: InsetCommand(p, "nomencl_print")
|
2006-11-04 17:55:36 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-02-23 22:01:02 +00:00
|
|
|
ParamInfo const & InsetPrintNomencl::findInfo(string const & /* cmdName */)
|
2007-10-25 04:13:56 +00:00
|
|
|
{
|
2009-05-22 08:31:43 +00:00
|
|
|
// The symbol width is set via nomencl's \nomlabelwidth in
|
|
|
|
// InsetPrintNomencl::latex and not as optional parameter of
|
|
|
|
// \printnomenclature
|
2008-02-23 22:01:02 +00:00
|
|
|
static ParamInfo param_info_;
|
2009-05-22 08:31:43 +00:00
|
|
|
if (param_info_.empty()) {
|
|
|
|
// how is the width set?
|
2009-05-22 16:26:15 +00:00
|
|
|
// values: none|auto|custom
|
2009-05-22 08:31:43 +00:00
|
|
|
param_info_.add("set_width", ParamInfo::LYX_INTERNAL);
|
2009-05-22 16:26:15 +00:00
|
|
|
// custom width
|
|
|
|
param_info_.add("width", ParamInfo::LYX_INTERNAL);
|
2009-05-22 08:31:43 +00:00
|
|
|
}
|
2008-02-23 22:01:02 +00:00
|
|
|
return param_info_;
|
2007-10-25 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring InsetPrintNomencl::screenLabel() const
|
2006-11-04 17:55:36 +00:00
|
|
|
{
|
2007-04-29 22:21:00 +00:00
|
|
|
return _("Nomenclature");
|
2006-11-04 17:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-22 16:26:15 +00:00
|
|
|
void InsetPrintNomencl::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|
|
|
{
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
InsetCommandParams p(NOMENCL_PRINT_CODE);
|
|
|
|
// FIXME UNICODE
|
|
|
|
InsetCommand::string2params("nomencl_print",
|
|
|
|
to_utf8(cmd.argument()), p);
|
|
|
|
if (p.getCmdName().empty()) {
|
|
|
|
cur.noUpdate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
setParams(p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
InsetCommand::doDispatch(cur, cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetPrintNomencl::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & status) const
|
|
|
|
{
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
status.setEnabled(true);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return InsetCommand::getStatus(cur, cmd, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetPrintNomencl::docbook(odocstream & os, OutputParams const &) const
|
2006-11-04 17:55:36 +00:00
|
|
|
{
|
2006-11-10 15:45:42 +00:00
|
|
|
os << "<glossary>\n";
|
|
|
|
int newlines = 2;
|
2008-04-23 18:49:55 +00:00
|
|
|
InsetIterator it = inset_iterator_begin(buffer().inset());
|
|
|
|
while (it) {
|
2007-10-13 09:04:52 +00:00
|
|
|
if (it->lyxCode() == NOMENCL_CODE) {
|
2006-11-10 15:45:42 +00:00
|
|
|
newlines += static_cast<InsetNomencl const &>(*it).docbookGlossary(os);
|
|
|
|
++it;
|
2008-04-23 13:00:57 +00:00
|
|
|
} else if (!it->producesOutput()) {
|
|
|
|
// Ignore contents of insets that are not in output
|
2006-11-10 15:45:42 +00:00
|
|
|
size_t const depth = it.depth();
|
|
|
|
++it;
|
|
|
|
while (it.depth() > depth)
|
|
|
|
++it;
|
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os << "</glossary>\n";
|
|
|
|
return newlines;
|
2006-11-04 17:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-22 08:31:43 +00:00
|
|
|
namespace {
|
2009-05-21 19:33:09 +00:00
|
|
|
docstring nomenclWidest(Buffer const & buffer)
|
|
|
|
{
|
2009-05-22 08:31:43 +00:00
|
|
|
// nomenclWidest() determines and returns the widest used
|
|
|
|
// nomenclature symbol in the document
|
2009-05-21 19:33:09 +00:00
|
|
|
|
|
|
|
int w = 0;
|
|
|
|
docstring symb;
|
|
|
|
InsetNomencl const * nomencl = 0;
|
|
|
|
ParagraphList::const_iterator it = buffer.paragraphs().begin();
|
|
|
|
ParagraphList::const_iterator end = buffer.paragraphs().end();
|
|
|
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (it->insetList().empty())
|
|
|
|
continue;
|
|
|
|
InsetList::const_iterator iit = it->insetList().begin();
|
|
|
|
InsetList::const_iterator eend = it->insetList().end();
|
|
|
|
for (; iit != eend; ++iit) {
|
|
|
|
Inset * inset = iit->inset;
|
|
|
|
if (inset->lyxCode() != NOMENCL_CODE)
|
|
|
|
continue;
|
|
|
|
nomencl = static_cast<InsetNomencl const *>(inset);
|
2009-05-22 09:25:31 +00:00
|
|
|
docstring const symbol =
|
|
|
|
nomencl->getParam("symbol");
|
|
|
|
// This is only an approximation,
|
|
|
|
// but the best we can get.
|
|
|
|
int const wx =
|
|
|
|
theFontMetrics(Font()).width(symbol);
|
|
|
|
if (wx > w) {
|
2009-05-21 19:33:09 +00:00
|
|
|
w = wx;
|
2009-05-22 09:25:31 +00:00
|
|
|
symb = symbol;
|
|
|
|
}
|
2009-05-21 19:33:09 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-22 09:25:31 +00:00
|
|
|
// return the widest (or an empty) string
|
2009-05-21 19:33:09 +00:00
|
|
|
return symb;
|
|
|
|
}
|
2009-05-22 08:31:43 +00:00
|
|
|
}
|
2009-05-21 19:33:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
int InsetPrintNomencl::latex(odocstream & os, OutputParams const &) const
|
|
|
|
{
|
|
|
|
int lines = 0;
|
2009-05-22 08:31:43 +00:00
|
|
|
if (getParam("set_width") == "auto") {
|
|
|
|
docstring widest = nomenclWidest(buffer());
|
2009-05-22 23:23:09 +00:00
|
|
|
// Set the label width via nomencl's command \nomlabelwidth.
|
|
|
|
// This must be output before the command
|
2009-05-22 08:31:43 +00:00
|
|
|
// \printnomenclature
|
|
|
|
if (!widest.empty()) {
|
|
|
|
// assure that the width is never below the
|
2009-05-22 23:23:09 +00:00
|
|
|
// value predefined in nomencl.cfg
|
|
|
|
os << "\\newlength{\\symbwidth}\n";
|
|
|
|
os << "\\settowidth{\\symbwidth}{"
|
2009-05-22 08:31:43 +00:00
|
|
|
<< widest
|
|
|
|
<< "}\n";
|
|
|
|
os << "\\ifthenelse{%\n";
|
2009-05-22 23:23:09 +00:00
|
|
|
os << "\\lengthtest{\\symbwidth < \\nomlabelwidth}}\n";
|
|
|
|
os << " {\\setlength{\\symbwidth}{\\nomlabelwidth}}\n";
|
2009-05-22 08:31:43 +00:00
|
|
|
os << " {}\n";
|
2009-05-22 23:23:09 +00:00
|
|
|
lines += 6;
|
2009-05-22 08:31:43 +00:00
|
|
|
}
|
2009-05-22 16:26:15 +00:00
|
|
|
} else if (getParam("set_width") == "custom") {
|
|
|
|
// custom length as optional arg of \printnomenclature
|
|
|
|
string const width =
|
|
|
|
Length(to_ascii(getParam("width"))).asLatexString();
|
|
|
|
os << '\\'
|
|
|
|
<< from_ascii(getCmdName())
|
|
|
|
<< '['
|
|
|
|
<< from_ascii(width)
|
|
|
|
<< "]{}";
|
|
|
|
return lines;
|
2009-05-21 19:33:09 +00:00
|
|
|
}
|
|
|
|
// output the command \printnomenclature
|
|
|
|
os << getCommand();
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-04 17:55:36 +00:00
|
|
|
void InsetPrintNomencl::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
features.require("nomencl");
|
2009-05-21 22:18:08 +00:00
|
|
|
// needed for InsetPrintNomencl::latex
|
|
|
|
features.require("ifthen");
|
2006-11-04 17:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-13 09:04:52 +00:00
|
|
|
InsetCode InsetPrintNomencl::lyxCode() const
|
2006-11-04 17:55:36 +00:00
|
|
|
{
|
2007-10-13 09:04:52 +00:00
|
|
|
return NOMENCL_PRINT_CODE;
|
2006-11-04 17:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-22 16:26:15 +00:00
|
|
|
docstring InsetPrintNomencl::contextMenu(BufferView const &, int, int) const
|
|
|
|
{
|
|
|
|
return from_ascii("context-nomenclprint");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-04 17:55:36 +00:00
|
|
|
} // namespace lyx
|