From 3c9b62a69d894b5ea020c18d0bec676dc00fe378 Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Tue, 3 Nov 2015 11:47:25 -0500 Subject: [PATCH] Layout format update: AddToToc, IsTocCaption, OutlinerName Preliminary work for addressing #7790. Thanks to Richard for providing initial files this is based on. Adding to TextClass: OutlinerName (the second string is translated) e.g.: OutlinerName thm "Definitions & Theorems" Adding to Layout: AddToToc (default "", means no) IsTocCaption (default 0) e.g.: AddToToc thm IsTocCaption 1 Adding to InsetLayout: AddToToc (default "", means no) IsTocCaption (default 0) e.g.: AddToToc literate Adding to inset arguments: IsTocCaption (default 0) --- lib/scripts/layout2layout.py | 11 ++++++++- po/lyx_pot.py | 7 ++++++ src/Layout.cpp | 19 ++++++++++++++++ src/Layout.h | 14 ++++++++++++ src/TextClass.cpp | 43 ++++++++++++++++++++++++++++++++++-- src/TextClass.h | 6 +++++ src/TocBackend.cpp | 8 +++++++ src/TocBackend.h | 2 ++ src/insets/InsetLayout.cpp | 17 +++++++++++++- src/insets/InsetLayout.h | 12 ++++++++++ 10 files changed, 135 insertions(+), 4 deletions(-) diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index 48a1e03f21..a87c300a88 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -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]) diff --git a/po/lyx_pot.py b/po/lyx_pot.py index c92939c9b9..432a126056 100755 --- a/po/lyx_pot.py +++ b/po/lyx_pot.py @@ -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) diff --git a/src/Layout.cpp b/src/Layout.cpp index 0fdb3412e7..db8c317764 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -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; diff --git a/src/Layout.h b/src/Layout.h index 091e319cb1..273a36155b 100644 --- a/src/Layout.h +++ b/src/Layout.h @@ -106,6 +106,7 @@ public: bool autoinsert; bool insertcotext; docstring pass_thru_chars; + bool is_toc_caption; }; /// typedef std::map 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 diff --git a/src/TextClass.cpp b/src/TextClass.cpp index 0ee74a7b50..c6f3ee0daf 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 = 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::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_, ',')) { diff --git a/src/TextClass.h b/src/TextClass.h index 0a075dd6c5..94fe003bd8 100644 --- a/src/TextClass.h +++ b/src/TextClass.h @@ -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 > cite_styles_; + /// + std::map outliner_names_; private: /////////////////////////////////////////////////////////////////// // helper routines for reading layout files @@ -359,6 +363,8 @@ private: int readCiteEngineType(Lexer &) const; /// bool readCiteFormat(Lexer &); + /// + bool readOutlinerName(Lexer &); }; diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index 5599e1f362..9bd435f2f2 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -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 diff --git a/src/TocBackend.h b/src/TocBackend.h index e18f1bc094..d5dfae4264 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -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: /// diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp index 9e03fcb42d..7291a60bf1 100644 --- a/src/insets/InsetLayout.cpp +++ b/src/insets/InsetLayout.cpp @@ -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; diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h index 9589fadd5e..c1bbe5c073 100644 --- a/src/insets/InsetLayout.h +++ b/src/insets/InsetLayout.h @@ -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_; }; ///