]> git.lyx.org Git - features.git/commitdiff
Fix crash when changing text class.
authorAngus Leeming <leeming@lyx.org>
Wed, 31 Mar 2004 09:44:40 +0000 (09:44 +0000)
committerAngus Leeming <leeming@lyx.org>
Wed, 31 Mar 2004 09:44:40 +0000 (09:44 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8569 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/lyxfunc.C
src/lyxtextclass.C

index e9ffc0df95371594fb8775c5ff41385e48d9d394..44b40bfc1b19458f44150939aa86a9be50d9a5b7 100644 (file)
@@ -1,3 +1,11 @@
+2004-03-31  Angus Leeming  <leeming@lyx.org>
+
+       * 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  <leeming@lyx.org>
 
        * lyxfunc.C (dispatch): remove the cursor-manipulation code from
index 0693b1e0513c6bbfa2ac43eb52ce655cfeea83be..a2d72087c60adf945d64c2476edf4a1bf878ba22 100644 (file)
@@ -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<bool, lyx::textclass_type> 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<bool, lyx::textclass_type> 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<bool, lyx::textclass_type> 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);
index d4f943dc3bfc3abe4337f050b8d5fb47c33a5a58..168520301dfa345535120f4a6dec85d789450db4 100644 (file)
@@ -845,16 +845,16 @@ bool LyXTextClass::load() const
 
        // Read style-file
        string const real_file = LibFileSearch("layouts", name_, "layout");
+       loaded_ = const_cast<LyXTextClass*>(this)->Read(real_file) == 0;
 
-       if (const_cast<LyXTextClass*>(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_;
 }