From b762358eece897036f43b46c3b5da960788301c0 Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Wed, 26 Sep 2007 19:36:09 +0000 Subject: [PATCH] Lyx now starts and asks for reconfigure if no textclass is found (bug 2829) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20522 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyX.cpp | 30 ++++++++++++++++++++++++++++++ src/LyXFunc.cpp | 3 ++- src/TextClassList.cpp | 12 +++++++----- src/TextClassList.h | 2 ++ src/callback.cpp | 5 +++-- src/callback.h | 2 +- 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/LyX.cpp b/src/LyX.cpp index 21de3ff6cf..fa03e2550c 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -615,6 +615,32 @@ void LyX::execBatchCommands() // aknowledged. restoreGuiSession(); + // if reconfiguration is needed. + if (textclasslist.empty()) { + switch (Alert::prompt( + _("No textclass is found"), + _("LyX can not continue because no textclass is found. " + "You can either reconfigure normally, or reconfigure using " + "default text classes, or quit lyx."), + 0, 2, + _("&Reconfigure"), + _("&Use Default"), + _("&Exit LyX"))) + { + case 0: + // regular reconfigure + pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_RECONFIGURE, "")); + break; + case 1: + // reconfigure --without-latex-config + pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_RECONFIGURE, + " --without-latex-config")); + break; + } + pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_LYX_QUIT)); + return; + } + // Execute batch commands if available if (batch_command.empty()) return; @@ -630,6 +656,10 @@ void LyX::restoreGuiSession() { LyXView * view = newLyXView(); + // if there is no valid class list, do not load any file. + if (textclasslist.empty()) + return; + // 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()) { diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 07238163b7..96cbc25e0c 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -1200,7 +1200,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd) case LFUN_RECONFIGURE: BOOST_ASSERT(lyx_view_); - reconfigure(*lyx_view_); + // argument is any additional parameter to the configure.py command + reconfigure(*lyx_view_, argument); break; case LFUN_HELP_OPEN: { diff --git a/src/TextClassList.cpp b/src/TextClassList.cpp index bfda9d35d5..708b1ac534 100644 --- a/src/TextClassList.cpp +++ b/src/TextClassList.cpp @@ -165,13 +165,15 @@ bool TextClassList::read() } LYXERR(Debug::TCLASS) << "End of parsing of textclass.lst" << endl; - if (classlist_.empty()) { + // lyx will start with an empty classlist_, but only reconfigure is allowed + // in this case. This gives users a second chance to configure lyx if + // initial configuration fails. (c.f. bug 2829) + if (classlist_.empty()) lyxerr << "TextClassList::Read: no textclasses found!" << endl; - return false; - } - // Ok everything loaded ok, now sort the list. - sort(classlist_.begin(), classlist_.end(), less_textclass_avail_desc()); + else + // Ok everything loaded ok, now sort the list. + sort(classlist_.begin(), classlist_.end(), less_textclass_avail_desc()); return true; } diff --git a/src/TextClassList.h b/src/TextClassList.h index 740b87f536..2931bab695 100644 --- a/src/TextClassList.h +++ b/src/TextClassList.h @@ -40,6 +40,8 @@ public: const_iterator begin() const { return classlist_.begin(); } /// const_iterator end() const { return classlist_.end(); } + /// + bool empty() const { return classlist_.empty(); } /// Gets textclass number from name, -1 if textclass name does not exist std::pair const diff --git a/src/callback.cpp b/src/callback.cpp index 2a41494be6..bde105b616 100644 --- a/src/callback.cpp +++ b/src/callback.cpp @@ -436,14 +436,15 @@ docstring const getContentsOfPlaintextFile(BufferView * bv, string const & f, // This function runs "configure" and then rereads lyx.defaults to // reconfigure the automatic settings. -void reconfigure(LyXView & lv) +void reconfigure(LyXView & lv, string const & option) { // emit message signal. lv.message(_("Running configure...")); // Run configure in user lyx directory support::Path p(package().user_support()); - string const configure_command = package().configure_command(); + string configure_command = package().configure_command(); + configure_command += option; Systemcall one; one.startscript(Systemcall::Wait, configure_command); p.pop(); diff --git a/src/callback.h b/src/callback.h index 716e30b942..3fe910eb22 100644 --- a/src/callback.h +++ b/src/callback.h @@ -40,7 +40,7 @@ void insertPlaintextFile(BufferView * bv, std::string const & f, bool asParagrap docstring const getContentsOfPlaintextFile(BufferView * bv, std::string const & f, bool asParagraph); /// -void reconfigure(frontend::LyXView & lv); +void reconfigure(frontend::LyXView & lv, std::string const & option); } // namespace lyx