X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyx_main.C;h=cc856fb70a4e3a8aaca7f0a644e1d1af14e227e5;hb=3815df7705b09920f9bb60c6fd9ee0576fe0a834;hp=874f10d8c024190f4e455627d17feeb33230cbfd;hpb=6c300f72a217722652dc27db9108e1050028979c;p=lyx.git diff --git a/src/lyx_main.C b/src/lyx_main.C index 874f10d8c0..cc856fb70a 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -44,6 +44,7 @@ #include "frontends/Alert.h" #include "frontends/Application.h" +#include "frontends/Gui.h" #include "frontends/LyXView.h" #include "support/environment.h" @@ -284,11 +285,6 @@ kb_keymap const & LyX::topLevelKeymap() const return *pimpl_->toplevel_keymap_.get(); } -void LyX::addLyXView(LyXView * lyxview) -{ - views_.push_back(lyxview); -} - Buffer const * const LyX::updateInset(InsetBase const * inset) const { @@ -296,10 +292,12 @@ Buffer const * const LyX::updateInset(InsetBase const * inset) const return 0; Buffer const * buffer_ptr = 0; - ViewList::const_iterator it = views_.begin(); - ViewList::const_iterator const end = views_.end(); + vector const & view_ids = pimpl_->application_->gui().viewIds(); + vector::const_iterator it = view_ids.begin(); + vector::const_iterator const end = view_ids.end(); for (; it != end; ++it) { - Buffer const * ptr = (*it)->updateInset(inset); + Buffer const * ptr = + pimpl_->application_->gui().view(*it).updateInset(inset); if (ptr) buffer_ptr = ptr; } @@ -333,9 +331,10 @@ int LyX::priv_exec(int & argc, char * argv[]) // Start the real execution loop. // FIXME - /* Create a CoreApplication class that will provide the main event loop and - * the socket callback registering. With Qt4, only QtCore library would be needed. - * When this done, a server_mode could be created and the following two + /* Create a CoreApplication class that will provide the main event loop + * and the socket callback registering. With Qt4, only QtCore + * library would be needed. + * When this is done, a server_mode could be created and the following two * line would be moved out from here. */ pimpl_->lyx_server_.reset(new LyXServer(&pimpl_->lyxfunc_, lyxrc.lyxpipes)); @@ -394,20 +393,14 @@ void LyX::earlyExit(int status) } -void LyX::quit(bool noask) +void LyX::quit() { lyxerr[Debug::INFO] << "Running QuitLyX." << endl; - if (use_gui) { - if (!noask && !pimpl_->buffer_list_.quitWriteAll()) - return; - - pimpl_->session_->writeFile(); - } - prepareExit(); if (use_gui) { + pimpl_->session_->writeFile(); pimpl_->lyx_server_.reset(); pimpl_->lyx_socket_.reset(); pimpl_->application_->exit(0); @@ -492,6 +485,31 @@ int LyX::execBatchCommands(int & argc, char * argv[], void LyX::restoreGuiSession(vector const & files) { + LyXView * view = newLyXView(); + + // load files + for_each(files.begin(), files.end(), + bind(&LyXView::loadLyXFile, view, _1, true)); + + // if a file is specified, I assume that user wants to edit *that* file + if (files.empty() && lyxrc.load_session) { + vector const & lastopened = pimpl_->session_->lastOpened().getfiles(); + // 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 + pimpl_->session_->lastOpened().clear(); +} + + +LyXView * LyX::newLyXView() +{ + if (!lyx::use_gui) + return 0; + // determine windows size and position, from lyxrc and/or session // initial geometry unsigned int width = 690; @@ -504,23 +522,24 @@ void LyX::restoreGuiSession(vector const & files) } // if lyxrc returns (0,0), then use session info else { - string val = session().loadSessionInfo("WindowWidth"); + string val = session().sessionInfo().load("WindowWidth"); if (!val.empty()) width = convert(val); - val = session().loadSessionInfo("WindowHeight"); + val = session().sessionInfo().load("WindowHeight"); if (!val.empty()) height = convert(val); - if (session().loadSessionInfo("WindowIsMaximized") == "yes") + if (session().sessionInfo().load("WindowIsMaximized") == "yes") maximize = true; } + // if user wants to restore window position int posx = -1; int posy = -1; if (lyxrc.geometry_xysaved) { - string val = session().loadSessionInfo("WindowPosX"); + string val = session().sessionInfo().load("WindowPosX"); if (!val.empty()) posx = convert(val); - val = session().loadSessionInfo("WindowPosY"); + val = session().sessionInfo().load("WindowPosY"); if (!val.empty()) posy = convert(val); } @@ -531,26 +550,10 @@ void LyX::restoreGuiSession(vector const & files) } // create the main window LyXView * view = &pimpl_->application_->createView(width, height, posx, posy, maximize); - ref().addLyXView(view); - // load files - for_each(files.begin(), files.end(), - bind(&LyXView::loadLyXFile, view, _1, true)); - - // if a file is specified, I assume that user wants to edit *that* file - if (files.empty() && lyxrc.load_session) { - vector const & lastopened = pimpl_->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 - pimpl_->session_->clearLastOpenedFiles(); + return view; } - /* Signals and Windows =================== @@ -725,6 +728,9 @@ bool LyX::init() // Query the OS to know what formats are viewed natively formats.setAutoOpen(); + // Read lyxrc.dist again to be able to override viewer auto-detection. + readRcFile("lyxrc.dist"); + system_lyxrc = lyxrc; system_formats = formats; system_converters = converters; @@ -1300,15 +1306,3 @@ kb_keymap & theTopLevelKeymap() } } // namespace lyx - - -namespace boost { - -void assertion_failed(char const* a, char const* b, char const* c, long d) -{ - lyx::lyxerr << "Assertion failed: " << a << ' ' << b << ' ' << c << ' ' - << d << '\n'; -} - -} // boost -