commit 760b7cf2b659380c03ff43860df077204b5e6cd1
Author: Juergen Spitzmueller <[email protected]>
Date:   Sat May 9 12:17:24 2015 +0200

    Add option to Argument to let it be inserted with a copy of the co-text.
    
    This is useful for classic "Short Titles", where one might want to start
    with the full title in the inset.
    
    Addresses: #4745

diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index e702b51..dc4dbb7 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -11391,12 +11391,54 @@ status collapsed
 , this argument is automatically inserted when the respective style is 
selected.
  Currently, only one argument per style\SpecialChar breakableslash
 layout can be automatically inserted.
-\change_inserted -712698321 1431070519
+\change_inserted -712698321 1431166542
 
 \end_layout
 
 \begin_layout Itemize
 
+\change_inserted -712698321 1431166604
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1431166548
+InsertCotext
+\end_layout
+
+\end_inset
+
+ 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1431166543
+[int=0]
+\end_layout
+
+\end_inset
+
+ If this is set to 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1431166543
+1
+\end_layout
+
+\end_inset
+
+, this argument will bei inserted with a copy of the co-text (either selected
+ text or the whole paragraph) as content.
+\end_layout
+
+\begin_layout Itemize
+
 \change_inserted -712698321 1431070588
 
 \lang ngerman
diff --git a/src/Layout.cpp b/src/Layout.cpp
index cb1f69b..60ff5cd 100644
--- a/src/Layout.cpp
+++ b/src/Layout.cpp
@@ -936,6 +936,7 @@ void Layout::readArgument(Lexer & lex)
        // writeArgument() makes use of these default values
        arg.mandatory = false;
        arg.autoinsert = false;
+       arg.insertcotext = false;
        bool error = false;
        bool finished = false;
        arg.font = inherit_font;
@@ -965,6 +966,9 @@ void Layout::readArgument(Lexer & lex)
                } else if (tok == "autoinsert") {
                        lex.next();
                        arg.autoinsert = lex.getBool();
+               } else if (tok == "insertcotext") {
+                       lex.next();
+                       arg.insertcotext = lex.getBool();
                } else if (tok == "leftdelim") {
                        lex.next();
                        arg.ldelim = lex.getDocString();
@@ -1024,6 +1028,8 @@ void writeArgument(ostream & os, string const & id, 
Layout::latexarg const & arg
                os << "\t\tMandatory " << arg.mandatory << '\n';
        if (arg.autoinsert)
                os << "\t\tAutoinsert " << arg.autoinsert << '\n';
+       if (arg.insertcotext)
+               os << "\t\tInsertCotext " << arg.insertcotext << '\n';
        if (!arg.ldelim.empty())
                os << "\t\tLeftDelim \""
                   << to_utf8(subst(arg.ldelim, from_ascii("\n"), 
from_ascii("<br/>")))
diff --git a/src/Layout.h b/src/Layout.h
index a458f2f..b18271a 100644
--- a/src/Layout.h
+++ b/src/Layout.h
@@ -104,6 +104,7 @@ public:
                FontInfo font;
                FontInfo labelfont;
                bool autoinsert;
+               bool insertcotext;
                docstring pass_thru_chars;
        };
        ///
diff --git a/src/Text3.cpp b/src/Text3.cpp
index f80bde6..3d73e1e 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -266,6 +266,35 @@ static bool doInsertInset(Cursor & cur, Text * text,
                }
                return true;
        }
+       else if (cmd.action() == LFUN_ARGUMENT_INSERT) {
+               bool cotextinsert = false;
+               InsetArgument const * const ia = static_cast<InsetArgument 
const *>(inset);
+               Layout const & lay = cur.paragraph().layout();
+               Layout::LaTeXArgMap args = lay.args();
+               Layout::LaTeXArgMap::const_iterator const lait = 
args.find(ia->name());
+               if (lait != args.end())
+                       cotextinsert = (*lait).second.insertcotext;
+               // The argument requests to insert a copy of the co-text to the 
inset
+               if (cotextinsert) {
+                       docstring ds;
+                       // If we have a selection within a paragraph, use this
+                       if (cur.selection() && cur.selBegin().pit() == 
cur.selEnd().pit())
+                               ds = cur.selectionAsString(false);
+                       // else use the whole paragraph
+                       else
+                               ds = cur.paragraph().asString();
+                       text->insertInset(cur, inset);
+                       if (edit)
+                               inset->edit(cur, true);
+                       // Now put co-text into inset
+                       Font const f(inherit_font, cur.current_font.language());
+                       if (!ds.empty()) {
+                               cur.text()->insertStringAsLines(cur, ds, f);
+                               cur.leaveInset(*inset);
+                       }
+                       return true;
+               }
+       }
 
        bool gotsel = false;
        if (cur.selection()) {
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
index de8ee9e..468f728 100644
--- a/src/insets/InsetLayout.cpp
+++ b/src/insets/InsetLayout.cpp
@@ -564,6 +564,7 @@ void InsetLayout::readArgument(Lexer & lex)
        Layout::latexarg arg;
        arg.mandatory = false;
        arg.autoinsert = false;
+       arg.insertcotext = false;
        bool error = false;
        bool finished = false;
        arg.font = inherit_font;
@@ -591,6 +592,9 @@ void InsetLayout::readArgument(Lexer & lex)
                } else if (tok == "autoinsert") {
                        lex.next();
                        arg.autoinsert = lex.getBool();
+               } else if (tok == "insertcotext") {
+                       lex.next();
+                       arg.insertcotext = lex.getBool();
                } else if (tok == "leftdelim") {
                        lex.next();
                        arg.ldelim = lex.getDocString();

Reply via email to