diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 3dbd9b7e96..c18e9b9e7d 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -1225,10 +1225,19 @@ void BufferParams::setTextClass(TextClass_ptr tc) { } -void BufferParams::setBaseClass(textclass_type tc) +bool BufferParams::setBaseClass(textclass_type tc) { + if (!textclasslist[tc].load()) { + 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; + } + baseClass_ = tc; makeTextClass(); + return true; } diff --git a/src/BufferParams.h b/src/BufferParams.h index 7922c66792..620b78e2a9 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -103,7 +103,7 @@ public: ///Set the LyX TextClass (that is, the layout file) this document is using. ///NOTE This also calls makeTextClass(), to update the local ///TextClass. - void setBaseClass(textclass_type); + bool setBaseClass(textclass_type); ///Returns the TextClass currently in use: the BaseClass as modified ///by modules. TextClass const & getTextClass() const; diff --git a/src/frontends/controllers/ControlDocument.cpp b/src/frontends/controllers/ControlDocument.cpp index e7452ac2be..d2ef46d55b 100644 --- a/src/frontends/controllers/ControlDocument.cpp +++ b/src/frontends/controllers/ControlDocument.cpp @@ -111,25 +111,12 @@ void ControlDocument::dispatchParams() // This must come first so that a language change is correctly noticed setLanguage(); - // Set the document class. - textclass_type const old_class = - kernel().buffer().params().getBaseClass(); - textclass_type const new_class = bp_->getBaseClass(); - if (new_class != old_class) { - string const name = textclasslist[new_class].name(); - kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_APPLY, name)); - } - - int const old_secnumdepth = kernel().buffer().params().secnumdepth; - int const new_secnumdepth = bp_->secnumdepth; - - // Apply the BufferParams. + // Apply the BufferParams. Note that this will set the base class + // and then update the buffer's layout. + //FIXME Could this be done last? Then, I think, we'd get the automatic + //update mentioned in the next FIXME... dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_PARAMS_APPLY); - // redo the numbering if necessary - if (new_secnumdepth != old_secnumdepth) - updateLabels(kernel().buffer()); - // Generate the colours requested by each new branch. BranchList & branchlist = params().branchlist(); if (!branchlist.empty()) { @@ -166,17 +153,6 @@ void ControlDocument::setLanguage() const } -bool ControlDocument::loadTextclass(textclass_type tc) const -{ - string const name = textclasslist[tc].name(); - kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_LOAD, name)); - - // Report back whether we were able to change the class. - bool const success = textclasslist[tc].loaded(); - return success; -} - - void ControlDocument::saveAsDefault() const { dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_SAVE_AS_DEFAULT); diff --git a/src/frontends/controllers/ControlDocument.h b/src/frontends/controllers/ControlDocument.h index 71f7d01122..2e725bfa0a 100644 --- a/src/frontends/controllers/ControlDocument.h +++ b/src/frontends/controllers/ControlDocument.h @@ -59,8 +59,6 @@ public: /// void saveAsDefault() const; /// - bool loadTextclass(textclass_type tc) const; - /// bool const isFontAvailable(std::string const & font) const; /// does this font provide Old Style figures? bool const providesOSF(std::string const & font) const; diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 8f61c641eb..954a433e3d 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -825,19 +825,12 @@ void GuiDocumentDialog::updatePagestyle(string const & items, string const & sel void GuiDocumentDialog::classChanged() { - ControlDocument & cntrl = form_->controller(); - BufferParams & params = cntrl.params(); - + BufferParams & params = form_->controller().params(); textclass_type const tc = latexModule->classCO->currentIndex(); - - if (form_->controller().loadTextclass(tc)) { - params.setJustBaseClass(tc); - if (lyxrc.auto_reset_options) - params.useClassDefaults(); - form_->update_contents(); - } else { - latexModule->classCO->setCurrentIndex(params.getBaseClass()); - } + params.setJustBaseClass(tc); + if (lyxrc.auto_reset_options) + params.useClassDefaults(); + form_->update_contents(); }