diff --git a/src/frontends/gtk/lyx_gui.C b/src/frontends/gtk/lyx_gui.C index ea07200152..3076e741f8 100644 --- a/src/frontends/gtk/lyx_gui.C +++ b/src/frontends/gtk/lyx_gui.C @@ -140,8 +140,7 @@ void lyx_gui::parse_lyxrc() } -int lyx_gui::start(string const & batch, std::vector 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); @@ -153,18 +152,21 @@ int lyx_gui::start(string const & batch, std::vector const & files, view.show(); view.init(); + return &view; +} + + +int lyx_gui::start(LyXView * view, string const & batch) +{ // FIXME: server code below needs moving - lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes); - lyxsocket = new LyXServerSocket(&view.getLyXFunc(), + 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)); - // 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(); diff --git a/src/frontends/lyx_gui.h b/src/frontends/lyx_gui.h index aa73b4ae4c..4fd080f3a2 100644 --- a/src/frontends/lyx_gui.h +++ b/src/frontends/lyx_gui.h @@ -27,6 +27,7 @@ class LyXComm; class LyXDataSocket; class LyXServerSocket; class FuncRequest; +class LyXView; namespace lyx { struct RGBColor; } @@ -53,12 +54,16 @@ std::string const typewriter_font_name(); void parse_lyxrc(); /** - * Start the main event loop, after executing the given - * batch commands, and loading the given documents + * Create the main window with given geometry settings */ -int start(std::string const & batch, std::vector 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); + +/** + * Start the main event loop, after executing the given + * batch commands + */ +int start(LyXView* view, std::string const & batch); /** * Enter the main event loop (\sa LyX::exec2) diff --git a/src/frontends/qt3/lyx_gui.C b/src/frontends/qt3/lyx_gui.C index 33cc8f9c13..4ff2dfc0f1 100644 --- a/src/frontends/qt3/lyx_gui.C +++ b/src/frontends/qt3/lyx_gui.C @@ -233,8 +233,8 @@ void parse_lyxrc() {} -int start(string const & batch, vector 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(); @@ -258,18 +258,21 @@ int start(string const & batch, vector const & files, } else view.show(); + return &view; +} + + +int start(LyXView * view, string const & batch) +{ // FIXME: some code below needs moving - lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes); - lyxsocket = new LyXServerSocket(&view.getLyXFunc(), + 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)); - // 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(); diff --git a/src/frontends/qt4/lyx_gui.C b/src/frontends/qt4/lyx_gui.C index cdf6e9a292..9f5aded103 100644 --- a/src/frontends/qt4/lyx_gui.C +++ b/src/frontends/qt4/lyx_gui.C @@ -194,8 +194,7 @@ void parse_lyxrc() {} -int start(string const & batch, vector 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 @@ -233,18 +232,21 @@ int start(string const & batch, vector const & files, view.show(); + return &view; +} + + +int start(LyXView * view, string const & batch) +{ // FIXME: some code below needs moving - lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes); - lyxsocket = new LyXServerSocket(&view.getLyXFunc(), + 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)); - // 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(); diff --git a/src/lyx_main.C b/src/lyx_main.C index 02c9758989..5a3978a824 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -259,14 +259,6 @@ int LyX::exec2(int & argc, char * argv[]) 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 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 @@ int LyX::exec2(int & argc, char * argv[]) 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 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);