Looking forward to the real solution then :-)

The real patch is attached. :-) Please test.

Note that
1. can not compile and test gtk
2. tested under linux, with qt3/4, windows, msvc/qt4
3. Scroll bar does not work (linux qt3/qt4, windows qt4), but does not
seem to be related to my patch.
4. We should find a better place for the LyxSocket stuff, which is
currently in create_view.

Bo
Index: src/frontends/gtk/lyx_gui.C
===================================================================
--- src/frontends/gtk/lyx_gui.C	(revision 14498)
+++ src/frontends/gtk/lyx_gui.C	(working copy)
@@ -140,8 +140,7 @@
 }
 
 
-int lyx_gui::start(string const & batch, std::vector<string> const & files,
-		   unsigned int width, unsigned int height,
+LyXView * lyx_gui::create_view(unsigned int width, unsigned int height,
 		   int /*posx*/, int /*posy*/, bool)
 {
 	int view_id = theApp->gui().newView(width, height);
@@ -158,13 +157,14 @@
 	lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
 	lyxsocket = new LyXServerSocket(&view.getLyXFunc(),
 			  os::internal_path(package().temp_dir() + "/lyxsocket"));
+}
 
-	for_each(files.begin(), files.end(),
-		 bind(&LyXView::loadLyXFile, &view, _1, true));
 
+int lyx_gui::start(LyXView * view, string const & batch)
+{
 	// handle the batch commands the user asked for
 	if (!batch.empty()) {
-		view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
+		view->getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
 	}
 
 	theApp->run();
Index: src/frontends/qt3/lyx_gui.C
===================================================================
--- src/frontends/qt3/lyx_gui.C	(revision 14498)
+++ src/frontends/qt3/lyx_gui.C	(working copy)
@@ -233,8 +233,8 @@
 {}
 
 
-int start(string const & batch, vector<string> const & files,
-          unsigned int width, unsigned int height, int posx, int posy, bool maximize)
+LyXView* create_view(unsigned int width, unsigned int height, int posx, int posy,
+	      bool maximize)
 {
 	// this can't be done before because it needs the Languages object
 	initEncodings();
@@ -263,13 +263,15 @@
 	lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
 	lyxsocket = new LyXServerSocket(&view.getLyXFunc(),
 			  os::internal_path(package().temp_dir() + "/lyxsocket"));
+	return &view;
+}
 
-	for_each(files.begin(), files.end(),
-		 bind(&LyXView::loadLyXFile, &view, _1, true));
 
+int start(LyXView * view, string const & batch)
+{
 	// handle the batch commands the user asked for
 	if (!batch.empty()) {
-		view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
+		view->getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
 	}
 
 	int const status = qApp->exec();
Index: src/frontends/qt4/lyx_gui.C
===================================================================
--- src/frontends/qt4/lyx_gui.C	(revision 14498)
+++ src/frontends/qt4/lyx_gui.C	(working copy)
@@ -194,8 +194,7 @@
 {}
 
 
-int start(string const & batch, vector<string> const & files,
-          unsigned int width, unsigned int height, int posx, int posy,
+LyXView * create_view(unsigned int width, unsigned int height, int posx, int posy,
           bool maximize)
 {
 	// this can't be done before because it needs the Languages object
@@ -238,13 +237,15 @@
 	lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
 	lyxsocket = new LyXServerSocket(&view.getLyXFunc(),
 			  os::internal_path(package().temp_dir() + "/lyxsocket"));
+	return &view;
+}
 
-	for_each(files.begin(), files.end(),
-		 bind(&LyXView::loadLyXFile, &view, _1, true));
 
+int start(LyXView * view, string const & batch)
+{
 	// handle the batch commands the user asked for
 	if (!batch.empty()) {
-		view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
+		view->getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
 	}
 
 	int const status = qApp->exec();
Index: src/frontends/lyx_gui.h
===================================================================
--- src/frontends/lyx_gui.h	(revision 14498)
+++ src/frontends/lyx_gui.h	(working copy)
@@ -27,6 +27,7 @@
 class LyXDataSocket;
 class LyXServerSocket;
 class FuncRequest;
+class LyXView;
 namespace lyx {
 struct RGBColor;
 }
@@ -53,12 +54,16 @@
 void parse_lyxrc();
 
 /**
+ * Create the main window with given geometry settings
+ */
+LyXView * create_view(unsigned int width, unsigned int height, int posx, int posy,
+	      bool maximize);
+
+/**
  * Start the main event loop, after executing the given
- * batch commands, and loading the given documents
+ * batch commands
  */
-int start(std::string const & batch, std::vector<std::string> const & files,
-          unsigned int width, unsigned int height, int posx, int posy,
-          bool maximize);
+int start(LyXView* view, std::string const & batch);
 
 /**
  * Enter the main event loop (\sa LyX::exec2)
Index: src/lyx_main.C
===================================================================
--- src/lyx_main.C	(revision 14498)
+++ src/lyx_main.C	(working copy)
@@ -259,14 +259,6 @@
 	if (first_start)
 		files.push_back(i18nLibFileSearch("examples", "splash.lyx"));
 
-	// if a file is specified, I assume that user wants to edit *that* file
-	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();
-
 	// Execute batch commands if available
 	if (!batch_command.empty()) {
 
@@ -355,9 +347,26 @@
 			width = 0;
 			height = 0;
 		}
+		// create the main window
+		LyXView * view = lyx_gui::create_view(width, height, posx, posy, maximize);
+		
+		// load files
+		for_each(files.begin(), files.end(),
+			bind(&LyXView::loadLyXFile, view, _1, true));
 
-		return lyx_gui::start(batch_command, files, width, height, posx, posy, maximize);
+		// if a file is specified, I assume that user wants to edit *that* file
+		if (files.empty() && lyxrc.load_session) {
+			vector<string> const & lastopened = session_->lastOpenedFiles();
+			// do not add to the lastfile list since these files are restored from
+			// last seesion, and should be already there (regular files), or should
+			// not be added at all (help files).
+			for_each(lastopened.begin(), lastopened.end(),
+				bind(&LyXView::loadLyXFile, view, _1, false));
+		}
+		// clear this list to save a few bytes of RAM
+		session_->clearLastOpenedFiles();
 
+		return lyx_gui::start(view, batch_command);
 	} else {
 		// Something went wrong above
 		quitLyX(false);

Reply via email to