]> git.lyx.org Git - features.git/commitdiff
* lib/lyx2lyx/lyx_1_4.py:
authorJürgen Spitzmüller <spitz@lyx.org>
Sat, 12 Jan 2008 09:59:37 +0000 (09:59 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Sat, 12 Jan 2008 09:59:37 +0000 (09:59 +0000)
* lib/lyx2lyx/lyx_1_6.py:
- improve reversion method for floats.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22508 a592a061-630c-0410-9148-cb99ea01b6c8

lib/lyx2lyx/lyx_1_4.py
lib/lyx2lyx/lyx_1_6.py

index 9952d14a8f05c4adb3c4aa94b0e5d180fbbc34b2..0e04b478cf10a86c7f8373c06033e27e431a5f05 100644 (file)
@@ -1832,7 +1832,13 @@ def revert_float(document):
         i = find_token_exact(document.body, '\\begin_inset Float', i)
         if i == -1:
             return
-        floatline = document.body[i]
+        line = document.body[i]
+        r = re.compile(r'\\begin_inset Float (.*)$')
+        m = r.match(line)
+        floattype = m.group(1)
+        if floattype != "figure" and floattype != "table":
+            i = i + 1
+            continue
         j = find_end_of_inset(document.body, i)
         if j == -1:
             document.warning("Malformed lyx document: Missing '\\end_inset'.")
@@ -1843,9 +1849,6 @@ def revert_float(document):
             if l == -1:
                 document.warning("Malformed LyX document: Missing `\\begin_layout Standard' in Float inset.")
                 return
-            floattype = "table"
-            if floatline == "\\begin_inset Float figure":
-                floattype = "figure"
             document.body[j] = '\\layout Standard\n\\begin_inset ERT\nstatus Collapsed\n\n' \
             '\\layout Standard\n\n\n\\backslash\n' \
             'end{sideways' + floattype + '}\n\n\\end_inset\n'
index cc93e90fdc3e55a9ff7835e3f602864c0336d3f1..0c50b81afa1ee59ae2cac72ee1426dbd3b61f1c7 100644 (file)
@@ -1140,12 +1140,19 @@ def revert_serbianlatin(document):
 
 
 def revert_rotfloat(document):
-    " Revert sidewaysalgorithm. "
+    " Revert sideways custom floats. "
     i = 0
     while 1:
-        i = find_token(document.body, '\\begin_inset Float algorithm', i)
+        i = find_token(document.body, "\\begin_inset Float", i)
         if i == -1:
             return
+        line = document.body[i]
+        r = re.compile(r'\\begin_inset Float (.*)$')
+        m = r.match(line)
+        floattype = m.group(1)
+        if floattype == "figure" or floattype == "table":
+            i = i + 1
+            continue
         j = find_end_of_inset(document.body, i)
         if j == -1:
             document.warning("Malformed lyx document: Missing '\\end_inset'.")
@@ -1158,17 +1165,20 @@ def revert_rotfloat(document):
                 return
             document.body[j] = '\\begin_layout Standard\n\\begin_inset ERT\nstatus collapsed\n\n' \
             '\\begin_layout Standard\n\n\n\\backslash\n' \
-            'end{sidewaysalgorithm}\n\\end_layout\n\n\\end_inset\n'
+            'end{sideways' + floattype + '}\n\\end_layout\n\n\\end_inset\n'
             del document.body[i+1:l-1]
             document.body[i] = '\\begin_inset ERT\nstatus collapsed\n\n' \
             '\\begin_layout Standard\n\n\n\\backslash\n' \
-            'begin{sidewaysalgorithm}\n\\end_layout\n\n\\end_inset\n\n\\end_layout\n\n'
-            add_to_preamble(document,
-                            ['% Commands inserted by lyx2lyx for sideways algorithm float',
-                             '\\usepackage{rotfloat}\n'
-                             '\\floatstyle{ruled}\n'
-                             '\\newfloat{algorithm}{tbp}{loa}\n'
-                             '\\floatname{algorithm}{Algorithm}\n'])
+            'begin{sideways' + floattype + '}\n\\end_layout\n\n\\end_inset\n\n\\end_layout\n\n'
+            if floattype == "algorithm":
+                add_to_preamble(document,
+                                ['% Commands inserted by lyx2lyx for sideways algorithm float',
+                                 '\\usepackage{rotfloat}\n'
+                                 '\\floatstyle{ruled}\n'
+                                 '\\newfloat{algorithm}{tbp}{loa}\n'
+                                 '\\floatname{algorithm}{Algorithm}\n'])
+            else:
+                document.warning("Cannot create preamble definition for custom float" + floattype + ".")
             i = i + 1
             continue
         i = i + 1
@@ -1181,7 +1191,13 @@ def revert_widesideways(document):
         i = find_token(document.body, '\\begin_inset Float', i)
         if i == -1:
             return
-        floatline = document.body[i]
+        line = document.body[i]
+        r = re.compile(r'\\begin_inset Float (.*)$')
+        m = r.match(line)
+        floattype = m.group(1)
+        if floattype != "figure" and floattype != "table":
+            i = i + 1
+            continue
         j = find_end_of_inset(document.body, i)
         if j == -1:
             document.warning("Malformed lyx document: Missing '\\end_inset'.")
@@ -1193,9 +1209,6 @@ def revert_widesideways(document):
                 if l == -1:
                     document.warning("Malformed LyX document: Missing `\\begin_layout Standard' in Float inset.")
                     return
-                floattype = "table"
-                if floatline == "\\begin_inset Float figure":
-                    floattype = "figure"
                 document.body[j] = '\\begin_layout Standard\n\\begin_inset ERT\nstatus collapsed\n\n' \
                 '\\begin_layout Standard\n\n\n\\backslash\n' \
                 'end{sideways' + floattype + '*}\n\\end_layout\n\n\\end_inset\n'