X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLyX.cpp;h=047e26515d813d397b1bec419b91441871aae5f8;hb=e335c764b47f8154973be212b446d9c13972cdf3;hp=b4c02168c8ed36f1d539d1030863eb6398245058;hpb=fdcff02a3124845d1033d3d804cede127850ff0f;p=lyx.git diff --git a/src/LyX.cpp b/src/LyX.cpp index b4c02168c8..047e26515d 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -61,13 +61,12 @@ #include "support/Messages.h" #include "support/os.h" #include "support/Package.h" - -#include "support/bind.h" -#include +#include "support/unique_ptr.h" #include -#include #include +#include +#include #include #include #include @@ -93,6 +92,12 @@ namespace os = support::os; bool use_gui = true; +// Report on the terminal about spawned commands. The default is false +// and can be changed with the option -v (--verbose). + +bool verbose = false; + + // We default to open documents in an already running instance, provided that // the lyxpipe has been setup. This can be overridden either on the command // line or through preference settings. @@ -150,13 +155,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 +409,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 +477,51 @@ 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"); + for(ErrorItem const & e : el) + printError(e); + 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 +536,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_); @@ -783,33 +780,35 @@ void cleanDuplicateEnvVars() static void initTemplatePath() { FileName const package_template_path = - FileName(addPath(package().system_support().absFileName(), "templates")); + FileName(addName(package().system_support().absFileName(), "templates")); if (lyxrc.template_path.empty()) { lyxrc.template_path = package_template_path.absFileName(); } #if defined (USE_MACOSX_PACKAGING) FileName const user_template_path = - FileName(addPath(package().user_support().absFileName(), "templates")); + FileName(addName(package().user_support().absFileName(), "templates")); if (package_template_path != FileName(lyxrc.template_path) && user_template_path != FileName(lyxrc.template_path)) { return; } - /// addPath cannot be used here. - /// The path with trailing slash doesn't work as symlink name. FileName const user_template_link = - FileName(user_template_path.absFileName() + "SystemTemplates"); - if (user_template_link.isSymLink()) { + FileName(addName(user_template_path.absFileName(),"SystemTemplates")); + if (user_template_link.isSymLink() && !equivalent(user_template_link, package_template_path)) { user_template_link.removeFile(); } if (!user_template_link.exists()) { if (!package_template_path.link(user_template_link)) { - LYXERR(Debug::INIT, "Cannot create symlink " + user_template_link.absFileName()); - lyxrc.template_path = package_template_path.absFileName(); + FileName const user_support = package().user_support(); + if (user_support.exists() && user_support.isDirectory()) { + LYXERR(Debug::INIT, "Cannot create symlink " + user_template_link.absFileName()); + lyxrc.template_path = package_template_path.absFileName(); + } return; } + LYXERR(Debug::INIT, "Symlink \"" << user_template_link.absFileName() << "\" created."); } lyxrc.template_path = user_template_path.absFileName(); #endif @@ -832,7 +831,7 @@ bool LyX::init() #endif lyxrc.tempdir_path = package().temp_dir().absFileName(); - lyxrc.document_path = package().document_dir().absFileName(); + lyxrc.document_path = "."; if (lyxrc.example_path.empty()) { lyxrc.example_path = addPath(package().system_support().absFileName(), @@ -883,6 +882,8 @@ bool LyX::init() if (queryUserLyXDir(package().explicit_user_support())) { package().reconfigureUserLyXDir(""); + // Now the user directory is present on first start. + initTemplatePath(); } fileUnlock(fd, lock_file.c_str()); } @@ -1113,7 +1114,7 @@ bool LyX::readEncodingsFile(string const & enc_name, namespace { /// return the the number of arguments consumed -typedef boost::function cmd_helper; +typedef function cmd_helper; int parse_dbg(string const & arg, string const &, string &) { @@ -1166,6 +1167,8 @@ int parse_help(string const &, string const &, string &) "\t-r [--remote]\n" " open documents in an already running instance\n" " (a working lyxpipe is needed)\n" + "\t-v [--verbose]\n" + " report on terminal about spawned commands.\n" "\t-batch execute commands without launching GUI and exit.\n" "\t-version summarize version and build info\n" "Check the LyX man page for more details.")) << endl; @@ -1300,6 +1303,13 @@ int parse_remote(string const &, string const &, string &) } +int parse_verbose(string const &, string const &, string &) +{ + verbose = true; + return 0; +} + + int parse_force(string const & arg, string const &, string &) { if (arg == "all") { @@ -1347,6 +1357,8 @@ void LyX::easyParse(int & argc, char * argv[]) cmdmap["--no-remote"] = parse_noremote; cmdmap["-r"] = parse_remote; cmdmap["--remote"] = parse_remote; + cmdmap["-v"] = parse_verbose; + cmdmap["--verbose"] = parse_verbose; for (int i = 1; i < argc; ++i) { map::const_iterator it @@ -1419,7 +1431,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_; } @@ -1428,7 +1440,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_; }