> Then what remains is whether or not you want to move embedded_files_
> to BufferParams. I am neutral about this.

Latest patch attached. Can I apply?

Cheers,
Bo
Index: src/EmbeddedFiles.cpp
===================================================================
--- src/EmbeddedFiles.cpp	(revision 20193)
+++ src/EmbeddedFiles.cpp	(working copy)
@@ -286,7 +286,7 @@
 }
 
 
-bool EmbeddedFiles::write(DocFileName const & filename)
+bool EmbeddedFiles::writeFile(DocFileName const & filename)
 {
 	// file in the temporary path has the content
 	string const content = FileName(addName(buffer_->temppath(),
@@ -406,7 +406,7 @@
 	file_list_.clear();
 	string filename = "";
 	string inzipName = "";
-	bool status = "";
+	bool embedded = false;
 
 	while (lex.isOK()) {
 		lex.next();
@@ -431,9 +431,9 @@
 			lex >> filename;
 		else if (token == "\\inzipName")
 			lex >> inzipName;
-		else if (token == "\\status") {
-			lex >> status;
-			registerFile(filename, status, NULL, inzipName);
+		else if (token == "\\embed") {
+			lex >> embedded;
+			registerFile(filename, embedded, NULL, inzipName);
 			filename = "";
 			inzipName = "";
 		} else {
@@ -463,7 +463,7 @@
 			<< to_utf8(makeRelPath(from_utf8(it->absFilename()),
 				from_utf8(buffer_->filePath()))) << '\n'
 			<< "\\inzipName " << it->inzipName() << '\n'
-			<< "\\status " << (it->embedded() ? "true" : "false") << '\n';
+			<< "\\embed " << (it->embedded() ? "true" : "false") << '\n';
 	}
 }
 
Index: src/EmbeddedFiles.h
===================================================================
--- src/EmbeddedFiles.h	(revision 20193)
+++ src/EmbeddedFiles.h	(working copy)
@@ -77,7 +77,7 @@
 3. When a lyx file file.lyx is saved, it is save to tmppath() first.
 Embedded files are compressed along with file.lyx and a manifest.txt. 
 If embedding is disabled, file.lyx is saved in the usual pure-text form.
-(c.f. Buffer::writeFile(), EmbeddedFiles::write())
+(c.f. Buffer::writeFile(), EmbeddedFiles::writeFile())
 
 4. When a lyx file.lyx file is opened, if it is a zip file, it is
 decompressed to tmppath(). If manifest.txt and file.lyx exists in
@@ -199,7 +199,7 @@
 	void update();
 
 	/// write a zip file
-	bool write(support::DocFileName const & filename);
+	bool writeFile(support::DocFileName const & filename);
 
 	void clear() { file_list_.clear(); }
 
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp	(revision 20193)
+++ src/Buffer.cpp	(working copy)
@@ -142,7 +142,7 @@
 
 namespace {
 
-int const LYX_FORMAT = 284;
+int const LYX_FORMAT = 285;
 
 } // namespace anon
 
@@ -559,7 +559,10 @@
 					 "\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
 		}
 	}
+	// read manifest after header
+	embeddedFiles().readManifest(lex, errorList);	
 
+	// read main text
 	bool const res = text().read(*this, lex, errorList);
 	for_each(text().paragraphs().begin(),
 		 text().paragraphs().end(),
@@ -661,12 +664,9 @@
 		LYXERR(Debug::FILES) << filename << " is in zip format. Unzip to " << temppath() << endl;
 		::unzipToDir(filename.toFilesystemEncoding(), temppath());
 		//
-		FileName manifest(addName(temppath(), "manifest.txt"));
-		FileName lyxfile(addName(temppath(), 
-			onlyFilename(filename.toFilesystemEncoding())));
+		FileName lyxfile(addName(temppath(), "content.lyx"));
 		// if both manifest.txt and file.lyx exist, this is am embedded file
-		if (fs::exists(manifest.toFilesystemEncoding()) &&
-			fs::exists(lyxfile.toFilesystemEncoding())) {
+		if (fs::exists(lyxfile.toFilesystemEncoding())) {
 			params().embedded = true;
 			fname = lyxfile;
 		}
@@ -889,8 +889,7 @@
 	FileName content;
 	if (params().embedded)
 		// first write the .lyx file to the temporary directory
-		content = FileName(addName(temppath(), 
-			onlyFilename(fname.toFilesystemEncoding())));
+		content = FileName(addName(temppath(), "content.lyx"));
 	else
 		content = fname;
 	
@@ -910,9 +909,8 @@
 
 	if (retval && params().embedded) {
 		// write file.lyx and all the embedded files to the zip file fname
-		// if embedding is enabled, and there is any embedded file
-		pimpl_->embedded_files.update();
-		return pimpl_->embedded_files.write(fname);
+		// if embedding is enabled
+		return pimpl_->embedded_files.writeFile(fname);
 	}
 	return retval;
 }
@@ -951,6 +949,12 @@
 	params().writeFile(ofs);
 	ofs << "\\end_header\n";
 
+	// write the manifest after header
+	ofs << "\n\\begin_manifest\n";
+	pimpl_->embedded_files.update();
+	embeddedFiles().writeManifest(ofs);
+	ofs << "\\end_manifest\n";
+
 	// write the text
 	ofs << "\n\\begin_body\n";
 	text().write(*this, ofs);
Index: lib/lyx2lyx/LyX.py
===================================================================
--- lib/lyx2lyx/LyX.py	(revision 20193)
+++ lib/lyx2lyx/LyX.py	(working copy)
@@ -78,7 +78,7 @@
                    ("1_3",     [221], generate_minor_versions("1.3" , 7)),
                    ("1_4", range(222,246), generate_minor_versions("1.4" , 5)),
                    ("1_5", range(246,277), generate_minor_versions("1.5" , 1)),
-                   ("1_6", range(277,285), generate_minor_versions("1.6" , 0))]
+                   ("1_6", range(277,286), generate_minor_versions("1.6" , 0))]
 
 
 def formats_list():
@@ -175,6 +175,7 @@
         self.default_layout = ''
         self.header = []
         self.preamble = []
+        self.manifest = []
         self.body = []
         self.status = 0
         self.encoding = encoding
@@ -198,7 +199,7 @@
 
 
     def read(self):
-        """Reads a file into the self.header and self.body parts, from self.input."""
+        """Reads a file into the self.header, self.manifest and self.body parts, from self.input."""
 
         while 1:
             line = self.input.readline()
@@ -225,6 +226,25 @@
             if check_token(line, '\\end_preamble'):
                 continue
 
+            if check_token(line, '\\begin_manifest'):
+                while 1:
+                    line = self.input.readline()
+                    if not line:
+                        self.error("Invalid LyX file.")
+
+                    line = trim_eol(line)
+                    if check_token(line, "\\end_manifest"):
+                        break
+
+                    if not line.startswith('\\filename') and not line.startswith('\\inzipName') \
+                            and not line.startswith('\\embed'):
+                        self.warning("Malformed LyX file: Missing '\\end_manifest'.")
+
+                    self.manifest.append(line)
+            
+            if check_token(line, '\\end_manifest'):
+                continue
+
             line = line.strip()
             if not line:
                 continue
@@ -275,7 +295,14 @@
         else:
             header = self.header
 
-        for line in header + [''] + self.body:
+        # LyX file format <= 284 does not have a manifest section
+        # so this section is set to None
+        if self.manifest is None:
+            manifest = []
+        else:
+            manifest = ['\\begin_manifest'] + self.manifest + ['\\end_manifest', '']
+
+        for line in header + [''] + manifest + self.body:
             self.output.write(line.encode(self.encoding)+"\n")
 
 
Index: lib/lyx2lyx/lyx_1_6.py
===================================================================
--- lib/lyx2lyx/lyx_1_6.py	(revision 20193)
+++ lib/lyx2lyx/lyx_1_6.py	(working copy)
@@ -174,7 +174,11 @@
         document.body[i] = document.body[i].replace('\\begin_inset Flex', '\\begin_inset CharStyle')
 
 
+def remove_manifest(document):
+    "Remove the manifest section"
+    document.manifest = None
 
+
 ##
 # Conversion hub
 #
@@ -188,10 +192,12 @@
            [281, []],
            [282, []],
            [283, [convert_flex]],
-           [284, []]
+           [284, []],
+           [285, []], # an empty manifest is automatically added
           ]
 
 revert =  [
+           [284, [remove_manifest]],
            [283, []],
            [282, [revert_flex]],
            [281, []],

Reply via email to