]> git.lyx.org Git - lyx.git/commitdiff
Implement PassThru option to arguments.
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 21 Oct 2016 08:39:55 +0000 (10:39 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 21 Oct 2016 08:39:55 +0000 (10:39 +0200)
lib/doc/Customization.lyx
lib/scripts/layout2layout.py
src/Layout.cpp
src/Layout.h
src/LayoutEnums.h
src/TextClass.cpp
src/insets/InsetArgument.cpp
src/insets/InsetArgument.h
src/insets/InsetLayout.cpp
src/insets/InsetText.cpp

index 851146e62cf9cb13c1f7835d605f1ef1ed398cf8..abc8dbc90ddff26dc150473621ce85cf8cae27f6 100644 (file)
@@ -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
index 753ef5e0c4c8713e2dfeb51e70bdfbebb30f2d53..c0829e6cd46009292d2c2c9e7f4e09b14eaced33 100644 (file)
@@ -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
index 7893c5fe7e6cd8a3d3cfa35551087fa4b3ed8e4a..b9674772e22abdcebebf72cfee6630fdedc2da65 100644 (file)
@@ -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";
index 5f964f80df421f80b3621b951514582f258554e8..184711b3b4b9c48c2af1e642b6e229b4c17fd111 100644 (file)
@@ -105,6 +105,7 @@ public:
                FontInfo labelfont;
                bool autoinsert;
                bool insertcotext;
+               ArgPassThru passthru;
                docstring pass_thru_chars;
                bool is_toc_caption;
        };
index 8bb206c6a98e46c46b4fa0b21c6970872ddbc1fa..969ad1dfffef54a12da9e0129ecf2f18a8655413 100644 (file)
@@ -150,6 +150,16 @@ enum EndLabelType {
        END_LABEL_STATIC
 };
 
+///
+enum ArgPassThru {
+       ///
+       PT_INHERITED,
+       ///
+       PT_FALSE,
+       ///
+       PT_TRUE
+};
+
 } // namespace lyx
 
 #endif
index 2db8ee2344985099199badee8c57591d9865f712..46a96e4815500b5367a3614928cd48907f38f1cd 100644 (file)
@@ -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
index 821fbbc9a52c73f6e42144cd151e2efc249fccab..70dc995699b30438dc36a229b65119b28b79c7b0 100644 (file)
@@ -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);
index 5c4701d8fcc471a1c75be6929bada882970f0bd0..0a5d00037966216410bbee395df294cf38798860 100644 (file)
@@ -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_;
index 3c4fc9bb9fce398d57e79d37a0312f0f67987098..b27963d88efa388bf2bc42d6115b5a8bee0d4ddf 100644 (file)
@@ -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();
index 41427ce7c3326c22838e4842a400bf8329cd7015..1c3689f627d81c1be78248329b45aad95c721913 100644 (file)
@@ -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