]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/layout2layout.py
Add ObsoletedBy tag to InsetLayout
[lyx.git] / lib / scripts / layout2layout.py
index b6345f1234f7181c3bf710d40fa551bf997b6e9b..cf1374463b3e4b516854842c8e6cd4735e0bb7df 100644 (file)
@@ -1,4 +1,3 @@
-#! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
 # file layout2layout.py
@@ -151,14 +150,41 @@ import os, re, string, sys
 # Remove COUNTER label style; rename as STATIC
 # Rename TOP_ENVIRONMENT to ABOVE and CENTERED_TOP_ENVIRONMENT to CENTERED
 
+# Incremented to format 45, 12 February 2013 by rgh
+# New Tag "NoInsetLayout"
+
+# Incremented to format 46, 15 May 2013 by gb
+# New Tag "ForceLocal"
+
+# Incremented to format 47, 23 May 2013 by rgh
+# Add PackageOptions tag
+
+# Incremented to format 48, 31 May 2013 by rgh
+# Add InitialValue tag for counters
+
+# 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"
+
 # 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 = 44
+currentFormat = 53
 
 
 def usage(prog_name):
@@ -244,6 +270,7 @@ def convert(lines):
     re_Builtin = re.compile(r'^(\s*)LaTeXBuiltin\s+(\w*)', re.IGNORECASE)
     re_True = re.compile(r'^\s*(?:true|1)\s*$', re.IGNORECASE)
     re_InsetLayout = re.compile(r'^\s*InsetLayout\s+(?:Custom|CharStyle|Element):(\S+)\s*$', re.IGNORECASE)
+    re_ResetsFont = re.compile(r'^(\s*)ResetsFont(\s+)(\S+)$', re.IGNORECASE)
     # with quotes
     re_QInsetLayout = re.compile(r'^\s*InsetLayout\s+"(?:Custom|CharStyle|Element):([^"]+)"\s*$', re.IGNORECASE)
     re_InsetLayout_CopyStyle = re.compile(r'^\s*CopyStyle\s+(?:Custom|CharStyle|Element):(\S+)\s*$', re.IGNORECASE)
@@ -255,6 +282,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*$')
@@ -289,7 +317,7 @@ def convert(lines):
                         "subparagraph"  : "\\arabic{section}.\\arabic{subsection}.\\arabic{subsubsection}.\\arabic{paragraph}.\\arabic{subparagraph}"}
 
     # Value of TocLevel for sectioning styles
-    toclevels = {"part"          : 0,
+    toclevels = {"part"          : -1,
                  "chapter"       : 0,
                  "section"       : 1,
                  "subsection"    : 2,
@@ -319,6 +347,11 @@ def convert(lines):
     opts = 0
     reqs = 0
     inchapter = False
+    isflexlayout = False         # only used for 48 -> 49
+    # Whether a style is inherited (works only for CopyStyle currently,
+    # not for true inherited styles, see bug 8920
+    inherited = False        # only used for 48 -> 49
+    resetsfont_found = False # only used for 48 -> 49
 
     while i < len(lines):
         # Skip comments and empty lines
@@ -352,7 +385,7 @@ def convert(lines):
                     # nothing to do
                     return format
                 else:
-                    error('Cannot convert file format %s' % format)
+                    error('Cannot convert file format %s to %s' % (format, currentFormat))
             else:
                 lines.insert(i, "Format 2")
                 only_comment = 0
@@ -374,7 +407,110 @@ def convert(lines):
             while i < len(lines) and not re_EndBabelPreamble.match(lines[i]):
                 i += 1
             continue
-        
+
+        if format >= 50 and format <= 52:
+            # 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 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:
+                  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:
+            # nothing to do.
+            i += 1
+            continue
+
         if format == 43:
           match = re_LabelTypeIsCounter.match(lines[i])
           if match: