From: Richard Heck Date: Sat, 1 Sep 2007 04:03:24 +0000 (+0000) Subject: This patch continues 19964. It takes advantage of the work there to simplify a few... X-Git-Tag: 1.6.10~8580 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=d7a33bc841e75fb746778f937336bc347fb32d8a;p=lyx.git This patch continues 19964. It takes advantage of the work there to simplify a few things elsewhere. First, in ControlDocument::dispatchParams(), we're setting the TextClass and then dispatching the BufferParams, which sets it again now. So we can get rid of the first call. This, however, requires loading the TextClass somewhere other than LFUN_TEXTCLASS_APPLY, which I do in BufferParams::setBaseClass(), which is when you'd actually need to do it. So I've moved some of the loading logic there. (It seemed a good idea to make setBaseClass() return whether it was successful, then, though this isn't used at the moment.) That makes another simplification both possible and desirable. For some reason, whenever you change the Document Class combobox in Document Settings, LyX tries to read whatever you choose _before_ you try to hit "Apply". Why? I see no good reason. You get the warning earlier that way, but maybe you weren't going to try to load it anyway and were going to change your mind. So I have removed that behavior, in which case you'll get the warning when you try to apply the parameters. This means we can also remove ControlDocument::loadTextclass(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19965 a592a061-630c-0410-9148-cb99ea01b6c8 --- 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(); }