> If you open a master doc, the slave docs will automatically open, too under
> some circumstances (I don't know what triggers this). If you close LyX with
> an open master doc, all docs will be written to the session file. On next
> startup you will get a dialog box for each slave doc asking you whether you
> want to open it again, because LyX tries to open it twice: Once because it
> gets loaded from the master doc and once again because it is in the session
> file.

The attached patch

1. fixes the above problem by not saving slave document name
2. save names *after* new (isUnnamed())  files are saved
3. clear the lastopened list even when lyx is called with parameter.
Otherwise, the new one by one add method will accumulate names in this
case.

OK to apply?

BTW, my understanding is that the only known session problem left is
to save cursor stack instead of a single slice. Right?

Bo
Index: src/bufferlist.C
===================================================================
--- src/bufferlist.C	(revision 13771)
+++ src/bufferlist.C	(working copy)
@@ -122,6 +122,15 @@
 		if (!quitWriteBuffer(*it))
 			return false;
 	}
+	// now, all buffers have been written sucessfully
+	// save file names to .lyx/session
+	it = bstore.begin();
+	for (; it != end; ++it) {
+		// if master/slave are both open, do not save slave since it 
+		// will be automatically loaded when the master is loaded
+		if ((*it)->getMasterBuffer() == (*it))
+			LyX::ref().session().addLastOpenedFile((*it)->fileName());
+	}
 
 	return true;
 }
Index: src/session.C
===================================================================
--- src/session.C	(revision 13771)
+++ src/session.C	(working copy)
@@ -247,9 +247,9 @@
 }
 
 
-void Session::setLastOpenedFiles(vector<string> const & files)
+void Session::addLastOpenedFile(string const & file)
 {
-	lastopened = files;
+	lastopened.push_back(file);
 }
 
 
Index: src/lyxfunc.C
===================================================================
--- src/lyxfunc.C	(revision 13771)
+++ src/lyxfunc.C	(working copy)
@@ -1011,8 +1011,6 @@
 				// save cursor Position for opened files to .lyx/session
 				LyX::ref().session().saveFilePosition(owner->buffer()->fileName(),
 					boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
-				// save opened file name to .lyx/session
-				LyX::ref().session().setLastOpenedFiles( bufferlist.getFileNames());
 				// save bookmarks to .lyx/session
 				view()->saveSavedPositions();
 			}
Index: src/session.h
===================================================================
--- src/session.h	(revision 13771)
+++ src/session.h	(working copy)
@@ -82,10 +82,10 @@
 	 */
 	void clearLastOpenedFiles();
 
-	/** set lastopened file list
-	    @param files filenames of a list of opened files
+	/** add file to lastopened file list
+	    @param file filename to add
 	*/
-	void setLastOpenedFiles(std::vector<std::string> const & files);
+	void addLastOpenedFile(std::string const & file);
 
 	/** load saved cursor position from the fname entry in the filepos map
 	    @param fname file entry for which to load position information
Index: src/lyx_main.C
===================================================================
--- src/lyx_main.C	(revision 13771)
+++ src/lyx_main.C	(working copy)
@@ -238,9 +238,9 @@
 	if (files.empty() && lyxrc.load_session) {
 		vector<string> const & lastopened = session_->lastOpenedFiles();
 		files.insert(files.end(), lastopened.begin(), lastopened.end()  );
-		// clear this list to save a few bytes of RAM
-		session_->clearLastOpenedFiles();
 	}
+	// clear this list to save a few bytes of RAM
+	session_->clearLastOpenedFiles();
 
 	// Execute batch commands if available
 	if (!batch_command.empty()) {

Reply via email to