]> git.lyx.org Git - lyx.git/commitdiff
Layout format update: AddToToc, IsTocCaption, OutlinerName
authorGuillaume Munch <gm@lyx.org>
Tue, 3 Nov 2015 16:47:25 +0000 (11:47 -0500)
committerGuillaume Munch <gm@lyx.org>
Sun, 13 Dec 2015 19:56:49 +0000 (19:56 +0000)
Preliminary work for addressing #7790. Thanks to Richard for providing initial
files this is based on.

Adding to TextClass:
    OutlinerName <string> <string>
    (the second string is translated)
e.g.:
    OutlinerName thm "Definitions & Theorems"

Adding to Layout:
    AddToToc <string>     (default "", means no)
    IsTocCaption <bool>   (default 0)
e.g.:
    AddToToc thm
    IsTocCaption 1

Adding to InsetLayout:
    AddToToc <string>     (default "", means no)
    IsTocCaption <bool>   (default 0)
e.g.:
    AddToToc literate

Adding to inset arguments:
    IsTocCaption <bool>   (default 0)

lib/scripts/layout2layout.py
po/lyx_pot.py
src/Layout.cpp
src/Layout.h
src/TextClass.cpp
src/TextClass.h
src/TocBackend.cpp
src/TocBackend.h
src/insets/InsetLayout.cpp
src/insets/InsetLayout.h

index 48a1e03f213b8f31cda58b6ce239ec04aa444527..a87c300a8872af3725444f85e0da768d5364b9e0 100644 (file)
@@ -193,6 +193,11 @@ import os, re, string, sys
 # New Layout tag "ProvideStyle"
 # Change "IfStyle" to "ModifyStyle"
 
+# Incremented to format 59, 22 November 2015 by gm
+# New Tag "OutlinerName"
+# New Layout tags "AddToToc", "IsTocCaption"
+# New Layout argument tag "IsTocCaption"
+
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
 
@@ -200,7 +205,7 @@ import os, re, string, sys
 # development/tools/updatelayouts.py script to update all
 # layout files to the new format.
 
-currentFormat = 58
+currentFormat = 59
 
 
 def usage(prog_name):
@@ -425,6 +430,10 @@ def convert(lines):
                 i += 1
             continue
 
+        if format == 58:
+            # nothing to do.
+            i += 1
+            continue
 
         if format == 57:
             match = re_IfStyle.match(lines[i])
index c92939c9b90e4fabaacdbc443b96fa295c77399a..432a126056886743bf16d8eace43eb8b59f0fddf 100755 (executable)
@@ -84,6 +84,7 @@ def layouts_l10n(input_files, output, base, layouttranslations):
     # match LabelString, EndLabelString, LabelStringAppendix and maybe others but no comments
     LabelString = re.compile(r'^[^#]*LabelString\S*\s+(.*\S)\s*$', re.IGNORECASE)
     MenuString = re.compile(r'^[^#]*MenuString\S*\s+(.*\S)\s*$', re.IGNORECASE)
+    OutlinerName = re.compile(r'^[^#]*OutlinerName\s+(\S+|\"[^\"]*\")\s+(\S+|\"[^\"]*\")\s*$', re.IGNORECASE)
     Tooltip = re.compile(r'^\s*Tooltip\S*\s+(.*\S)\s*$', re.IGNORECASE)
     GuiName = re.compile(r'^\s*GuiName\s+(.*\S)\s*$', re.IGNORECASE)
     ListName = re.compile(r'^\s*ListName\s+(.*\S)\s*$', re.IGNORECASE)
@@ -250,6 +251,12 @@ def layouts_l10n(input_files, output, base, layouttranslations):
                 if not layouttranslations:
                     writeString(out, src, base, lineno, string)
                 continue
+            res = OutlinerName.search(line)
+            if res != None:
+                string = res.group(2)
+                if not layouttranslations:
+                    writeString(out, src, base, lineno, string)
+                continue
             res = Tooltip.search(line)
             if res != None:
                 string = res.group(1)
