From 2ce7c41f03b733a458736fe607f7b88b1e8d9c1b Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 28 May 2008 00:25:42 +0000 Subject: [PATCH] Fix bug 4097: Give LyX an intelligent return value on file load errors. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24976 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyX.cpp | 32 +++++++++++++++++++------------- src/LyX.h | 3 ++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/LyX.cpp b/src/LyX.cpp index 0131eb95f9..0d4d2053eb 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -380,11 +380,12 @@ int LyX::exec(int & argc, char * argv[]) return exit_status; } - loadFiles(); + // this is correct, since return values are inverted. + exit_status = !loadFiles(); if (pimpl_->batch_command.empty() || pimpl_->buffer_list_.empty()) { prepareExit(); - return EXIT_SUCCESS; + return exit_status; } BufferList::iterator begin = pimpl_->buffer_list_.begin(); @@ -530,8 +531,10 @@ void LyX::addFileToLoad(string const & fname) } -void LyX::loadFiles() +bool LyX::loadFiles() { + LASSERT(!use_gui, /**/); + bool success = true; vector::const_iterator it = pimpl_->files_to_load_.begin(); vector::const_iterator end = pimpl_->files_to_load_.end(); @@ -551,9 +554,12 @@ void LyX::loadFiles() for_each(el.begin(), el.end(), boost::bind(&LyX::printError, this, _1)); } - else + else { pimpl_->buffer_list_.release(buf); + success = false; + } } + return success; } @@ -565,15 +571,15 @@ void LyX::execBatchCommands() // if reconfiguration is needed. while (LayoutFileList::get().empty()) { - switch (Alert::prompt( - _("No textclass is found"), - _("LyX cannot continue because no textclass is found. " - "You can either reconfigure normally, or reconfigure using " - "default textclasses, or quit LyX."), - 0, 2, - _("&Reconfigure"), - _("&Use Default"), - _("&Exit LyX"))) + switch (Alert::prompt( + _("No textclass is found"), + _("LyX cannot continue because no textclass is found. " + "You can either reconfigure normally, or reconfigure using " + "default textclasses, or quit LyX."), + 0, 2, + _("&Reconfigure"), + _("&Use Default"), + _("&Exit LyX"))) { case 0: // regular reconfigure diff --git a/src/LyX.h b/src/LyX.h index 5a82c9037c..cee66fa102 100644 --- a/src/LyX.h +++ b/src/LyX.h @@ -120,10 +120,11 @@ private: int init(int & argc, char * argv[]); /// Load files passed at command-line. + /// return true on success false if we encounter an error /** This method is used only in non-GUI mode. */ - void loadFiles(); + bool loadFiles(); /// initial LyX set up bool init();