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
This commit is contained in:
Juergen Spitzmueller 2015-05-09 12:17:24 +02:00
parent be040c4469
commit 760b7cf2b6
5 changed files with 83 additions and 1 deletions

View 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

View 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/>")))

View File

@ -104,6 +104,7 @@ public:
FontInfo font;
FontInfo labelfont;
bool autoinsert;
bool insertcotext;
docstring pass_thru_chars;
};
///

View 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()) {

View 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();