load files from lyx_main.C instead of lyx_gui.C, do not add session-restored files to lastfile list.

* src/frontends/lyx_gui.h: add prototype for create_view
	* src/frontends/(gtk,qt3,qt4)/lyx_gui.C: separate start()
	* src/lyx_main.C: call create_view, load file, and call start


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14500 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2006-07-27 14:13:45 +00:00
parent 857eb02a5c
commit c8e5ee867f
5 changed files with 59 additions and 38 deletions

View File

@ -140,8 +140,7 @@ void lyx_gui::parse_lyxrc()
}
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);
@ -153,18 +152,21 @@ int lyx_gui::start(string const & batch, std::vector<string> 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();

View File

@ -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<std::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);
/**
* 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)

View File

@ -233,8 +233,8 @@ void parse_lyxrc()
{}
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();
@ -258,18 +258,21 @@ int start(string const & batch, vector<string> 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();

View File

@ -194,8 +194,7 @@ void parse_lyxrc()
{}
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
@ -233,18 +232,21 @@ int start(string const & batch, vector<string> 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();

View File

@ -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<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 @@ 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<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);