]> git.lyx.org Git - lyx.git/commitdiff
Allow to specify default argument for layout/inset argments
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 24 Feb 2013 10:29:21 +0000 (11:29 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Sun, 24 Feb 2013 10:29:21 +0000 (11:29 +0100)
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.

lib/doc/Customization.lyx
src/Layout.cpp
src/Layout.h
src/insets/InsetLayout.cpp
src/output_latex.cpp

index 632964499b4e84a85f12deaeb4ceee12c217b06d..0772ff60a730c23f18d4fe7fee15c23b0228bf52 100644 (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
index 48489548c0984a09a8ba223640db7a0036b05e11..deec49fdbe763630501b2426b1da150895e5cfab 100644 (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();
index d84ca372b62d2cb74ea7ec37440a7e081672ad42..88cb9a4edba234c22d0181581d905a1926bdd1b1 100644 (file)
@@ -96,6 +96,7 @@ public:
                bool mandatory;
                docstring ldelim;
                docstring rdelim;
+               docstring defaultarg;
                docstring presetarg;
                docstring tooltip;
                std::string requires;
index c1a6c113c27b0445c7a5a2d206c709708a0473a8..77294856d23c86c33aa74129c50dd91e16724439 100644 (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();
index 2af9831d780f175aa61c26ea24e42601658d8050..4acbe654331ab67fe2bb0acc41158f860721e0f4 100644 (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() ?