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
This commit is contained in:
Richard Heck 2007-09-01 04:03:24 +00:00
parent 1588f9d201
commit d7a33bc841
5 changed files with 20 additions and 44 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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());
}
}