Add new ProvideStyle tag, which adds a new style only if it does not already

exist. This will allow for a proper fix for bug #8796, though that may or may
not get fixed before 2.2.0.

Also, change the InStyle tag to ModifyStyle, per a suggestion of Jurgen's.
This commit is contained in:
Richard Heck 2015-12-03 21:06:28 -05:00
parent 400703aff1
commit 4d94460ce3
2 changed files with 54 additions and 13 deletions

View File

@ -189,6 +189,10 @@ import os, re, string, sys
# Incremented to format 57, 30 May 2015 by spitz # Incremented to format 57, 30 May 2015 by spitz
# New Layout tag "ParagraphGroup" # New Layout tag "ParagraphGroup"
# Incremented to format 58, 5 December 2015, by rgh
# New Layout tag "ProvideStyle"
# Change "IfStyle" to "ModifyStyle"
# Do not forget to document format change in Customization # Do not forget to document format change in Customization
# Manual (section "Declaring a new text class"). # Manual (section "Declaring a new text class").
@ -196,7 +200,7 @@ import os, re, string, sys
# development/tools/updatelayouts.py script to update all # development/tools/updatelayouts.py script to update all
# layout files to the new format. # layout files to the new format.
currentFormat = 57 currentFormat = 58
def usage(prog_name): def usage(prog_name):
@ -265,6 +269,7 @@ def convert(lines):
re_LabelStringAppendix = re.compile(r'^(\s*)(LabelStringAppendix)(\s+)(("[^"]+")|(\S+))', re.IGNORECASE) re_LabelStringAppendix = re.compile(r'^(\s*)(LabelStringAppendix)(\s+)(("[^"]+")|(\S+))', re.IGNORECASE)
re_LatexType = re.compile(r'^(\s*)(LatexType)(\s+)(\S+)', re.IGNORECASE) re_LatexType = re.compile(r'^(\s*)(LatexType)(\s+)(\S+)', re.IGNORECASE)
re_Style = re.compile(r'^(\s*)(Style)(\s+)(\S+)', re.IGNORECASE) re_Style = re.compile(r'^(\s*)(Style)(\s+)(\S+)', re.IGNORECASE)
re_IfStyle = re.compile(r'^(\s*)IfStyle(\s+\S+)', re.IGNORECASE)
re_CopyStyle = re.compile(r'^(\s*)(CopyStyle)(\s+)(\S+)', re.IGNORECASE) re_CopyStyle = re.compile(r'^(\s*)(CopyStyle)(\s+)(\S+)', re.IGNORECASE)
re_NoStyle = re.compile(r'^(\s*)(NoStyle)(\s+)(\S+)', re.IGNORECASE) re_NoStyle = re.compile(r'^(\s*)(NoStyle)(\s+)(\S+)', re.IGNORECASE)
re_End = re.compile(r'^(\s*)(End)(\s*)$', re.IGNORECASE) re_End = re.compile(r'^(\s*)(End)(\s*)$', re.IGNORECASE)
@ -420,6 +425,19 @@ def convert(lines):
i += 1 i += 1
continue continue
if format == 57:
match = re_IfStyle.match(lines[i])
if not match:
i += 1
continue
# r'^(\s*)IfStyle(\s+\S+)
lead = match.group(1)
trail = match.group(2)
lines[i] = lead + "ModifyStyle" + trail
i += 1
continue
if format >= 50 and format <= 56: if format >= 50 and format <= 56:
# nothing to do. # nothing to do.
i += 1 i += 1

View File

