This patch adds removal of branch insets to lyx2lyx. It is not very 
sophisticated (it would probably not be too difficult to replace branches 
with booleans and the ifthen package), and it can produce empty 
paragraphs, but it is good enough for 1.4.0 IMO.
Please test.


Georg
Index: development/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/development/ChangeLog,v
retrieving revision 1.65
diff -u -p -r1.65 ChangeLog
--- development/ChangeLog	1 Feb 2006 15:16:59 -0000	1.65
+++ development/ChangeLog	1 Feb 2006 21:00:12 -0000
@@ -1,3 +1,7 @@
+2006-02-01  Georg Baum  <[EMAIL PROTECTED]>
+
+	* FORMAT: document branches
+
 2006-02-01  Bennett Helm  <[EMAIL PROTECTED]>
 
 	* MacOSX/LyX.app/Contents/Resources/preferences: update again.
Index: development/FORMAT
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/development/FORMAT,v
retrieving revision 1.43
diff -u -p -r1.43 FORMAT
--- development/FORMAT	13 Oct 2005 10:59:36 -0000	1.43
+++ development/FORMAT	1 Feb 2006 21:00:13 -0000
@@ -296,6 +296,26 @@ Paragraph text.
 	* attribute valignment="center" is replaced by valignment="middle"
 	for tabular columns and cells
 
+2003-08-17  Martin Vermeer  <[EMAIL PROTECTED]>
+
+	* Added branch inset. File format:
+
+	branch definition in the header:
+	\branch <branchname>
+	\selected 0                    0/1
+	\color #rrggbb
+	\end_branch
+
+	\begin_inset Branch <branchname>
+	collapsed false                 true/false
+
+	\begin_layout Standard
+
+	<branch contents>
+	\end_layout
+
+	\end_inset
+
 2003-07-28  José Matos  <[EMAIL PROTECTED]>
 
 	* \the_end is replaced with \end_document
Index: lib/lyx2lyx/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/ChangeLog,v
retrieving revision 1.106
diff -u -p -r1.106 ChangeLog
--- lib/lyx2lyx/ChangeLog	1 Dec 2005 19:00:06 -0000	1.106
+++ lib/lyx2lyx/ChangeLog	1 Feb 2006 21:00:13 -0000
@@ -1,3 +1,7 @@
+2006-02-01  Georg Baum  <[EMAIL PROTECTED]>
+
+	* lyx_1_4.py (remove_branches): new, remove branch insets
+
 2005-12-01  José Matos  <[EMAIL PROTECTED]>
 
 	* LyX.py (choose_io): replace open and make the choice more transparent.
Index: lib/lyx2lyx/lyx_1_4.py
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/lyx_1_4.py,v
retrieving revision 1.55
diff -u -p -r1.55 lyx_1_4.py
--- lib/lyx2lyx/lyx_1_4.py	21 Nov 2005 17:05:03 -0000	1.55
+++ lib/lyx2lyx/lyx_1_4.py	1 Feb 2006 21:00:13 -0000
@@ -1613,6 +1613,41 @@ def convert_frameless_box(file):
 	                      'collapsed ' + params['collapsed']]
 	    i = i + 6
 
+
+def remove_branches(file):
+    i = 0
+    while 1:
+        i = find_token(file.header, "\\branch", i)
+        if i == -1:
+            break
+        file.warning("Removing branch %s." % split(file.header[i])[1])
+        del file.header[i:i+4]
+
+    i = 0
+    while 1:
+        i = find_token(file.body, "\\begin_inset Branch", i)
+        if i == -1:
+            return
+        j = find_end_of_inset(file.body, i)
+        if j == -1:
+            file.warning("Malformed LyX file: Missing '\\end_inset'.")
+            i = i + 1
+            continue
+        del file.body[i]
+        del file.body[j - 1]
+        # Seach for a line starting 'collapsed'
+        # If, however, we find a line starting '\layout'
+        # (_always_ present) then break with a warning message
+        while 1:
+            if (file.body[i][:9] == "collapsed"):
+                del file.body[i]
+                break
+            elif (file.body[i][:7] == "\\layout"):
+                file.warning("Malformed LyX file: Missing 'collapsed'.")
+                break
+            i = i + 1
+
+
 ##
 # Convert jurabib
 #
@@ -2318,7 +2437,8 @@ revert =  [[244, []],
            [226, [revert_box, revert_external_2]],
            [225, [revert_note]],
            [224, [rm_end_layout, begin_layout2layout, revert_end_document,
-                  revert_valignment_middle, revert_breaks, convert_frameless_box]],
+                  revert_valignment_middle, revert_breaks, convert_frameless_box,
+                  remove_branches]],
            [223, [revert_external_2, revert_comment, revert_eqref]],
            [222, [revert_spaces, revert_bibtex]],
            [221, [rm_end_header, rm_tracking_changes, rm_body_changes]]]

Reply via email to