]> git.lyx.org Git - lyx.git/commitdiff
Add option to Argument to let it be inserted with a copy of the co-text.
authorJuergen Spitzmueller <spitz@lyx.org>
Sat, 9 May 2015 10:17:24 +0000 (12:17 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Sat, 9 May 2015 10:17:24 +0000 (12:17 +0200)
This is useful for classic "Short Titles", where one might want to start
with the full title in the inset.

Addresses: #4745

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

index e702b517c0a2305bf83e755664566a752e84b585..dc4dbb7b4dd2e2ca1638f856b9cd4eab104a0dd1 100644 (file)
@@ -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
index cb1f69bf8d65c616eeb0354b566bde6e7fdcb768..60ff5cd043a2c7aee9afdb8976f8a8e821d3b9a4 100644 (file)
@@ -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/>")))
index a458f2f6dc07619faa180273f6e3fa78c22b6924..b18271a0a5c56afd40a7c38863d15592f64636ae 100644 (file)
@@ -104,6 +104,7 @@ public:
                FontInfo font;
                FontInfo labelfont;
                bool autoinsert;
+               bool insertcotext;
                docstring pass_thru_chars;
        };
        ///
index f80bde6554d38c8fe10b5f0c9aaaec32fbec7aa1..3d73e1ef66eccbbfbfdca83dce4ec233502ea728 100644 (file)
@@ -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()) {
index de8ee9e0083c76cebada2f12ea27c766c4f988fe..468f7286bd274e63586b4b867f8ea3da8ac7b09b 100644 (file)
@@ -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();