]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/layout2layout.py
Add AllowedInInsets and AllowedInLayouts InsetLayout tags
[lyx.git] / lib / scripts / layout2layout.py
index a8c0ded990a21ab2f6ed1428d8d198a0c5d5cb11..5f4a50470644f2cca289cec97bbb73f146658536 100644 (file)
@@ -11,7 +11,7 @@
 # This script will update a .layout file to current format
 
 # The latest layout format is also defined in src/TextClass.cpp
-currentFormat = 99
+currentFormat = 102
 
 
 # Incremented to format 4, 6 April 2007, lasgouttes
@@ -334,6 +334,16 @@ currentFormat = 99
 # Incremented to format 99, 22 December 2022 by tcuvelier
 # Add DocBookGenerateTitle for Layout
 
+# Incremented to format 100, 9 May 2023 by forenr
+# Add inset label color
+
+# Incremented to format 101, 22 July 2023 by lasgouttes
+# add InsetLayout tag InheritFont
+
+# Incremented to format 102, 25 July 2023 by spitz
+# add InsetLayout tags AllowedInInsets, EndAllowedInInsets,
+# AllowedInLayouts, EndAllowedInLayouts
+
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
 
@@ -472,8 +482,9 @@ def convert(lines, end_format):
     re_trimLabelStringAppendix  = re.compile(b'^(\\s*LabelStringAppendix\\s+)"\\s*(.*?)\\s*"\\s*$')
     re_trimEndLabelString = re.compile(b'^(\\s*EndLabelString\\s+)"\\s*(.*?)\\s*"\\s*$')
     re_trimLabelCounter = re.compile(b'^(\\s*LabelCounter\\s+)"\\s*(.*?)\\s*"\\s*$')
-
-
+    # for format 100
+    re_InsetLayout100 = re.compile(b'^\\s*InsetLayout\\s+\\"?(Box|Float|Foot|Marginal|Listings|Note:Comment|Note:Greyedout|Tabular)(:\\S*)?\\"?\\s*$', re.IGNORECASE)
+    re_InheritFont = re.compile(b'^(\\s*)InheritFont(\\s+)(\\S+)$', re.IGNORECASE)
     # counters for sectioning styles (hardcoded in 1.3)
     counters = {b"part"          : b"\\Roman{part}",
                 b"chapter"       : b"\\arabic{chapter}",
@@ -580,7 +591,41 @@ def convert(lines, end_format):
                 i += 1
             continue
 
-        if 87 <= format <= 98:
+        if format == 101:
+            # nothing to do.
+            i += 1
+            continue
+
+        if format == 100:
+            # InheritFont has been introduced and defaults to true. Some insets had
+            # an hardcoded inheritFont') method returning true. We removed them, so
+            # we want to introduce the correct tag if it is not already there.
+            match = re_InsetLayout100.match(lines[i])
+            if not match:
+                i += 1
+                continue
+
+            inheritfont_found = False
+            inherited = False
+            while i < len(lines):
+                match = re_InheritFont.match(lines[i])
+                if match:
+                    inheritfont_found = True
+                else:
+                    match = re_CopyStyle.match(lines[i])
+                    if match:
+                        inherited = True
+                    else:
+                        match = re_End.match(lines[i])
+                        if match:
+                            break
+                i += 1
+            if not inheritfont_found and not inherited:
+                lines.insert(i, b"\tInheritFont false")
+
+            continue
+
+        if 87 <= format <= 99:
             # nothing to do.
             i += 1
             continue