From 2baeac64ff6ccf435a2a02adf1e0c8b3d0f43e11 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Wed, 31 Mar 2004 09:44:40 +0000 Subject: [PATCH] Fix crash when changing text class. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8569 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 8 +++++++ src/lyxfunc.C | 59 ++++++++++++++++++++++++---------------------- src/lyxtextclass.C | 6 ++--- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index e9ffc0df95..44b40bfc1b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2004-03-31 Angus Leeming + + * lyxfunc.C (loadTextclass): new helper function, invoked by two of + dispatch's case blocks, LFUN_TEXTCLASS_APPLY and LFUN_TEXTCLASS_LOAD. + + * lyxtextclass.C (load): if the text class couldn't be loaded, then + don't overwrite 'loaded_ = false' with 'loaded_ = true' ! + 2004-03-31 Angus Leeming * lyxfunc.C (dispatch): remove the cursor-manipulation code from diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 0693b1e051..a2d72087c6 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -551,14 +551,38 @@ bool ensureBufferClean(BufferView * bv) return buf.isClean(); } + void showPrintError(string const & name) { - string str = bformat(_("Could not print the document %1$s.\n" - "Check that your printer is set up correctly."), - MakeDisplayPath(name, 50)); - Alert::error(_("Print document failed"), str); + string str = bformat(_("Could not print the document %1$s.\n" + "Check that your printer is set up correctly."), + MakeDisplayPath(name, 50)); + Alert::error(_("Print document failed"), str); } + +void loadTextclass(string const & name) +{ + std::pair const tc_pair = + textclasslist.NumberOfClass(name); + + if (!tc_pair.first) { + lyxerr << "Document class \"" << name + << "\" does not exist." + << std::endl; + return; + } + + lyx::textclass_type const tc = tc_pair.second; + + if (!textclasslist[tc].load()) { + string s = bformat(_("The document could not be converted\n" + "into the document class %1$s."), + textclasslist[tc].name()); + Alert::error(_("Could not change class"), s); + } +} + } //namespace anon @@ -1313,7 +1337,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose) lyx::textclass_type const old_class = buffer->params().textclass; - dispatch(FuncRequest(LFUN_TEXTCLASS_LOAD, argument)); + loadTextclass(argument); std::pair const tc_pair = textclasslist.NumberOfClass(argument); @@ -1339,30 +1363,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose) break; } - case LFUN_TEXTCLASS_LOAD: { - std::pair const tc_pair = - textclasslist.NumberOfClass(argument); - - if (!tc_pair.first) { - lyxerr << "Document class \"" << argument - << "\" does not exist." - << std::endl; - break; - } - - lyx::textclass_type const tc = tc_pair.second; - - bool const success = textclasslist[tc].load(); - if (success) - break; - - string s = bformat(_("The document could not be converted\n" - "into the document class %1$s."), - textclasslist[tc].name()); - Alert::error(_("Could not change class"), s); - + case LFUN_TEXTCLASS_LOAD: + loadTextclass(argument); break; - } default: { DispatchResult res = view()->cursor().dispatch(cmd); diff --git a/src/lyxtextclass.C b/src/lyxtextclass.C index d4f943dc3b..168520301d 100644 --- a/src/lyxtextclass.C +++ b/src/lyxtextclass.C @@ -845,16 +845,16 @@ bool LyXTextClass::load() const // Read style-file string const real_file = LibFileSearch("layouts", name_, "layout"); + loaded_ = const_cast(this)->Read(real_file) == 0; - if (const_cast(this)->Read(real_file)) { + if (!loaded_) { lyxerr << "Error reading `" << MakeDisplayPath(real_file) << "'\n(Check `" << name_ << "')\nCheck your installation and " "try Options/Reconfigure..." << endl; - loaded_ = false; } - loaded_ = true; + return loaded_; } -- 2.39.5