From aebd5ebaf9d804640b8f37e54dcce90ebd409b08 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Sat, 8 Sep 2007 17:46:02 +0000 Subject: [PATCH] Fix crash when layout file cannot be read due to failure to call makeTextClass() in that case. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20150 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 5 +++-- src/BufferParams.cpp | 15 ++++++++------- src/LyXAction.cpp | 1 + src/LyXFunc.cpp | 13 +++++++++++++ src/TextClassList.cpp | 19 +++++++++++++++---- src/TextClassList.h | 3 +++ src/lfuns.h | 1 + 7 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index bdf866fbe1..a7bca7bd37 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -531,8 +531,9 @@ bool Buffer::readDocument(Lexer & lex) BOOST_ASSERT(paragraphs().empty()); readHeader(lex); - if (!params().getTextClass().load(filePath())) { - string theclass = params().getTextClass().name(); + TextClass const & baseClass = textclasslist[params().getBaseClass()]; + if (!baseClass.load(filePath())) { + string theclass = baseClass.name(); Alert::error(_("Can't load document class"), bformat( _("Using the default document class, because the " "class %1$s could not be loaded."), from_utf8(theclass))); diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index b78056b529..e566cdd822 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -1227,17 +1227,18 @@ void BufferParams::setTextClass(TextClass_ptr tc) { bool BufferParams::setBaseClass(textclass_type tc) { - if (!textclasslist[tc].load()) { - docstring s = bformat(_("The document class %1$s." - "could not be loaded."), + bool retVal = true; + if (textclasslist[tc].load()) + baseClass_ = tc; + else { + docstring s = + bformat(_("The document class %1$s could not be loaded."), from_utf8(textclasslist[tc].name())); frontend::Alert::error(_("Could not load class"), s); - return false; + retVal = false; } - - baseClass_ = tc; makeTextClass(); - return true; + return retVal; } diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index fe2369cac8..d26b4dffeb 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -374,6 +374,7 @@ void LyXAction::init() { LFUN_LISTING_INSERT, "listing-insert", Noop }, { LFUN_LAYOUT_MODULES_CLEAR, "layout-modules-clear", Noop }, { LFUN_LAYOUT_MODULE_ADD, "layout-module-add", Noop }, + { LFUN_LAYOUT_RELOAD, "layout-reload", Noop }, { LFUN_NOACTION, "", Noop } }; diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 2dc4086bb4..ff466d0323 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -731,6 +731,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const case LFUN_BUFFER_PARAMS_APPLY: case LFUN_LAYOUT_MODULES_CLEAR: case LFUN_LAYOUT_MODULE_ADD: + case LFUN_LAYOUT_RELOAD: case LFUN_LYXRC_APPLY: case LFUN_BUFFER_NEXT: case LFUN_BUFFER_PREVIOUS: @@ -1835,6 +1836,18 @@ void LyXFunc::dispatch(FuncRequest const & cmd) updateFlags = Update::Force | Update::FitCursor; break; } + + case LFUN_LAYOUT_RELOAD: { + BOOST_ASSERT(lyx_view_); + Buffer * buffer = lyx_view_->buffer(); + TextClass_ptr oldClass = buffer->params().getTextClass_ptr(); + textclass_type const tc = buffer->params().getBaseClass(); + textclasslist.reset(tc); + buffer->params().setBaseClass(tc); + updateLayout(oldClass, buffer); + updateFlags = Update::Force | Update::FitCursor; + break; + } case LFUN_TEXTCLASS_LOAD: loadTextclass(argument); diff --git a/src/TextClassList.cpp b/src/TextClassList.cpp index aee1144668..bfda9d35d5 100644 --- a/src/TextClassList.cpp +++ b/src/TextClassList.cpp @@ -66,11 +66,12 @@ TextClassList::numberOfClass(string const & textclass) const TextClass const & TextClassList::operator[](textclass_type textclass) const { - classlist_[textclass].load(); - if (textclass < classlist_.size()) - return classlist_[textclass]; - else + if (textclass >= classlist_.size()) return classlist_[0]; + + //FIXME I don't believe the following line is actually necessary (rgh) + classlist_[textclass].load(); + return classlist_[textclass]; } @@ -175,6 +176,16 @@ bool TextClassList::read() } +void TextClassList::reset(textclass_type const textclass) { + if (textclass >= classlist_.size()) + return; + TextClass const & tc = classlist_[textclass]; + TextClass tmpl(tc.name(), tc.latexname(), tc.description(), + tc.isTeXClassAvailable()); + classlist_[textclass] = tmpl; +} + + std::pair const TextClassList::addTextClass(std::string const & textclass, std::string const & path) { diff --git a/src/TextClassList.h b/src/TextClassList.h index 6f8f963fc5..740b87f536 100644 --- a/src/TextClassList.h +++ b/src/TextClassList.h @@ -50,6 +50,9 @@ public: /// Read textclass list. Returns false if this fails. bool read(); + + /// Clears the textclass so as to force it to be reloaded + void reset(textclass_type const textclass); /// add a textclass from user local directory. /// Return ture/false, and textclass number diff --git a/src/lfuns.h b/src/lfuns.h index 4a6295abf6..299166c6a2 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -402,6 +402,7 @@ enum kb_action { LFUN_PARAGRAPH_PARAMS, // rgh, 200708XX LFUN_LAYOUT_MODULES_CLEAR, // rgh, 20070825 LFUN_LAYOUT_MODULE_ADD, // rgh, 20070825 + LFUN_LAYOUT_RELOAD, // rgh, 20070903 LFUN_LASTACTION // end of the table };