]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlBibtex.C
Rename .C => .cpp for files in src/frontends/controllers, step 1
[lyx.git] / src / frontends / controllers / ControlBibtex.C
index 0573d240042379777aeb64ffba5574fa0dcd3f5f..1d13cf3d6063c05ebe6fb160fc51c012ae5f475c 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * \file ControlBibtex.C
+ * \file ControlBibtex.cpp
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
 #include <config.h>
 
 #include "ControlBibtex.h"
+#include "frontend_helpers.h"
 
 #include "buffer.h"
 #include "bufferparams.h"
 
 #include "lyxrc.h"
-#include "helper_funcs.h"
-#include "tex_helpers.h"
 #include "gettext.h"
 
 #include "support/filefilterlist.h"
 #include "support/filetools.h"
+#include "support/lstrings.h"
 
 using std::pair;
 using std::string;
@@ -32,34 +32,39 @@ using std::vector;
 
 namespace lyx {
 
+using support::contains;
 using support::FileFilterList;
-using support::OnlyFilename;
+using support::onlyFilename;
+using support::prefixIs;
+using support::split;
 
 namespace frontend {
 
 
 ControlBibtex::ControlBibtex(Dialog & d)
-       : ControlCommand(d, "bibtex")
+       : ControlCommand(d, "bibtex", "bibtex")
 {}
 
 
-string const ControlBibtex::browseBib(string const & in_name) const
+docstring const ControlBibtex::browseBib(docstring const & in_name) const
 {
-       pair<string, string> dir1(_("Documents|#o#O"),
-                                 string(lyxrc.document_path));
+       // FIXME UNICODE
+       pair<docstring, docstring> dir1(_("Documents|#o#O"),
+                                 lyx::from_utf8(lyxrc.document_path));
        FileFilterList const filter(_("BibTeX Databases (*.bib)"));
-       return browseRelFile(in_name, kernel().bufferFilepath(),
+       return browseRelFile(in_name, lyx::from_utf8(kernel().bufferFilepath()),
                             _("Select a BibTeX database to add"),
                             filter, false, dir1);
 }
 
 
-string const ControlBibtex::browseBst(string const & in_name) const
+docstring const ControlBibtex::browseBst(docstring const & in_name) const
 {
-       pair<string, string> dir1(_("Documents|#o#O"),
-                                 string(lyxrc.document_path));
+       // FIXME UNICODE
+       pair<docstring, docstring> dir1(_("Documents|#o#O"),
+                                 lyx::from_utf8(lyxrc.document_path));
        FileFilterList const filter(_("BibTeX Styles (*.bst)"));
-       return browseRelFile(in_name, kernel().bufferFilepath(),
+       return browseRelFile(in_name, lyx::from_utf8(kernel().bufferFilepath()),
                             _("Select a BibTeX style"), filter, false, dir1);
 }
 
@@ -77,7 +82,7 @@ void ControlBibtex::getBibStyles(vector<string> & data) const
        vector<string>::iterator it  = data.begin();
        vector<string>::iterator end = data.end();
        for (; it != end; ++it) {
-               *it = OnlyFilename(*it);
+               *it = onlyFilename(*it);
        }
        // sort on filename only (no path)
        std::sort(data.begin(), data.end());
@@ -97,7 +102,7 @@ void ControlBibtex::getBibFiles(vector<string> & data) const
        vector<string>::iterator it  = data.begin();
        vector<string>::iterator end = data.end();
        for (; it != end; ++it) {
-               *it = OnlyFilename(*it);
+               *it = onlyFilename(*it);
        }
        // sort on filename only (no path)
        std::sort(data.begin(), data.end());
@@ -112,7 +117,56 @@ void ControlBibtex::rescanBibStyles() const
 
 bool ControlBibtex::usingBibtopic() const
 {
-    return kernel().buffer().params().use_bibtopic;
+       return kernel().buffer().params().use_bibtopic;
+}
+
+
+bool ControlBibtex::bibtotoc() const
+{
+       return prefixIs(lyx::to_utf8(params()["options"]), "bibtotoc");
+}
+
+
+string const ControlBibtex::getStylefile() const
+{
+       // the different bibtex packages have (and need) their
+       // own "plain" stylefiles
+       biblio::CiteEngine const engine =
+               kernel().buffer().params().getEngine();
+       docstring defaultstyle;
+       switch (engine) {
+       case biblio::ENGINE_BASIC:
+               defaultstyle = lyx::from_ascii("plain");
+               break;
+       case biblio::ENGINE_NATBIB_AUTHORYEAR:
+               defaultstyle = lyx::from_ascii("plainnat");
+               break;
+       case biblio::ENGINE_NATBIB_NUMERICAL:
+               defaultstyle = lyx::from_ascii("plainnat");
+               break;
+       case biblio::ENGINE_JURABIB:
+               defaultstyle = lyx::from_ascii("jurabib");
+               break;
+       }
+
+       docstring bst = params()["options"];
+       if (bibtotoc()){
+               // bibstyle exists?
+               if (contains(bst, ',')) {
+                       docstring bibtotoc = lyx::from_ascii("bibtotoc");
+                       bst = split(bst, bibtotoc, ',');
+               } else
+                       bst.erase();
+       }
+
+       // propose default style file for new insets
+       // existing insets might have (legally) no bst files
+       // (if the class already provides a style)
+       if (bst.empty() && params()["bibfiles"].empty())
+               bst = defaultstyle;
+
+       // FIXME UNICODE
+       return lyx::to_utf8(bst);
 }
 
 } // namespace frontend