The branch, master, has been updated.

- Log -----------------------------------------------------------------

commit 41060c9723f6bf5ee5e1e888961338a62bb0302e
Author: Juergen Spitzmueller <[email protected]>
Date:   Sun Feb 24 11:29:21 2013 +0100

    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.

diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index 6329644..0772ff6 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -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
diff --git a/src/Layout.cpp b/src/Layout.cpp
index 4848954..deec49f 100644
--- a/src/Layout.cpp
+++ b/src/Layout.cpp
@@ -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();
diff --git a/src/Layout.h b/src/Layout.h
index d84ca37..88cb9a4 100644
--- a/src/Layout.h
+++ b/src/Layout.h
@@ -96,6 +96,7 @@ public:
                bool mandatory;
                docstring ldelim;
                docstring rdelim;
+               docstring defaultarg;
                docstring presetarg;
                docstring tooltip;
                std::string requires;
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
index c1a6c11..7729485 100644
--- a/src/insets/InsetLayout.cpp
+++ b/src/insets/InsetLayout.cpp
@@ -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();
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index 2af9831..4acbe65 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -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() ?

-----------------------------------------------------------------------

Summary of changes:
 lib/doc/Customization.lyx  |   43 +++++++++++++++++++++++++++++++++++++++----
 src/Layout.cpp             |    3 +++
 src/Layout.h               |    1 +
 src/insets/InsetLayout.cpp |    3 +++
 src/output_latex.cpp       |   24 +++++++++++++-----------
 5 files changed, 59 insertions(+), 15 deletions(-)


hooks/post-receive
-- 
The LyX Source Repository

Reply via email to