@ -61,7 +61,7 @@ namespace lyx {
// You should also run the development/tools/updatelayouts.py script, // You should also run the development/tools/updatelayouts.py script,
// to update the format of all of our layout files. // to update the format of all of our layout files.
// //
int const LAYOUT_FORMAT = 57; //spitz: New Layout tag ParagraphGroup int const LAYOUT_FORMAT = 58; // rgh: ProvideStyle
namespace { namespace {
@ -173,7 +173,8 @@ enum TextClassTags {
TC_OUTPUTFORMAT, TC_OUTPUTFORMAT,
TC_INPUT, TC_INPUT,
TC_STYLE, TC_STYLE,
TC_IFSTYLE, TC_MODIFYSTYLE,
TC_PROVIDESTYLE,
TC_DEFAULTSTYLE, TC_DEFAULTSTYLE,
TC_INSETLAYOUT, TC_INSETLAYOUT,
TC_NOINSETLAYOUT, TC_NOINSETLAYOUT,
@ -240,10 +241,10 @@ LexerKeyword textClassTags[] = {
{ "htmlstyles", TC_HTMLSTYLES }, { "htmlstyles", TC_HTMLSTYLES },
{ "htmltocsection", TC_HTMLTOCSECTION }, { "htmltocsection", TC_HTMLTOCSECTION },
{ "ifcounter", TC_IFCOUNTER }, { "ifcounter", TC_IFCOUNTER },
{ "ifstyle", TC_IFSTYLE },
{ "input", TC_INPUT }, { "input", TC_INPUT },
{ "insetlayout", TC_INSETLAYOUT }, { "insetlayout", TC_INSETLAYOUT },
{ "leftmargin", TC_LEFTMARGIN }, { "leftmargin", TC_LEFTMARGIN },
{ "modifystyle", TC_MODIFYSTYLE },
{ "nocounter", TC_NOCOUNTER }, { "nocounter", TC_NOCOUNTER },
{ "nofloat", TC_NOFLOAT }, { "nofloat", TC_NOFLOAT },
{ "noinsetlayout", TC_NOINSETLAYOUT }, { "noinsetlayout", TC_NOINSETLAYOUT },
@ -255,6 +256,7 @@ LexerKeyword textClassTags[] = {
{ "preamble", TC_PREAMBLE }, { "preamble", TC_PREAMBLE },
{ "provides", TC_PROVIDES }, { "provides", TC_PROVIDES },
{ "providesmodule", TC_PROVIDESMODULE }, { "providesmodule", TC_PROVIDESMODULE },
{ "providestyle", TC_PROVIDESTYLE },
{ "requires", TC_REQUIRES }, { "requires", TC_REQUIRES },
{ "rightmargin", TC_RIGHTMARGIN }, { "rightmargin", TC_RIGHTMARGIN },
{ "secnumdepth", TC_SECNUMDEPTH }, { "secnumdepth", TC_SECNUMDEPTH },
@ -413,8 +415,9 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
} }
// used below to track whether we are in an IfStyle or IfCounter tag. // used below to track whether we are in an IfStyle or IfCounter tag.
bool ifstyle = false; bool modifystyle = false;
bool ifcounter = false; bool providestyle = false;
bool ifcounter = false;
switch (static_cast<TextClassTags>(le)) { switch (static_cast<TextClassTags>(le)) {
@ -467,9 +470,15 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
} }
break; break;
case TC_IFSTYLE: case TC_MODIFYSTYLE:
ifstyle = true; modifystyle = true;
// fall through // fall through
case TC_PROVIDESTYLE:
// if modifystyle is true, then we got here by falling through
// so we are not in an ProvideStyle block
if (!modifystyle)
providestyle = true;
// fall through
case TC_STYLE: { case TC_STYLE: {
if (!lexrc.next()) { if (!lexrc.next()) {
lexrc.printError("No name given for style: `$$Token'."); lexrc.printError("No name given for style: `$$Token'.");
@ -486,10 +495,21 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
// Since we couldn't read the name, we just scan the rest // Since we couldn't read the name, we just scan the rest
// of the style and discard it. // of the style and discard it.
error = !readStyle(lexrc, lay); error = !readStyle(lexrc, lay);
} else if (hasLayout(name)) { break;
}
bool const have_layout = hasLayout(name);
// If the layout already exists, then we want to add it to
// the existing layout, as long as we are not in an ProvideStyle
// block.
if (have_layout && !providestyle) {
Layout & lay = operator[](name); Layout & lay = operator[](name);
error = !readStyle(lexrc, lay); error = !readStyle(lexrc, lay);
} else if (!ifstyle) { }
// If the layout does not exist, then we want to create a new
// one, but not if we are in a ModifyStyle block.
else if (!have_layout && !modifystyle) {
Layout layout; Layout layout;
layout.setName(name); layout.setName(name);
error = !readStyle(lexrc, layout); error = !readStyle(lexrc, layout);
@ -502,9 +522,12 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
defaultlayout_ = name; defaultlayout_ = name;
} }
} }
// There are two ways to get here:
// (i) The layout exists but we are in an ProvideStyle block
// (ii) The layout doesn't exist, but we are in an ModifyStyle
// block.
// Either way, we just scan the rest and discard it
else { else {
// this was an ifstyle where we didn't have the style
// scan the rest and discard it
Layout lay; Layout lay;
readStyle(lexrc, lay); readStyle(lexrc, lay);
} }