2 * \file InsetArgument.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Martin Vermeer
8 * Full author contact details are available in file CREDITS.
13 #include "InsetArgument.h"
15 #include "InsetList.h"
18 #include "ParIterator.h"
20 #include "support/convert.h"
21 #include "support/debug.h"
22 #include "support/docstream.h"
23 #include "support/gettext.h"
24 #include "support/lstrings.h"
31 InsetArgument::InsetArgument(Buffer * buf, string const & name)
32 : InsetCollapsable(buf), name_(name), labelstring_(docstring())
36 void InsetArgument::write(ostream & os) const
38 os << "Argument " << name_ << "\n";
39 InsetCollapsable::write(os);
42 void InsetArgument::read(Lexer & lex)
45 InsetCollapsable::read(lex);
48 void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype)
50 Layout::LaTeXArgMap args;
51 bool const insetlayout = &it.inset() && it.paragraph().layout().latexargs().empty();
53 args = it.inset().getLayout().latexargs();
55 args = it.paragraph().layout().latexargs();
57 // Handle pre 2.1 ArgInsets (lyx2lyx cannot classify them)
59 int req = insetlayout ? it.inset().getLayout().requiredArgs()
60 : it.paragraph().layout().requiredArgs();
61 int opts = insetlayout ? it.inset().getLayout().optArgs()
62 : it.paragraph().layout().optArgs();
65 InsetList::const_iterator parit = it.paragraph().insetList().begin();
66 InsetList::const_iterator parend = it.paragraph().insetList().end();
67 for (; parit != parend; ++parit) {
68 if (parit->inset->lyxCode() == ARG_CODE) {
70 if (parit->inset == this)
77 // We have optional arguments
79 if (ours <= realopts) {
80 name_ = convert<string>(ours);
85 // This is a mandatory argument. We have to consider
86 // non-given optional arguments for the numbering
87 int offset = opts - realopts;
89 name_ = convert<string>(ours);
92 Layout::LaTeXArgMap::const_iterator const lait =
93 args.find(convert<unsigned int>(name_));
94 if (lait != args.end()) {
95 labelstring_ = translateIfPossible((*lait).second.labelstring);
96 tooltip_ = translateIfPossible((*lait).second.tooltip);
98 labelstring_ = _("Unknown Argument");
99 tooltip_ = _("Argument not known in this Layout. Will be supressed in the output.");
102 InsetCollapsable::updateBuffer(it, utype);
105 void InsetArgument::setButtonLabel()
107 setLabel(labelstring_);
110 docstring InsetArgument::toolTip(BufferView const & bv, int, int) const
114 return toolTipText(tooltip_ + from_ascii(":\n"));
117 void InsetArgument::latexArgument(otexstream & os,
118 OutputParams const & runparams, docstring const & ldelim,
119 docstring const & rdelim) const
123 otexstream ots(ss, texrow);
124 InsetText::latex(ots, runparams);
125 docstring str = ss.str();
126 if (ldelim != "{" && support::contains(str, rdelim))
127 str = '{' + str + '}';
128 os << ldelim << str << rdelim;