index 0fdb3412e7ed5b3c4eb6c153cbf54a5576e6f29d..db8c317764797306dd098b7e58958c7b05c9b9d9 100644 (file)
@@ -108,12 +108,15 @@ enum LayoutTags {
        LT_RIGHTDELIM,
        LT_FORCELOCAL,
        LT_TOGGLE_INDENT,
+       LT_ADDTOTOC,
+       LT_ISTOCCAPTION,
        LT_INTITLE // keep this last!
 };
 
 /////////////////////
 
 Layout::Layout()
+       : add_to_toc_(false), is_toc_caption_(false)
 {
        unknown_ = false;
        margintype = MARGIN_STATIC;
@@ -180,6 +183,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 {
        // This table is sorted alphabetically [asierra 30March96]
        LexerKeyword layoutTags[] = {
+               { "addtotoc",       LT_ADDTOTOC },
                { "align",          LT_ALIGN },
                { "alignpossible",  LT_ALIGNPOSSIBLE },
                { "argument",       LT_ARGUMENT },
@@ -209,6 +213,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                { "innertag",       LT_INNERTAG },
                { "inpreamble",     LT_INPREAMBLE },
                { "intitle",        LT_INTITLE },
+               { "istoccaption",   LT_ISTOCCAPTION },
                { "itemcommand",    LT_ITEMCOMMAND },
                { "itemsep",        LT_ITEMSEP },
                { "itemtag",        LT_ITEMTAG },
@@ -638,6 +643,16 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                case LT_FORCELOCAL:
                        lex >> forcelocal;
                        break;
+
+               case LT_ADDTOTOC:
+                       lex >> toc_type_;
+                       add_to_toc_ = !toc_type_.empty();
+                       break;
+
+               case LT_ISTOCCAPTION:
+                       lex >> is_toc_caption_;
+                       break;
+
                }
        }
        lex.popTable();
@@ -951,6 +966,7 @@ void Layout::readArgument(Lexer & lex)
        bool finished = false;
        arg.font = inherit_font;
        arg.labelfont = inherit_font;
+       arg.is_toc_caption = false;
        string id;
        lex >> id;
        bool const itemarg = prefixIs(id, "item:");
@@ -1011,6 +1027,9 @@ void Layout::readArgument(Lexer & lex)
                } else if (tok == "passthruchars") {
                        lex.next();
                        arg.pass_thru_chars = lex.getDocString();
+               } else if (tok == "istoccaption") {
+                       lex.next();
+                       arg.is_toc_caption = lex.getBool();
                } else {
                        lex.printError("Unknown tag");
                        error = true;
index 091e319cb1d02830ae3bd62ce5cfdfbb38f6d530..273a36155bbedbfeb10124980993a7808737fb5b 100644 (file)
@@ -106,6 +106,7 @@ public:
                bool autoinsert;
                bool insertcotext;
                docstring pass_thru_chars;
+               bool is_toc_caption;
        };
        ///
        typedef std::map<std::string, latexarg> LaTeXArgMap;
@@ -203,6 +204,12 @@ public:
                        || labeltype == LABEL_CENTERED
                  || labeltype == LABEL_BIBLIO;
        }
+       ///
+       bool addToToc() const { return add_to_toc_; }
+       ///
+       std::string tocType() const { return toc_type_; }
+       ///
+       bool isTocCaption() const { return is_toc_caption_; }
 
        ///
        bool operator==(Layout const &) const;
@@ -459,8 +466,15 @@ private:
        LaTeXArgMap postcommandargs_;
        ///
        LaTeXArgMap itemargs_;
+       ///
+       bool add_to_toc_;
+       ///
+       std::string toc_type_;
+       ///
+       bool is_toc_caption_;
 };
 
+
 } // namespace lyx
 
 #endif
