]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetBibtex.cpp
de.po
[lyx.git] / src / insets / InsetBibtex.cpp
index edf50f8787d820fe9f63f62b0e26e6133ae6cd4e..ae76a7f26c0c2bd7e8270fc35e322f3ec501e63c 100644 (file)
 #include "PDFOptions.h"
 #include "texstream.h"
 #include "TextClass.h"
+#include "TocBackend.h"
 
 #include "frontends/alert.h"
 
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/docstream.h"
+#include "support/docstring_list.h"
 #include "support/ExceptionMessage.h"
 #include "support/FileNameList.h"
 #include "support/filetools.h"
@@ -103,6 +105,7 @@ void InsetBibtex::doDispatch(Cursor & cur, FuncRequest & cmd)
 
                cur.recordUndo();
                setParams(p);
+               cur.buffer()->clearBibFileCache();
                cur.forceBufferUpdate();
                break;
        }
@@ -151,7 +154,7 @@ void InsetBibtex::editDatabases() const
        vector<docstring>::const_iterator it = bibfilelist.begin();
        vector<docstring>::const_iterator en = bibfilelist.end();
        for (; it != en; ++it) {
-               FileName const bibfile = getBibTeXPath(*it, buffer());
+               FileName const bibfile = buffer().getBibfilePath(*it);
                theFormats().edit(buffer(), bibfile,
                     theFormats().getFormatFromFile(bibfile));
        }
@@ -382,29 +385,9 @@ void InsetBibtex::latex(otexstream & os, OutputParams const & runparams) const
 }
 
 
-FileNamePairList InsetBibtex::getBibFiles() const
+docstring_list InsetBibtex::getBibFiles() const
 {
-       FileName path(buffer().filePath());
-       PathChanger p(path);
-
-       // We need to store both the real FileName and the way it is entered
-       // (with full path, rel path or as a single file name).
-       // The latter is needed for biblatex's central bibfile macro.
-       FileNamePairList vec;
-
-       vector<docstring> bibfilelist = getVectorFromString(getParam("bibfiles"));
-       vector<docstring>::const_iterator it = bibfilelist.begin();
-       vector<docstring>::const_iterator en = bibfilelist.end();
-       for (; it != en; ++it) {
-               FileName const file = getBibTeXPath(*it, buffer());
-
-               if (!file.empty())
-                       vec.push_back(make_pair(*it, file));
-               else
-                       LYXERR0("Couldn't find " + to_utf8(*it) + " in InsetBibtex::getBibFiles()!");
-       }
-
-       return vec;
+       return getVectorFromString(getParam("bibfiles"));
 }
 
 namespace {
@@ -675,11 +658,13 @@ void InsetBibtex::parseBibTeXFiles(FileNameList & checkedFiles) const
 
        BiblioInfo keylist;
 
-       FileNamePairList const files = getBibFiles();
-       FileNamePairList::const_iterator it = files.begin();
-       FileNamePairList::const_iterator en = files.end();
-       for (; it != en; ++ it) {
-               FileName const bibfile = it->second;
+       docstring_list const files = getBibFiles();
+       for (auto const & bf : files) {
+               FileName const bibfile = buffer().getBibfilePath(bf);
+               if (bibfile.empty()) {
+                       LYXERR0("Unable to find path for " << bf << "!");
+                       continue;
+               }
                if (find(checkedFiles.begin(), checkedFiles.end(), bibfile) != checkedFiles.end())
                        // already checked this one. Skip.
                        continue;
@@ -697,7 +682,6 @@ void InsetBibtex::parseBibTeXFiles(FileNameList & checkedFiles) const
                VarMap strings;
 
                while (ifs) {
-
                        ifs.get(ch);
                        if (!ifs)
                                break;
@@ -856,18 +840,6 @@ void InsetBibtex::parseBibTeXFiles(FileNameList & checkedFiles) const
 }
 
 
-FileName InsetBibtex::getBibTeXPath(docstring const & filename, Buffer const & buf)
-{
-       string texfile = changeExtension(to_utf8(filename), "bib");
-       // note that, if the filename can be found directly from the path,
-       // findtexfile will just return a FileName object for that path.
-       FileName file(findtexfile(texfile, "bib"));
-       if (file.empty())
-               file = FileName(makeAbsPath(texfile, buf.filePath()));
-       return file;
-}
-
-
 bool InsetBibtex::addDatabase(docstring const & db)
 {
        docstring bibfiles = getParam("bibfiles");
@@ -925,15 +897,36 @@ void InsetBibtex::updateBuffer(ParIterator const &, UpdateType)
                                string() : to_ascii(params()["encoding"]);
        if (buffer().params().bibEncoding() != enc) {
                buffer().params().setBibEncoding(enc);
-               buffer().reloadBibInfoCache(true);
+               buffer().invalidateBibinfoCache();
        }
 }
 
 
+docstring InsetBibtex::getRefLabel() const
+{
+       if (buffer().masterParams().documentClass().hasLaTeXLayout("chapter"))
+               return buffer().B_("Bibliography");
+       return buffer().B_("References");
+}
+
+
+void InsetBibtex::addToToc(DocIterator const & cpit, bool output_active,
+                          UpdateType, TocBackend & backend) const
+{
+       if (!prefixIs(to_utf8(getParam("options")), "bibtotoc"))
+               return;
+
+       docstring const str = getRefLabel();
+       TocBuilder & b = backend.builder("tableofcontents");
+       b.pushItem(cpit, str, output_active);
+       b.pop();
+}
+
+
 int InsetBibtex::plaintext(odocstringstream & os,
        OutputParams const & op, size_t max_length) const
 {
-       docstring const reflabel = buffer().B_("References");
+       docstring const reflabel = getRefLabel();
 
        // We could output more information here, e.g., what databases are included
        // and information about options. But I don't necessarily see any reason to