mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 10:58:52 +00:00
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 <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)
This commit is contained in:
parent
afaf28964a
commit
3c9b62a69d
@ -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])
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
14
src/Layout.h
14
src/Layout.h
@ -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
|
||||
|
@ -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_, ',')) {
|
||||
|
@ -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 &);
|
||||
};
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
///
|
||||
|
@ -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;
|
||||
|
@ -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_;
|
||||
};
|
||||
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user