mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
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:
parent
400703aff1
commit
4d94460ce3
@ -189,6 +189,10 @@ import os, re, string, sys
|
||||
# Incremented to format 57, 30 May 2015 by spitz
|
||||
# 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
|
||||
# Manual (section "Declaring a new text class").
|
||||
|
||||
@ -196,7 +200,7 @@ import os, re, string, sys
|
||||
# development/tools/updatelayouts.py script to update all
|
||||
# layout files to the new format.
|
||||
|
||||
currentFormat = 57
|
||||
currentFormat = 58
|
||||
|
||||
|
||||
def usage(prog_name):
|
||||
@ -265,6 +269,7 @@ def convert(lines):
|
||||
re_LabelStringAppendix = re.compile(r'^(\s*)(LabelStringAppendix)(\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_IfStyle = re.compile(r'^(\s*)IfStyle(\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_End = re.compile(r'^(\s*)(End)(\s*)$', re.IGNORECASE)
|
||||
@ -420,6 +425,19 @@ def convert(lines):
|
||||
i += 1
|
||||
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:
|
||||
# nothing to do.
|
||||
i += 1
|
||||
|
@ -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 = 57; //spitz: New Layout tag ParagraphGroup
|
||||
int const LAYOUT_FORMAT = 58; // rgh: ProvideStyle
|
||||
|
||||
namespace {
|
||||
|
||||
@ -173,7 +173,8 @@ enum TextClassTags {
|
||||
TC_OUTPUTFORMAT,
|
||||
TC_INPUT,
|
||||
TC_STYLE,
|
||||
TC_IFSTYLE,
|
||||
TC_MODIFYSTYLE,
|
||||
TC_PROVIDESTYLE,
|
||||
TC_DEFAULTSTYLE,
|
||||
TC_INSETLAYOUT,
|
||||
TC_NOINSETLAYOUT,
|
||||
@ -240,10 +241,10 @@ LexerKeyword textClassTags[] = {
|
||||
{ "htmlstyles", TC_HTMLSTYLES },
|
||||
{ "htmltocsection", TC_HTMLTOCSECTION },
|
||||
{ "ifcounter", TC_IFCOUNTER },
|
||||
{ "ifstyle", TC_IFSTYLE },
|
||||
{ "input", TC_INPUT },
|
||||
{ "insetlayout", TC_INSETLAYOUT },
|
||||
{ "leftmargin", TC_LEFTMARGIN },
|
||||
{ "modifystyle", TC_MODIFYSTYLE },
|
||||
{ "nocounter", TC_NOCOUNTER },
|
||||
{ "nofloat", TC_NOFLOAT },
|
||||
{ "noinsetlayout", TC_NOINSETLAYOUT },
|
||||
@ -255,6 +256,7 @@ LexerKeyword textClassTags[] = {
|
||||
{ "preamble", TC_PREAMBLE },
|
||||
{ "provides", TC_PROVIDES },
|
||||
{ "providesmodule", TC_PROVIDESMODULE },
|
||||
{ "providestyle", TC_PROVIDESTYLE },
|
||||
{ "requires", TC_REQUIRES },
|
||||
{ "rightmargin", TC_RIGHTMARGIN },
|
||||
{ "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.
|
||||
bool ifstyle = false;
|
||||
bool ifcounter = false;
|
||||
bool modifystyle = false;
|
||||
bool providestyle = false;
|
||||
bool ifcounter = false;
|
||||
|
||||
switch (static_cast<TextClassTags>(le)) {
|
||||
|
||||
@ -467,9 +470,15 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
|
||||
}
|
||||
break;
|
||||
|
||||
case TC_IFSTYLE:
|
||||
ifstyle = true;
|
||||
// fall through
|
||||
case TC_MODIFYSTYLE:
|
||||
modifystyle = true;
|
||||
// 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: {
|
||||
if (!lexrc.next()) {
|
||||
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
|
||||
// of the style and discard it.
|
||||
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);
|
||||
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.setName(name);
|
||||
error = !readStyle(lexrc, layout);
|
||||
@ -502,9 +522,12 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
|
||||
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 {
|
||||
// this was an ifstyle where we didn't have the style
|
||||
// scan the rest and discard it
|
||||
Layout lay;
|
||||
readStyle(lexrc, lay);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user