Implement PassThru option to arguments.

This commit is contained in:
Juergen Spitzmueller 2016-10-21 10:39:55 +02:00
parent e37e4f537c
commit fb9a866a66
10 changed files with 127 additions and 14 deletions

View File

@ -122,6 +122,7 @@ logicalmkup
\html_math_output 0 \html_math_output 0
\html_css_as_file 0 \html_css_as_file 0
\html_be_strict true \html_be_strict true
\author -712698321 "Jürgen Spitzmüller"
\author 2089657418 "Usti" \author 2089657418 "Usti"
\end_header \end_header
@ -11385,6 +11386,59 @@ status collapsed
, this argument will be inserted with a copy of the co-text (either selected , this argument will be inserted with a copy of the co-text (either selected
text or the whole paragraph) as content. text or the whole paragraph) as content.
\change_inserted -712698321 1477038290
\end_layout
\begin_layout Itemize
\change_inserted -712698321 1477038425
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1477038295
PassThru
\end_layout
\end_inset
[
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1477038311
\emph on
inherited
\emph default
, true, false
\end_layout
\end_inset
] Whether the contents of this argument should be output in raw form, meaning
without special translations that \SpecialChar LaTeX
would require.
By default, the
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1477038356
PassThru
\end_layout
\end_inset
status is inherited by the inset or paragraph layout the argument belongs
to, true and false change the status for the given argument only.
\change_unchanged
\end_layout \end_layout
\begin_layout Itemize \begin_layout Itemize

View File

@ -11,7 +11,7 @@
# This script will update a .layout file to current format # This script will update a .layout file to current format
# The latest layout format is also defined in src/TextClass.cpp # The latest layout format is also defined in src/TextClass.cpp
currentFormat = 61 currentFormat = 62
# Incremented to format 4, 6 April 2007, lasgouttes # Incremented to format 4, 6 April 2007, lasgouttes
@ -205,6 +205,9 @@ currentFormat = 61
# Incremented to format 61, 14 October 2016 by spitz # Incremented to format 61, 14 October 2016 by spitz
# New Layout tags "ResumeCounter", "StepMasterCounter" # New Layout tags "ResumeCounter", "StepMasterCounter"
# Incremented to format 62, 21 October 2016 by spitz
# New Layout argument tag "PassThru"
# Do not forget to document format change in Customization # Do not forget to document format change in Customization
# Manual (section "Declaring a new text class"). # Manual (section "Declaring a new text class").
@ -448,7 +451,7 @@ def convert(lines, end_format):
i += 1 i += 1
continue continue
if format == 60: if format >= 60 and format <= 61:
# nothing to do. # nothing to do.
i += 1 i += 1
continue continue

View File

@ -981,6 +981,7 @@ void Layout::readArgument(Lexer & lex)
arg.font = inherit_font; arg.font = inherit_font;
arg.labelfont = inherit_font; arg.labelfont = inherit_font;
arg.is_toc_caption = false; arg.is_toc_caption = false;
arg.passthru = PT_INHERITED;
string id; string id;
lex >> id; lex >> id;
bool const itemarg = prefixIs(id, "item:"); bool const itemarg = prefixIs(id, "item:");
@ -1041,6 +1042,15 @@ void Layout::readArgument(Lexer & lex)
} else if (tok == "passthruchars") { } else if (tok == "passthruchars") {
lex.next(); lex.next();
arg.pass_thru_chars = lex.getDocString(); arg.pass_thru_chars = lex.getDocString();
} else if (tok == "passthru") {
lex.next();
docstring value = lex.getDocString();
if (value == "true" || value == "1")
arg.passthru = PT_TRUE;
else if (value == "false" || value == "0")
arg.passthru = PT_FALSE;
else
arg.passthru = PT_INHERITED;
} else if (tok == "istoccaption") { } else if (tok == "istoccaption") {
lex.next(); lex.next();
arg.is_toc_caption = lex.getBool(); arg.is_toc_caption = lex.getBool();
@ -1095,6 +1105,17 @@ void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg
lyxWrite(os, arg.font, "Font", 2); lyxWrite(os, arg.font, "Font", 2);
if (arg.labelfont != inherit_font) if (arg.labelfont != inherit_font)
lyxWrite(os, arg.labelfont, "LabelFont", 2); lyxWrite(os, arg.labelfont, "LabelFont", 2);
switch (arg.passthru) {
case PT_TRUE:
os << "\t\tPassThru true\n";
break;
case PT_FALSE:
os << "\t\tPassThru false\n";
break;
case PT_INHERITED:
os << "\t\tPassThru inherited\n";
break;
}
if (!arg.pass_thru_chars.empty()) if (!arg.pass_thru_chars.empty())
os << "\t\tPassThruChars \"" << to_utf8(arg.pass_thru_chars) << "\"\n"; os << "\t\tPassThruChars \"" << to_utf8(arg.pass_thru_chars) << "\"\n";
os << "\tEndArgument\n"; os << "\tEndArgument\n";

View File

@ -105,6 +105,7 @@ public:
FontInfo labelfont; FontInfo labelfont;
bool autoinsert; bool autoinsert;
bool insertcotext; bool insertcotext;
ArgPassThru passthru;
docstring pass_thru_chars; docstring pass_thru_chars;
bool is_toc_caption; bool is_toc_caption;
}; };