index 0ee74a7b50449852bcaf24ee3f7fe43215d31f97..c6f3ee0daf41b5fd55cf6ca97d0b6d7e7136a191 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 = 58; // rgh: ProvideStyle
+int const LAYOUT_FORMAT = 59; //gm: OutlinerName, AddToToc, IsTocCaption
 
 namespace {
 
@@ -213,7 +213,8 @@ enum TextClassTags {
        TC_CITEENGINETYPE,
        TC_CITEFORMAT,
        TC_DEFAULTBIBLIO,
-       TC_FULLAUTHORLIST
+       TC_FULLAUTHORLIST,
+       TC_OUTLINERNAME
 };
 
 
@@ -249,6 +250,7 @@ LexerKeyword textClassTags[] = {
        { "nofloat",           TC_NOFLOAT },
        { "noinsetlayout",     TC_NOINSETLAYOUT },
        { "nostyle",           TC_NOSTYLE },
+       { "outlinername",      TC_OUTLINERNAME },
        { "outputformat",      TC_OUTPUTFORMAT },
        { "outputtype",        TC_OUTPUTTYPE },
        { "packageoptions",    TC_PKGOPTS },
@@ -801,6 +803,10 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                                floatlist_.erase(nofloat);
                        }
                        break;
+
+               case TC_OUTLINERNAME:
+                       error = !readOutlinerName(lexrc);
+                       break;
                } // end of switch
 
                // Note that this is triggered the first time through the loop unless
@@ -1295,6 +1301,39 @@ bool TextClass::readFloat(Lexer & lexrc)
 }
 
 
+bool TextClass::readOutlinerName(Lexer & lexrc)
+{
+       std::string type;
+       docstring name;
+       if (lexrc.next())
+               type = lexrc.getString();
+       else {
+               lexrc.printError("No type given for OutlinerName: `$$Token'.");
+               return false;
+       }
+       if (lexrc.next())
+               name = lexrc.getDocString();
+       else {
+               lexrc.printError("No name given for OutlinerName: `$$Token'.");
+               return false;
+       }
+       outliner_names_[type] = name;
+    return true;
+}
+
+
+docstring TextClass::outlinerName(std::string const & type) const
+{
+       std::map<std::string,docstring>::const_iterator const it
+               = outliner_names_.find(type);
+       if (it == outliner_names_.end()) {
+               LYXERR0("Missing OutlinerName for " << type << "!");
+               return from_utf8(type);
+       } else
+               return it->second;
+}
+
+
 string const & TextClass::prerequisites(string const & sep) const
 {
        if (contains(prerequisites_, ',')) {
index 0a075dd6c588c778f5ff8ec407729072c64a3513..94fe003bd80fa372fb5af73ce7323ae42861ba87 100644 (file)
@@ -199,6 +199,8 @@ public:
        OutputType outputType() const { return outputType_; }
        /// Can be latex, docbook ... (the name of a format)
        std::string outputFormat() const { return outputFormat_; }
+       ///
+       docstring outlinerName(std::string const & type) const;
 protected:
        /// Protect construction
        TextClass();
@@ -327,6 +329,8 @@ protected:
        bool cite_full_author_list_;
        /// The possible citation styles
        std::map<CiteEngineType, std::vector<CitationStyle> > cite_styles_;
+       ///
+       std::map<std::string, docstring> outliner_names_;
 private:
        ///////////////////////////////////////////////////////////////////
        // helper routines for reading layout files
@@ -359,6 +363,8 @@ private:
        int readCiteEngineType(Lexer &) const;
        ///
        bool readCiteFormat(Lexer &);
+       ///
+       bool readOutlinerName(Lexer &);
 };
 
 
index 5599e1f362313fc0e01278a7dd6282eb2309545d..9bd435f2f209283245b5ae9d7ad2ef9c7115a5ff 100644 (file)
@@ -32,6 +32,7 @@
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/docstream.h"
+#include "support/gettext.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
 
@@ -362,4 +363,11 @@ void TocBackend::writePlaintextTocList(string const & type,
 }
 
 
+docstring TocBackend::outlinerName(std::string const & type) const
+{
+       return translateIfPossible(
+           buffer_->params().documentClass().outlinerName(type));
+}
+
+
 } // namespace lyx
index e18f1bc0947f5a90062ff83ed4ca9993525f5c02..d5dfae426427cd8388ace89740d245e8db3aeb46 100644 (file)
@@ -221,6 +221,8 @@ public:
        ///
        void writePlaintextTocList(std::string const & type,
                odocstringstream & os, size_t max_length) const;
