]> git.lyx.org Git - features.git/blobdiff - src/Buffer.cpp
* docstream: factorize out some code and introduce odocfstream::reset()
[features.git] / src / Buffer.cpp
index 71b58902ee672598a11eb63afb18aa71cb24487b..7ab95e8f0ea53360609a82439d2add74e86ac26e 100644 (file)
@@ -79,6 +79,7 @@
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/FileFilterList.h"
+#include "support/FileNameList.h"
 #include "support/filetools.h"
 #include "support/ForkedCalls.h"
 #include "support/gettext.h"
@@ -129,6 +130,7 @@ using support::changeExtension;
 using support::cmd_ret;
 using support::createBufferTmpDir;
 using support::FileName;
+using support::FileNameList;
 using support::libFileSearch;
 using support::latex_path;
 using support::ltrim;
@@ -229,6 +231,10 @@ public:
 
        ///
        Undo undo_;
+
+       /// A cache for the bibfiles (including bibfiles of loaded child
+       /// documents), needed for appropriate update of natbib labels.
+       mutable FileNameList bibfilesCache_;
 };
 
 
@@ -1003,7 +1009,15 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
        string const encoding = runparams.encoding->iconvName();
        LYXERR(Debug::LATEX, "makeLaTeXFile encoding: " << encoding << "...");
 
-       odocfstream ofs(encoding);
+       odocfstream ofs;
+       try { ofs.reset(encoding); }
+       catch (iconv_codecvt_facet_exception & e) {
+               lyxerr << "Caught iconv exception: " << e.what() << endl;
+               Alert::error(_("Iconv software exception Detected"), bformat(_("Please "
+                       "verify that the support software for your encoding (%1$s) is "
+                       "properly installed"), from_ascii(encoding)));
+               return false;
+       }
        if (!openFileWrite(ofs, fname))
                return false;
 
@@ -1450,22 +1464,22 @@ void Buffer::updateBibfilesCache() const
                return;
        }
 
-       bibfilesCache_.clear();
+       d->bibfilesCache_.clear();
        for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
                if (it->lyxCode() == BIBTEX_CODE) {
                        InsetBibtex const & inset =
                                static_cast<InsetBibtex const &>(*it);
-                       vector<FileName> const bibfiles = inset.getFiles(*this);
-                       bibfilesCache_.insert(bibfilesCache_.end(),
+                       FileNameList const bibfiles = inset.getFiles(*this);
+                       d->bibfilesCache_.insert(d->bibfilesCache_.end(),
                                bibfiles.begin(),
                                bibfiles.end());
                } else if (it->lyxCode() == INCLUDE_CODE) {
                        InsetInclude & inset =
                                static_cast<InsetInclude &>(*it);
                        inset.updateBibfilesCache(*this);
-                       vector<FileName> const & bibfiles =
+                       FileNameList const & bibfiles =
                                        inset.getBibfilesCache(*this);
-                       bibfilesCache_.insert(bibfilesCache_.end(),
+                       d->bibfilesCache_.insert(d->bibfilesCache_.end(),
                                bibfiles.begin(),
                                bibfiles.end());
                }
@@ -1473,7 +1487,7 @@ void Buffer::updateBibfilesCache() const
 }
 
 
-vector<FileName> const & Buffer::getBibfilesCache() const
+FileNameList const & Buffer::getBibfilesCache() const
 {
        // if this is a child document and the parent is already loaded
        // use the parent's cache instead
@@ -1483,10 +1497,10 @@ vector<FileName> const & Buffer::getBibfilesCache() const
                return tmp->getBibfilesCache();
 
        // We update the cache when first used instead of at loading time.
-       if (bibfilesCache_.empty())
+       if (d->bibfilesCache_.empty())
                const_cast<Buffer *>(this)->updateBibfilesCache();
 
-       return bibfilesCache_;
+       return d->bibfilesCache_;
 }