Allow to specify default argument for layout/inset argments

This default argument is inserted iff no inset argument is present. This is useful particularly for mandatory arguments that need to have a sensible default value.
This commit is contained in:
Juergen Spitzmueller 2013-02-24 11:29:21 +01:00
parent be4ab02dd3
commit 41060c9723
5 changed files with 59 additions and 15 deletions

View File

@ -1,5 +1,5 @@
#LyX 2.1 created this file. For more info see http://www.lyx.org/
\lyxformat 461
\lyxformat 463
\begin_document
\begin_header
\textclass scrbook
@ -11024,7 +11024,44 @@ status collapsed
\begin_layout Itemize
\change_inserted -712698321 1355144578
\change_inserted -712698321 1361701444
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1361701356
DefaultArg
\end_layout
\end_inset
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1361701356
[string]
\end_layout
\end_inset
defines an argument that is inserted if and only if no user-specified arguments
were given, i.
\begin_inset space \thinspace{}
\end_inset
e.
if no argument inset has been inserted (note that also an empty argument
inset omits the DefaultArg).
Multiple arguments need to be separated by comma.
\end_layout
\begin_layout Itemize
\change_inserted -712698321 1361701337
\begin_inset Flex Code
status collapsed
@ -11053,8 +11090,6 @@ status collapsed
defines an argument that is inserted in any case (alone or in addition
to user-specified arguments).
Multiple arguments need to be separated by comma.
\change_unchanged
\end_layout
\begin_layout Itemize

View File

@ -923,6 +923,9 @@ void Layout::readArgument(Lexer & lex)
arg.rdelim = lex.getDocString();
arg.rdelim = support::subst(arg.rdelim, from_ascii("<br/>"),
from_ascii("\n"));
} else if (tok == "defaultarg") {
lex.next();
arg.defaultarg = lex.getDocString();
} else if (tok == "presetarg") {
lex.next();
arg.presetarg = lex.getDocString();

View File

@ -96,6 +96,7 @@ public:
bool mandatory;
docstring ldelim;
docstring rdelim;
docstring defaultarg;
docstring presetarg;
docstring tooltip;
std::string requires;

View File

@ -551,6 +551,9 @@ void InsetLayout::readArgument(Lexer & lex)
arg.rdelim = lex.getDocString();
arg.rdelim = support::subst(arg.rdelim,
from_ascii("<br/>"), from_ascii("\n"));
} else if (tok == "defaultarg") {
lex.next();
arg.defaultarg = lex.getDocString();
} else if (tok == "presetarg") {
lex.next();
arg.presetarg = lex.getDocString();

View File

@ -351,22 +351,24 @@ void getArgInsets(otexstream & os, OutputParams const & runparams, Layout::LaTeX
string const name = prefix + convert<string>(i);
if ((*lait).first == name) {
Layout::latexarg arg = (*lait).second;
docstring preset = arg.presetarg;
if (!arg.defaultarg.empty()) {
if (!preset.empty())
preset += ",";
preset += arg.defaultarg;
}
if (arg.mandatory) {
docstring ldelim = arg.ldelim.empty() ?
from_ascii("{") : arg.ldelim;
docstring rdelim = arg.rdelim.empty() ?
from_ascii("}") : arg.rdelim;
os << ldelim << arg.presetarg << rdelim;
} else if (!arg.presetarg.empty()) {
docstring ldelim = arg.mandatory ?
from_ascii("{") : from_ascii("[");
docstring rdelim = arg.mandatory ?
from_ascii("}") : from_ascii("]");
if (!arg.ldelim.empty())
ldelim = arg.ldelim;
if (!arg.rdelim.empty())
rdelim = arg.rdelim;
os << ldelim << arg.presetarg << rdelim;
os << ldelim << preset << rdelim;
} else if (!preset.empty()) {
docstring ldelim = arg.ldelim.empty() ?
from_ascii("[") : arg.ldelim;
docstring rdelim = arg.rdelim.empty() ?
from_ascii("]") : arg.rdelim;
os << ldelim << preset << rdelim;
} else if (find(required.begin(), required.end(),
(*lait).first) != required.end()) {
docstring ldelim = arg.ldelim.empty() ?