]> git.lyx.org Git - lyx.git/commitdiff
Clean up split index reversion routine.
authorRichard Heck <rgheck@comcast.net>
Thu, 4 Nov 2010 01:04:39 +0000 (01:04 +0000)
committerRichard Heck <rgheck@comcast.net>
Thu, 4 Nov 2010 01:04:39 +0000 (01:04 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36026 a592a061-630c-0410-9148-cb99ea01b6c8

lib/lyx2lyx/lyx_2_0.py

index b5f21f0ac2c3cd44a3d2660fedd8a42359871576..695796092fe6509a6313e373d58b12a9ae2f2334 100644 (file)
@@ -682,9 +682,12 @@ def revert_splitindex(document):
         return
     indices = get_value(document.header, "\\use_indices", i)
     preamble = ""
-    if indices == "true":
+    useindices = (indices == "true")
+    if useindices:
          preamble += "\\usepackage{splitidx}\n"
     del document.header[i]
+    
+    # deal with index declarations in the preamble
     i = 0
     while True:
         i = find_token(document.header, "\\index", i)
@@ -694,17 +697,20 @@ def revert_splitindex(document):
         if k == -1:
             document.warning("Malformed LyX document: Missing \\end_index.")
             return
-        line = document.header[i]
-        l = re.compile(r'\\index (.*)$')
-        m = l.match(line)
-        iname = m.group(1)
-        ishortcut = get_value(document.header, '\\shortcut', i, k)
-        if ishortcut != "" and indices == "true":
-            preamble += "\\newindex[" + iname + "]{" + ishortcut + "}\n"
+        if useindices:    
+          line = document.header[i]
+          l = re.compile(r'\\index (.*)$')
+          m = l.match(line)
+          iname = m.group(1)
+          ishortcut = get_value(document.header, '\\shortcut', i, k)
+          if ishortcut != "":
+              preamble += "\\newindex[" + iname + "]{" + ishortcut + "}\n"
         del document.header[i:k + 1]
-        i = 0
     if preamble != "":
         insert_to_preamble(0, document, preamble)
+        
+    # deal with index insets
+    # these need to have the argument removed
     i = 0
     while True:
         i = find_token(document.body, "\\begin_inset Index", i)
@@ -719,13 +725,17 @@ def revert_splitindex(document):
         else:
             k = find_end_of_inset(document.body, i)
             if k == -1:
-                 return
+                document.warning("Can't find end of index inset!")
+                i += 1
+                continue
             content = lyx2latex(document, document.body[i:k])
             # escape quotes
             content = content.replace('"', r'\"')
-            subst = [old_put_cmd_in_ert("\\sindex[" + itype + "]{" + content + "}")]
+            subst = put_cmd_in_ert("\\sindex[" + itype + "]{" + content + "}")
             document.body[i:k + 1] = subst
         i = i + 1
+        
+    # deal with index_print insets
     i = 0
     while True:
         i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
@@ -736,10 +746,10 @@ def revert_splitindex(document):
         if ptype == "idx":
             j = find_token(document.body, "type", i, k)
             del document.body[j]
-        elif indices == "false":
+        elif not useindices:
             del document.body[i:k + 1]
         else:
-            subst = [old_put_cmd_in_ert("\\printindex[" + ptype + "]{}")]
+            subst = put_cmd_in_ert("\\printindex[" + ptype + "]{}")
             document.body[i:k + 1] = subst
         i = i + 1