commit fb9a866a6666be093b7b12a3ad8e7f83bfc3b3f3
Author: Juergen Spitzmueller <[email protected]>
Date: Fri Oct 21 10:39:55 2016 +0200
Implement PassThru option to arguments.
---
lib/doc/Customization.lyx | 54 ++++++++++++++++++++++++++++++++++++++++++
lib/scripts/layout2layout.py | 7 ++++-
src/Layout.cpp | 21 ++++++++++++++++
src/Layout.h | 1 +
src/LayoutEnums.h | 10 +++++++
src/TextClass.cpp | 2 +-
src/insets/InsetArgument.cpp | 28 ++++++++++++++-------
src/insets/InsetArgument.h | 6 ++++-
src/insets/InsetLayout.cpp | 10 +++++++
src/insets/InsetText.cpp | 2 +-
10 files changed, 127 insertions(+), 14 deletions(-)
diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index 851146e..abc8dbc 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -122,6 +122,7 @@ logicalmkup
\html_math_output 0
\html_css_as_file 0
\html_be_strict true
+\author -712698321 "Jürgen Spitzmüller"
\author 2089657418 "Usti"
\end_header
@@ -11385,6 +11386,59 @@ status collapsed
, this argument will be inserted with a copy of the co-text (either selected
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
\begin_layout Itemize
diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py
index 753ef5e..c0829e6 100644
--- a/lib/scripts/layout2layout.py
+++ b/lib/scripts/layout2layout.py
@@ -11,7 +11,7 @@
# This script will update a .layout file to current format
# The latest layout format is also defined in src/TextClass.cpp
-currentFormat = 61
+currentFormat = 62
# Incremented to format 4, 6 April 2007, lasgouttes
@@ -205,6 +205,9 @@ currentFormat = 61
# Incremented to format 61, 14 October 2016 by spitz
# 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
# Manual (section "Declaring a new text class").
@@ -448,7 +451,7 @@ def convert(lines, end_format):
i += 1
continue
- if format == 60:
+ if format >= 60 and format <= 61:
# nothing to do.
i += 1
continue
diff --git a/src/Layout.cpp b/src/Layout.cpp
index 7893c5f..b967477 100644
--- a/src/Layout.cpp
+++ b/src/Layout.cpp
@@ -981,6 +981,7 @@ void Layout::readArgument(Lexer & lex)
arg.font = inherit_font;
arg.labelfont = inherit_font;
arg.is_toc_caption = false;
+ arg.passthru = PT_INHERITED;
string id;
lex >> id;
bool const itemarg = prefixIs(id, "item:");
@@ -1041,6 +1042,15 @@ void Layout::readArgument(Lexer & lex)
} else if (tok == "passthruchars") {
lex.next();
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") {
lex.next();
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);
if (arg.labelfont != inherit_font)
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())
os << "\t\tPassThruChars \"" << to_utf8(arg.pass_thru_chars) <<
"\"\n";
os << "\tEndArgument\n";
diff --git a/src/Layout.h b/src/Layout.h
index 5f964f8..184711b 100644
--- a/src/Layout.h
+++ b/src/Layout.h
@@ -105,6 +105,7 @@ public:
FontInfo labelfont;
bool autoinsert;
bool insertcotext;
+ ArgPassThru passthru;
docstring pass_thru_chars;
bool is_toc_caption;
};
diff --git a/src/LayoutEnums.h b/src/LayoutEnums.h
index 8bb206c..969ad1d 100644
--- a/src/LayoutEnums.h
+++ b/src/LayoutEnums.h
@@ -150,6 +150,16 @@ enum EndLabelType {
END_LABEL_STATIC
};
+///
+enum ArgPassThru {
+ ///
+ PT_INHERITED,
+ ///
+ PT_FALSE,
+ ///
+ PT_TRUE
+};
+
} // namespace lyx
#endif
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index 2db8ee2..46a96e4 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -61,7 +61,7 @@ namespace lyx {
// You should also run the development/tools/updatelayouts.py script,
// 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
diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp
index 821fbbc..70dc995 100644
--- a/src/insets/InsetArgument.cpp
+++ b/src/insets/InsetArgument.cpp
@@ -41,7 +41,8 @@ namespace lyx {
InsetArgument::InsetArgument(Buffer * buf, string const & name)
: InsetCollapsable(buf), name_(name), labelstring_(docstring()),
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)
{
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();
if (insetlayout) {
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)
@@ -115,6 +116,19 @@ void InsetArgument::updateBuffer(ParIterator const & it,
UpdateType utype)
labelfont_ = (*lait).second.labelfont;
decoration_ = (*lait).second.decoration;
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 {
labelstring_ = _("Unknown Argument");
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
// fixParagraphsFont(), which does not play nicely with
// inherited pass_thru (see #8471).
- // FIXME: Once we have implemented genuine pass_thru
- // option for InsetArgument (not inherited pass_thru),
- // we should probably directly call
- // InsetCollapsable::doDispatch(cur, cmd) for that
- // case as well
- if (pass_thru_)
+ if (pass_thru_ && !pass_thru_local_)
text().dispatch(cur, cmd);
else
InsetCollapsable::doDispatch(cur, cmd);
@@ -281,6 +290,7 @@ void InsetArgument::latexArgument(otexstream & os,
OutputParams runparams = runparams_in;
if (!pass_thru_chars_.empty())
runparams.pass_thru_chars += pass_thru_chars_;
+ runparams.pass_thru = isPassThru();
InsetText::latex(ots, runparams);
TexString ts = ots.release();
bool const add_braces = ldelim != "{" && support::contains(ts.str,
rdelim);
diff --git a/src/insets/InsetArgument.h b/src/insets/InsetArgument.h
index 5c4701d..0a5d000 100644
--- a/src/insets/InsetArgument.h
+++ b/src/insets/InsetArgument.h
@@ -97,7 +97,11 @@ private:
FontInfo labelfont_;
///
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_;
///
docstring pass_thru_chars_;
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
index 3c4fc9b..b27963d 100644
--- a/src/insets/InsetLayout.cpp
+++ b/src/insets/InsetLayout.cpp
@@ -584,6 +584,7 @@ void InsetLayout::readArgument(Lexer & lex)
arg.font = inherit_font;
arg.labelfont = inherit_font;
arg.is_toc_caption = false;
+ arg.passthru = PT_INHERITED;
string nr;
lex >> nr;
bool const postcmd = prefixIs(nr, "post:");
@@ -642,6 +643,15 @@ void InsetLayout::readArgument(Lexer & lex)
} else if (tok == "passthruchars") {
lex.next();
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") {
lex.next();
arg.is_toc_caption = lex.getBool();
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index 41427ce..1c3689f 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -290,7 +290,7 @@ void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd)
LYXERR(Debug::ACTION, "InsetText::doDispatch(): cmd: " << cmd);
// See bug #9042, for instance.
- if (isPassThru() && lyxCode() != ARG_CODE) {
+ if (isPassThru()) {
// Force any new text to latex_language FIXME: This
// should only be necessary in constructor, but new
// paragraphs that are created by pressing enter at