Dear all, This patch solves two problems:
1. LFUN_TEXTCLASS_APPLY and LFUN_TEXTCLASS_LOAD try to load a textclass without passing document path. (see loadTextclass(class) in line 1765 and 1796 of LyXFunc.cpp). This leads to erraneous behaviors when the preamble of a buffer with local layout file is modified. 2. It takes lyx several attempts to load a local layout file because addTextClass(local_layout) does not load the layout, and getTextClass() and others will fail to load it without buffer path information. Because on-request (local) layout file will always be used, I load it in addTextClass(). This avoids several warnings when such a file is opened. This patch is safe, and has been tested for a few days. Jurgen? Bo
Index: src/TextClass.cpp =================================================================== --- src/TextClass.cpp (revision 23137) +++ src/TextClass.cpp (working copy) @@ -990,6 +990,8 @@ string const & TextClass::latexname() const { + // No buffer path information is needed here because on-demand layout files + // have already been loaded, and no path is needed for system layouts. const_cast<TextClass*>(this)->load(); return latexname_; } Index: src/TextClassList.cpp =================================================================== --- src/TextClassList.cpp (revision 23137) +++ src/TextClassList.cpp (working copy) @@ -155,6 +155,8 @@ // fname, clname, desc, and avail TextClass tmpl(fname, clname, desc, avail); if (lyxerr.debugging(Debug::TCLASS)) { + // only system layout files are loaded here so no + // buffer path is needed. tmpl.load(); } classlist_.push_back(tmpl); @@ -214,6 +216,10 @@ if (pp.first && classlist_[pp.second].description() == tmpl.description()) return pp; classlist_.push_back(tmpl); + // This textclass is added on request so it will definitely be + // used. Load it now because other load() calls may fail if they + // are called in a context without buffer path information. + classlist_.back().load(path); return make_pair(true, classlist_.size() - 1); } } Index: src/LyXFunc.cpp =================================================================== --- src/LyXFunc.cpp (revision 23137) +++ src/LyXFunc.cpp (working copy) @@ -787,7 +787,7 @@ } -void loadTextclass(string const & name) +void loadTextclass(string const & name, string const & buf_path) { std::pair<bool, textclass_type> const tc_pair = textclasslist.numberOfClass(name); @@ -801,7 +801,7 @@ textclass_type const tc = tc_pair.second; - if (!textclasslist[tc].load()) { + if (!textclasslist[tc].load(buf_path)) { docstring s = bformat(_("The document could not be converted\n" "into the document class %1$s."), from_utf8(textclasslist[tc].name())); @@ -1762,7 +1762,7 @@ textclass_type const old_class = buffer->params().textclass; - loadTextclass(argument); + loadTextclass(argument, buffer->filePath()); std::pair<bool, textclass_type> const tc_pair = textclasslist.numberOfClass(argument); @@ -1793,7 +1793,7 @@ } case LFUN_TEXTCLASS_LOAD: - loadTextclass(argument); + loadTextclass(argument, lyx_view_->buffer()->filePath()); break; case LFUN_LYXRC_APPLY: {