]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/layout2layout.py
The way this was previously, it had to fail if the GUI language
[lyx.git] / lib / scripts / layout2layout.py
index 32f095663e2d1efb09dac79a7448dbaae58359d7..7de844b87fb66ed41f5aaf216c5f0caa4165c08c 100644 (file)
@@ -165,14 +165,50 @@ import os, re, string, sys
 # Incremented to format 49, 10 Feb 2014 by gb
 # Change default of "ResetsFont" tag to false
 
+# Incremented to format 50, 9 May 2014 by forenr
+# Removal of "Separator" layouts
+
+# Incremented to format 51, 29 May 2014 by spitz
+# New Style tag "ToggleIndent"
+
+# Incremented to format 52, 1 December 2014 by spitz
+# New InsetLayout tag "ForceOwnlines"
+
+# Incremented to format 53, 7 December 2014 by spitz
+# New InsetLayout tag "ObsoletedBy"
+
+# Incremented to format 54, 11 Jan 2014 by gb
+# New InsetLayout tag "FixedWidthPreambleEncoding"
+
+# Incremented to format 55, 20 April 2015 by spitz
+# New InsetLayout and Layout tags "PassThruChars"
+
+# Incremented to format 56, 20 May 2015 by spitz
+# New Float tags "AllowedPlacement", "AllowsWide", "AllowsSideways"
+
+# 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"
+
+# Incremented to format 59, 22 November 2015 by gm
+# New Tag "OutlinerName"
+# New Layout tags "AddToToc", "IsTocCaption"
+# New Layout argument tag "IsTocCaption"
+
+# Incremented to format 60, 25 March 2016 by lasgouttes
+# Rename caption subtype LongTableNoNumber to Unnumbered
+
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
 
 # You might also want to consider running the
-# development/tools/updatelayouts.sh script to update all
+# development/tools/updatelayouts.py script to update all
 # layout files to the new format.
 
-currentFormat = 49
+currentFormat = 60
 
 
 def usage(prog_name):
@@ -241,6 +277,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)
@@ -270,6 +307,7 @@ def convert(lines):
     re_QInsetLayout2 = re.compile(r'^\s*InsetLayout\s+"([^"]+)"\s*$', re.IGNORECASE)
     re_IsFlex = re.compile(r'\s*LyXType.*$', re.IGNORECASE)
     re_CopyStyle2 = re.compile(r'(\s*CopyStyle\s+)"?([^"]+)"?\s*$')
+    re_Separator = re.compile(r'^(?:(-*)|(\s*))(Separator|EndOfSlide)(?:(-*)|(\s*))$', re.IGNORECASE)
     # for categories
     re_Declaration = re.compile(r'^#\s*\\Declare\w+Class.*$')
     re_ExtractCategory = re.compile(r'^(#\s*\\Declare\w+Class(?:\[[^]]*?\])?){([^(]+?)\s+\(([^)]+?)\)\s*}\s*$')
@@ -284,6 +322,7 @@ def convert(lines):
     re_TopEnvironment = re.compile(r'^(\s*)LabelType(\s+)Top_Environment\s*$', re.IGNORECASE)
     re_CenteredEnvironment = re.compile(r'^(\s*)LabelType(\s+)Centered_Top_Environment\s*$', re.IGNORECASE)
     re_ChapterStyle = re.compile(r'^\s*Style\s+Chapter\s*$', re.IGNORECASE)
+    re_InsetLayout_CaptionLTNN = re.compile(r'^(\s*InsetLayout\s+)(Caption:LongTableNonumber)', re.IGNORECASE)
 
 
     # counters for sectioning styles (hardcoded in 1.3)
@@ -395,40 +434,130 @@ def convert(lines):
                 i += 1
             continue
 
