+
+void LyX::execBatchCommands()
+{
+ // The advantage of doing this here is that the event loop
+ // is already started. So any need for interaction will be
+ // aknowledged.
+ restoreGuiSession();
+
+ // Execute batch commands if available
+ if (batch_command.empty())
+ return;
+
+ lyxerr[Debug::INIT] << "About to handle -x '"
+ << batch_command << '\'' << endl;
+
+ pimpl_->lyxfunc_.dispatch(lyxaction.lookupFunc(batch_command));
+}
+
+
+void LyX::restoreGuiSession()
+{
+ LyXView * view = newLyXView();
+
+ // if some files were specified at command-line we assume that the
+ // user wants to edit *these* files and not to restore the session.
+ if (!pimpl_->files_to_load_.empty()) {
+ for_each(pimpl_->files_to_load_.begin(),
+ pimpl_->files_to_load_.end(),
+ bind(&LyXView::loadLyXFile, view, _1, true));
+ // clear this list to save a few bytes of RAM
+ pimpl_->files_to_load_.clear();
+ pimpl_->session_->lastOpened().clear();
+ return;
+ }
+
+ if (!lyxrc.load_session)
+ return;
+
+ vector<FileName> const & lastopened = pimpl_->session_->lastOpened().getfiles();
+ // do not add to the lastfile list since these files are restored from
+ // last session, 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();