View File

@ -150,6 +150,16 @@ enum EndLabelType {
END_LABEL_STATIC END_LABEL_STATIC
}; };
///
enum ArgPassThru {
///
PT_INHERITED,
///
PT_FALSE,
///
PT_TRUE
};
} // namespace lyx } // namespace lyx
#endif #endif

View File

@ -61,7 +61,7 @@ namespace lyx {
// You should also run the development/tools/updatelayouts.py script, // You should also run the development/tools/updatelayouts.py script,
// to update the format of all of our layout files. // to update the format of all of our layout files.
// //
int const LAYOUT_FORMAT = 61; //spitz ResumeCounter, StepMasterCounter int const LAYOUT_FORMAT = 62; //spitz PassThru for arguments.
// Layout format for the current lyx file format. Controls which format is // Layout format for the current lyx file format. Controls which format is

View File

@ -41,7 +41,8 @@ namespace lyx {
InsetArgument::InsetArgument(Buffer * buf, string const & name) InsetArgument::InsetArgument(Buffer * buf, string const & name)
: InsetCollapsable(buf), name_(name), labelstring_(docstring()), : InsetCollapsable(buf), name_(name), labelstring_(docstring()),
font_(inherit_font), labelfont_(inherit_font), decoration_(string()), font_(inherit_font), labelfont_(inherit_font), decoration_(string()),
pass_thru_(false), pass_thru_chars_(docstring()) pass_thru_context_(false), pass_thru_local_(false), pass_thru_(false),
pass_thru_chars_(docstring())
{} {}
@ -62,11 +63,11 @@ void InsetArgument::read(Lexer & lex)
void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype) void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype)
{ {
Layout::LaTeXArgMap args = it.paragraph().layout().args(); Layout::LaTeXArgMap args = it.paragraph().layout().args();
pass_thru_ = it.paragraph().layout().pass_thru; pass_thru_context_ = it.paragraph().layout().pass_thru;
bool const insetlayout = args.empty(); bool const insetlayout = args.empty();
if (insetlayout) { if (insetlayout) {
args = it.inset().getLayout().args(); args = it.inset().getLayout().args();
pass_thru_ = it.inset().getLayout().isPassThru(); pass_thru_context_ = it.inset().getLayout().isPassThru();
} }
// Handle pre 2.1 ArgInsets (lyx2lyx cannot classify them) // Handle pre 2.1 ArgInsets (lyx2lyx cannot classify them)
@ -115,6 +116,19 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype)
labelfont_ = (*lait).second.labelfont; labelfont_ = (*lait).second.labelfont;
decoration_ = (*lait).second.decoration; decoration_ = (*lait).second.decoration;
pass_thru_chars_ = (*lait).second.pass_thru_chars; pass_thru_chars_ = (*lait).second.pass_thru_chars;
pass_thru_local_ = false;
switch ((*lait).second.passthru) {
case PT_INHERITED:
pass_thru_ = pass_thru_context_;
break;
case PT_TRUE:
pass_thru_ = true;
pass_thru_local_ = true;
break;
case PT_FALSE:
pass_thru_ = false;
break;
}
} else { } else {
labelstring_ = _("Unknown Argument"); labelstring_ = _("Unknown Argument");
tooltip_ = _("Argument not known in this Layout. Will be supressed in the output."); tooltip_ = _("Argument not known in this Layout. Will be supressed in the output.");
@ -165,12 +179,7 @@ void InsetArgument::doDispatch(Cursor & cur, FuncRequest & cmd)
// with (inherited) pass_thru to avoid call for // with (inherited) pass_thru to avoid call for
// fixParagraphsFont(), which does not play nicely with // fixParagraphsFont(), which does not play nicely with
// inherited pass_thru (see #8471). // inherited pass_thru (see #8471).
// FIXME: Once we have implemented genuine pass_thru if (pass_thru_ && !pass_thru_local_)
// option for InsetArgument (not inherited pass_thru),
// we should probably directly call
// InsetCollapsable::doDispatch(cur, cmd) for that
// case as well
if (pass_thru_)
text().dispatch(cur, cmd); text().dispatch(cur, cmd);
else else
InsetCollapsable::doDispatch(cur, cmd); InsetCollapsable::doDispatch(cur, cmd);
@ -281,6 +290,7 @@ void InsetArgument::latexArgument(otexstream & os,
OutputParams runparams = runparams_in; OutputParams runparams = runparams_in;
if (!pass_thru_chars_.empty()) if (!pass_thru_chars_.empty())
runparams.pass_thru_chars += pass_thru_chars_; runparams.pass_thru_chars += pass_thru_chars_;
runparams.pass_thru = isPassThru();
InsetText::latex(ots, runparams); InsetText::latex(ots, runparams);
TexString ts = ots.release(); TexString ts = ots.release();
bool const add_braces = ldelim != "{" && support::contains(ts.str, rdelim); bool const add_braces = ldelim != "{" && support::contains(ts.str, rdelim);

View File

@ -97,7 +97,11 @@ private:
FontInfo labelfont_; FontInfo labelfont_;
/// ///
std::string decoration_; std::string decoration_;
/// /// Are we in a pass-thru context?
bool pass_thru_context_;
/// Is the argument itself have an explicitly pass-thru?
bool pass_thru_local_;
/// Effective pass-thru setting (inherited or local)
bool pass_thru_; bool pass_thru_;
/// ///
docstring pass_thru_chars_; docstring pass_thru_chars_;

View File

@ -584,6 +584,7 @@ void InsetLayout::readArgument(Lexer & lex)
arg.font = inherit_font; arg.font = inherit_font;
arg.labelfont = inherit_font; arg.labelfont = inherit_font;
arg.is_toc_caption = false; arg.is_toc_caption = false;
arg.passthru = PT_INHERITED;
string nr; string nr;
lex >> nr; lex >> nr;
bool const postcmd = prefixIs(nr, "post:"); bool const postcmd = prefixIs(nr, "post:");
@ -642,6 +643,15 @@ void InsetLayout::readArgument(Lexer & lex)
} else if (tok == "passthruchars") { } else if (tok == "passthruchars") {
lex.next(); lex.next();
arg.pass_thru_chars = lex.getDocString(); arg.pass_thru_chars = lex.getDocString();
} else if (tok == "passthru") {
lex.next();
docstring value = lex.getDocString();
if (value == "true" || value == "1")
arg.passthru = PT_TRUE;
else if (value == "false" || value == "0")
arg.passthru = PT_FALSE;
else
arg.passthru = PT_INHERITED;
} else if (tok == "istoccaption") { } else if (tok == "istoccaption") {
lex.next(); lex.next();
arg.is_toc_caption = lex.getBool(); arg.is_toc_caption = lex.getBool();

View File

@ -290,7 +290,7 @@ void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd)
LYXERR(Debug::ACTION, "InsetText::doDispatch(): cmd: " << cmd); LYXERR(Debug::ACTION, "InsetText::doDispatch(): cmd: " << cmd);
// See bug #9042, for instance. // See bug #9042, for instance.
if (isPassThru() && lyxCode() != ARG_CODE) { if (isPassThru()) {
// Force any new text to latex_language FIXME: This // Force any new text to latex_language FIXME: This
// should only be necessary in constructor, but new // should only be necessary in constructor, but new
// paragraphs that are created by pressing enter at // paragraphs that are created by pressing enter at