+        if format == 59:
+            match = re_InsetLayout_CaptionLTNN.match(lines[i])
+            if not match:
+                i += 1
+                continue
+            # '^(\s*InsetLayout\s+)(Caption:LongTableNonumber)'
+            lead  = match.group(1)
+            lines[i] = lead + "Caption:Unnumbered"
+            i += 1
+            continue
+
+        if format == 58:
+            # nothing to do.
+            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
+            continue
+
+        if format == 49:
+            separator = []
+
+            # delete separator styles
+            match = re_Style.match(lines[i])
+            if match:
+                style = string.lower(match.group(4))
+                if re_Separator.match(style):
+                    del lines[i]
+                    while i < len(lines) and not re_End.match(lines[i]):
+                        separator.append(lines[i])
+                        del lines[i]
+                    if i == len(lines):
+                        error('Incomplete separator style.')
+                    else:
+                        del lines[i]
+                        continue
+
+            # delete undefinition of separator styles
+            match = re_NoStyle.match(lines[i])
+            if match:
+                style = string.lower(match.group(4))
+                if re_Separator.match(style):
+                    del lines[i]
+                    continue
+
+            # replace the CopyStyle statement with the definition of the real
+            # style. This may result in duplicate statements, but that is OK
+            # since the second one will overwrite the first one.
+            match = re_CopyStyle.match(lines[i])
+            if match:
+                style = string.lower(match.group(4))
+                if re_Separator.match(style):
+                    if len(separator) > 0:
+                        lines[i:i+1] = separator
+                    else:
+                        # FIXME: If this style was redefined in an include file,
+                        # we should replace the real style and not this default.
+                        lines[i:i+1] = ['      Category              MainText',
+                                        '      KeepEmpty             1',
+                                        '      Margin                Dynamic',
+                                        '      LatexType             Paragraph',
+                                        '      LatexName             dummy',
+                                        '      ParIndent             MM',
+                                        '      Align                 Block',
+                                        '      LabelType             Static',
+                                        '      LabelString           "--- Separate Environment ---"',
+                                        '      LabelFont',
+                                        '        Family              Roman',
+                                        '        Series              Medium',
+                                        '        Size                Normal',
+                                        '        Color               Blue',
+                                        '      EndFont',
+                                        '      HTMLLabel             NONE']
+            i += 1
+            continue
+
         if format == 48:
             # The default of ResetsFont in LyX changed from true to false,
             # because it is now used for all InsetLayouts, not only flex ones.
             # Therefore we need to set it to true for all flex insets which do
             # do not already have a ResetsFont.
             match = re_InsetLayout2.match(lines[i])
-            if match:
-                resetsfont_found = False
-                inherited = False
-                name = string.lower(match.group(1))
-                if name == "flex" or name[:5] == "flex:":
-                    isflexlayout = True
+            if not match:
+                i += 1
+                continue
+
+            name = string.lower(match.group(1))
+            if name != "flex" and name != "\"flex\"" and name[0:5] != "flex:" and name [0:6] != "\"flex:":
+                i += 1
+                continue
+
+            resetsfont_found = False
+            inherited = False
+            notdone = True
+            while i < len(lines):
+              match = re_ResetsFont.match(lines[i])
+              if match:
+                  resetsfont_found = True
+              else:
+                match = re_CopyStyle.match(lines[i])
+                if match:
+                  inherited = True
                 else:
-                    isflexlayout = False
-            match = re_ResetsFont.match(lines[i])
-            if match:
-                resetsfont_found = True
-            match = re_End.match(lines[i])
-            if match:
-                if isflexlayout and not resetsfont_found and not inherited:
-                    lines.insert(i, "\tResetsFont true")
-                    i += 1
-            match = re_Style.match(lines[i])
-            if match:
-                isflexlayout = False
-                inherited = False
-            match = re_Counter.match(lines[i])
-            if match:
-                isflexlayout = False
-                inherited = False
-            match = re_CopyStyle.match(lines[i])
-            if match:
-                inherited = True
-            i += 1
+                  match = re_End.match(lines[i])
+                  if match:
+                    break
+              i += 1
+            if not resetsfont_found and not inherited:
+              lines.insert(i, "\tResetsFont true")
+
             continue
 
         if format >= 44 and format <= 47: