X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLyX.cpp;h=66ff6f3dbed227559ab8d99e98aa4ed038bc8a79;hb=57b69a5efddf9f3c148007322f00dad6c253a2ed;hp=a1fdac914007501829a8820767cf3bc781c59d30;hpb=bdc997726438fb63a671e5f2569e0f57d5ae0c1e;p=lyx.git diff --git a/src/LyX.cpp b/src/LyX.cpp index a1fdac9140..66ff6f3dbe 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -50,6 +50,7 @@ #include "frontends/alert.h" #include "frontends/Application.h" +#include "support/bind.h" #include "support/ConsoleApplication.h" #include "support/lassert.h" #include "support/debug.h" @@ -61,9 +62,7 @@ #include "support/Messages.h" #include "support/os.h" #include "support/Package.h" - -#include "support/bind.h" -#include +#include "support/unique_ptr.h" #include #include @@ -150,13 +149,13 @@ struct LyX::Impl { /// CmdDef toplevel_cmddef_; /// - boost::scoped_ptr lyx_server_; + unique_ptr lyx_server_; /// - boost::scoped_ptr lyx_socket_; + unique_ptr lyx_socket_; /// - boost::scoped_ptr application_; + unique_ptr application_; /// lyx session, containing lastfiles, lastfilepos, and lastopened - boost::scoped_ptr session_; + unique_ptr session_; /// Files to load at start. vector files_to_load_; @@ -404,10 +403,8 @@ void LyX::prepareExit() LYXERR(Debug::INFO, "Deleting tmp dir " << package().temp_dir().absFileName()); if (!package().temp_dir().destroyDirectory()) { - docstring const msg = - bformat(_("Unable to remove the temporary directory %1$s"), - from_utf8(package().temp_dir().absFileName())); - Alert::warning(_("Unable to remove temporary directory"), msg); + LYXERR0(bformat(_("Unable to remove the temporary directory %1$s"), + from_utf8(package().temp_dir().absFileName()))); } } } @@ -474,21 +471,52 @@ int LyX::execWithoutGui(int & argc, char * argv[]) return exit_status; } - // this is correct, since return values are inverted. - exit_status = !loadFiles(); + // Used to keep track of which buffers were explicitly loaded by user request. + // This is necessary because master and child document buffers are loaded, even + // if they were not named on the command line. We do not want to dispatch to + // those. + vector command_line_buffers; + + // Load the files specified on the command line + vector::const_iterator it = pimpl_->files_to_load_.begin(); + vector::const_iterator end = pimpl_->files_to_load_.end(); + for (; it != end; ++it) { + // get absolute path of file and add ".lyx" to the filename if necessary + FileName fname = fileSearch(string(), os::internal_path(*it), "lyx", + may_not_exist); + + if (fname.empty()) + continue; + + Buffer * buf = pimpl_->buffer_list_.newBuffer(fname.absFileName()); + LYXERR(Debug::FILES, "Loading " << fname); + if (buf && buf->loadLyXFile() == Buffer::ReadSuccess) { + ErrorList const & el = buf->errorList("Parse"); + if (!el.empty()) + for_each(el.begin(), el.end(), + bind(&LyX::printError, this, _1)); + command_line_buffers.push_back(buf); + } else { + if (buf) + pimpl_->buffer_list_.release(buf); + docstring const error_message = + bformat(_("LyX failed to load the following file: %1$s"), + from_utf8(fname.absFileName())); + lyxerr << to_utf8(error_message) << endl; + exit_status = 1; // failed + } + } - if (pimpl_->batch_commands.empty() || pimpl_->buffer_list_.empty()) { + if (exit_status || pimpl_->batch_commands.empty() || pimpl_->buffer_list_.empty()) { prepareExit(); return exit_status; } - BufferList::iterator begin = pimpl_->buffer_list_.begin(); - + // Iterate through the buffers that were specified on the command line bool final_success = false; - for (BufferList::iterator I = begin; I != pimpl_->buffer_list_.end(); ++I) { - Buffer * buf = *I; - if (buf != buf->masterBuffer()) - continue; + vector::iterator buf_it = command_line_buffers.begin(); + for (; buf_it != command_line_buffers.end(); ++buf_it) { + Buffer * buf = *buf_it; vector::const_iterator bcit = pimpl_->batch_commands.begin(); vector::const_iterator bcend = pimpl_->batch_commands.end(); DispatchResult dr; @@ -503,42 +531,6 @@ int LyX::execWithoutGui(int & argc, char * argv[]) } -bool LyX::loadFiles() -{ - LATTEST(!use_gui); - bool success = true; - vector::const_iterator it = pimpl_->files_to_load_.begin(); - vector::const_iterator end = pimpl_->files_to_load_.end(); - - for (; it != end; ++it) { - // get absolute path of file and add ".lyx" to - // the filename if necessary - FileName fname = fileSearch(string(), os::internal_path(*it), "lyx", - may_not_exist); - - if (fname.empty()) - continue; - - Buffer * buf = pimpl_->buffer_list_.newBuffer(fname.absFileName()); - if (buf->loadLyXFile() == Buffer::ReadSuccess) { - ErrorList const & el = buf->errorList("Parse"); - if (!el.empty()) - for_each(el.begin(), el.end(), - bind(&LyX::printError, this, _1)); - } - else { - pimpl_->buffer_list_.release(buf); - docstring const error_message = - bformat(_("LyX failed to load the following file: %1$s"), - from_utf8(fname.absFileName())); - lyxerr << to_utf8(error_message) << endl; - success = false; - } - } - return success; -} - - void execBatchCommands() { LAPPERR(singleton_); @@ -1423,7 +1415,7 @@ Server & theServer() // FIXME: this should not be use_gui dependent LWARNIF(use_gui); LAPPERR(singleton_); - return *singleton_->pimpl_->lyx_server_.get(); + return *singleton_->pimpl_->lyx_server_; } @@ -1432,7 +1424,7 @@ ServerSocket & theServerSocket() // FIXME: this should not be use_gui dependent LWARNIF(use_gui); LAPPERR(singleton_); - return *singleton_->pimpl_->lyx_socket_.get(); + return *singleton_->pimpl_->lyx_socket_; }