+       ///
+       docstring outlinerName(std::string const & type) const;
 
 private:
        ///
index 9e03fcb42d5f77ba70f5419a1135eea2a8f4f305..7291a60bf14fd7d9242b401b4ef7d569da2c668c 100644 (file)
@@ -44,7 +44,7 @@ InsetLayout::InsetLayout() :
        freespacing_(false), keepempty_(false), forceltr_(false),
        forceownlines_(false), needprotect_(false), intoc_(false),
        spellcheck_(true), resetsfont_(false), display_(true),
-       forcelocalfontswitch_(false)
+       forcelocalfontswitch_(false), add_to_toc_(false), is_toc_caption_(false)
 {
        labelfont_.setColor(Color_error);
 }
@@ -80,6 +80,7 @@ InsetLayout::InsetLaTeXType translateLaTeXType(std::string const & str)
 bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
 {
        enum {
+               IL_ADDTOTOC,
                IL_ARGUMENT,
                IL_BABELPREAMBLE,
                IL_BGCOLOR,
@@ -106,6 +107,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                IL_HTMLSTYLE,
                IL_HTMLPREAMBLE,
                IL_INTOC,
+               IL_ISTOCCAPTION,
                IL_LABELFONT,
                IL_LABELSTRING,
                IL_LANGPREAMBLE,
@@ -133,6 +135,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
 
 
        LexerKeyword elementTags[] = {
+               { "addtotoc", IL_ADDTOTOC },
                { "argument", IL_ARGUMENT },
                { "babelpreamble", IL_BABELPREAMBLE },
                { "bgcolor", IL_BGCOLOR },
@@ -160,6 +163,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                { "htmlstyle", IL_HTMLSTYLE },
                { "htmltag", IL_HTMLTAG },
                { "intoc", IL_INTOC },
+               { "istoccaption", IL_ISTOCCAPTION },
                { "keepempty", IL_KEEPEMPTY },
                { "labelfont", IL_LABELFONT },
                { "labelstring", IL_LABELSTRING },
@@ -454,6 +458,13 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                case IL_DISPLAY:
                        lex >> display_;
                        break;
+               case IL_ADDTOTOC:
+                       lex >> toc_type_;
+                       add_to_toc_ = !toc_type_.empty();
+                       break;
+               case IL_ISTOCCAPTION:
+                       lex >> is_toc_caption_;
+                       break;
                case IL_END:
                        getout = true;
                        break;
@@ -569,6 +580,7 @@ void InsetLayout::readArgument(Lexer & lex)
        bool finished = false;
        arg.font = inherit_font;
        arg.labelfont = inherit_font;
+       arg.is_toc_caption = false;
        string nr;
        lex >> nr;
        bool const postcmd = prefixIs(nr, "post:");
@@ -630,6 +642,9 @@ void InsetLayout::readArgument(Lexer & lex)
                } else if (tok == "passthruchars") {
                        lex.next();
                        arg.pass_thru_chars = lex.getDocString();
+               } else if (tok == "istoccaption") {
+                       lex.next();
+                       arg.is_toc_caption = lex.getBool();
                } else {
                        lex.printError("Unknown tag");
                        error = true;
index 9589fadd5e13c6f8c29900e0d7f2c06b7e3140da..c1bbe5c07371afa2b14764d9d6c0dc85de57b493 100644 (file)
@@ -181,6 +181,12 @@ public:
        bool forcelocalfontswitch() const { return forcelocalfontswitch_; }
        ///
        docstring const & obsoleted_by() const { return obsoleted_by_; }
+       ///
+       bool addToToc() const { return add_to_toc_; }
+       ///
+       std::string tocType() const { return toc_type_; }
+       ///
+       bool isTocCaption() const { return is_toc_caption_; }
 private:
        ///
        void makeDefaultCSS() const;
@@ -296,6 +302,12 @@ private:
        Layout::LaTeXArgMap latexargs_;
        ///
        Layout::LaTeXArgMap postcommandargs_;
+       ///
+       bool add_to_toc_;
+       ///
+       std::string toc_type_;
+       ///
+       bool is_toc_caption_;
 };
 
 ///