]> git.lyx.org Git - lyx.git/blobdiff - src/Layout.cpp
Fix external middle-mouse pasting with Qt5/X11.
[lyx.git] / src / Layout.cpp
index 5ac163a532fd1d9e51611645bba72787bd62b32f..bb312877667c50908779db6ebdca0d727aafd446 100644 (file)
@@ -104,6 +104,8 @@ enum LayoutTags {
        LT_REFPREFIX,
        LT_RESETARGS,
        LT_RIGHTDELIM,
+       LT_FORCELOCAL,
+       LT_TOGGLE_INDENT,
        LT_INTITLE // keep this last!
 };
 
@@ -145,11 +147,33 @@ Layout::Layout()
        htmlforcecss_ = false;
        htmltitle_ = false;
        spellcheck = true;
+       forcelocal = 0;
        itemcommand_ = "item";
+       toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
 }
 
 
 bool Layout::read(Lexer & lex, TextClass const & tclass)
+{
+       // If this is an empty layout, or if no force local version is set,
+       // we know that we will not discard the stuff to read
+       if (forcelocal == 0)
+               return readIgnoreForcelocal(lex, tclass);
+       Layout tmp(*this);
+       tmp.forcelocal = 0;
+       bool const ret = tmp.readIgnoreForcelocal(lex, tclass);
+       // Keep the stuff if
+       // - the read version is higher
+       // - both versions are infinity (arbitrary decision)
+       // - the file did not contain any local version (needed for not
+       //   skipping user defined local layouts)
+       if (tmp.forcelocal <= 0 || tmp.forcelocal > forcelocal)
+               *this = tmp;
+       return ret;
+}
+
+
+bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 {
        // This table is sorted alphabetically [asierra 30March96]
        LexerKeyword layoutTags[] = {
@@ -166,6 +190,7 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
                { "endlabelstring", LT_ENDLABELSTRING },
                { "endlabeltype",   LT_ENDLABELTYPE },
                { "font",           LT_FONT },
+               { "forcelocal",     LT_FORCELOCAL },
                { "freespacing",    LT_FREE_SPACING },
                { "htmlattr",       LT_HTMLATTR },
                { "htmlforcecss",   LT_HTMLFORCECSS },
@@ -220,6 +245,7 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
                { "spellcheck",     LT_SPELLCHECK },
                { "textfont",       LT_TEXTFONT },
                { "toclevel",       LT_TOCLEVEL },
+               { "toggleindent",   LT_TOGGLE_INDENT },
                { "topsep",         LT_TOPSEP }
        };
 
@@ -360,6 +386,19 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
                        lex >> nextnoindent;
                        break;
 
+               case LT_TOGGLE_INDENT: {
+                       string tog;
+                       lex >> tog;
+                       tog = support::ascii_lowercase(tog);
+                       if (tog == "always")
+                               toggle_indent = ITOGGLE_ALWAYS;
+                       else if (tog == "never")
+                               toggle_indent = ITOGGLE_NEVER;
+                       else
+                               toggle_indent = ITOGGLE_DOCUMENT_DEFAULT;
+                       break;
+               }
+
                case LT_COMMANDDEPTH:
                        lex >> commanddepth;
                        break;
@@ -582,6 +621,10 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
                case LT_SPELLCHECK:
                        lex >> spellcheck;
                        break;
+
+               case LT_FORCELOCAL:
+                       lex >> forcelocal;
+                       break;
                }
        }
        lex.popTable();
@@ -748,6 +791,8 @@ void Layout::readLabelType(Lexer & lex)
 
 void Layout::readEndLabelType(Lexer & lex)
 {
+       // this should be const, but can't be because
+       // of PushPopHelper.
        static LexerKeyword endlabelTypeTags[] = {
                { "box",              END_LABEL_BOX },
                { "filled_box", END_LABEL_FILLED_BOX },
@@ -1093,17 +1138,17 @@ void Layout::write(ostream & os) const
        if (!preamble_.empty())
                os << "\tPreamble\n\t"
                   << to_utf8(subst(rtrim(preamble_, "\n"),
-                                         from_ascii("\n"), from_ascii("\n\t")))
+                                   from_ascii("\n"), from_ascii("\n\t")))
                   << "\n\tEndPreamble\n";
        if (!langpreamble_.empty())
                os << "\tLangPreamble\n\t"
                   << to_utf8(subst(rtrim(langpreamble_, "\n"),
-                                         from_ascii("\n"), from_ascii("\n\t")))
+                                   from_ascii("\n"), from_ascii("\n\t")))
                   << "\n\tEndLangPreamble\n";
        if (!babelpreamble_.empty())
                os << "\tBabelPreamble\n\t"
                   << to_utf8(subst(rtrim(babelpreamble_, "\n"),
-                                         from_ascii("\n"), from_ascii("\n\t")))
+                                   from_ascii("\n"), from_ascii("\n\t")))
                   << "\n\tEndBabelPreamble\n";
        switch (labeltype) {
        case LABEL_ABOVE:
@@ -1290,6 +1335,7 @@ void Layout::write(ostream & os) const
                   << "\n\tEndPreamble\n";
        os << "\tHTMLTitle " << htmltitle_ << "\n"
              "\tSpellcheck " << spellcheck << "\n"
+             "\tForceLocal " << forcelocal << "\n"
              "End\n";
 }
 
@@ -1477,14 +1523,11 @@ void Layout::makeDefaultCSS() const
                htmldefaultstyle_ += from_ascii(tmp);
        }
 
-// tex2lyx does not see output_xhtml.cpp
-#ifndef NO_LAYOUT_CSS
        // alignment
        string where = alignmentToCSS(align);
        if (!where.empty()) {
                htmldefaultstyle_ += from_ascii("text-align: " + where + ";\n");
        }
-#endif
 
        // wrap up what we have, if anything
        if (!htmldefaultstyle_.empty())