]> 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 feb5a15cfcb43a6159257a984ec93c88c1475aed..1d13cf3d6063c05ebe6fb160fc51c012ae5f475c 100644 (file)
@@ -1,11 +1,11 @@
 /**
- * \file ControlBibtex.C
+ * \file ControlBibtex.cpp
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
  * \author John Levon
  * \author Angus Leeming
- * \author Herbert Voss
+ * \author Herbert Voß
  *
  * Full author contact details are available in file CREDITS.
  */
 #include <config.h>
 
 #include "ControlBibtex.h"
-#include "Kernel.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"
-
-using namespace lyx::support;
+#include "support/lstrings.h"
 
 using std::pair;
+using std::string;
 using std::vector;
 
 
+namespace lyx {
+
+using support::contains;
+using support::FileFilterList;
+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::Browse(string const & in_name,
-                                  string const & title,
-                                  string const & pattern)
+docstring const ControlBibtex::browseBib(docstring const & in_name) const
+{
+       // 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, lyx::from_utf8(kernel().bufferFilepath()),
+                            _("Select a BibTeX database to add"),
+                            filter, false, dir1);
+}
+
+
+docstring const ControlBibtex::browseBst(docstring const & in_name) const
 {
-       pair<string, string> dir1(_("Documents|#o#O"),
-                                 string(lyxrc.document_path));
-       return browseRelFile(in_name, kernel().bufferFilepath(),
-                            title, pattern, false, dir1);
+       // 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, lyx::from_utf8(kernel().bufferFilepath()),
+                            _("Select a BibTeX style"), filter, false, dir1);
 }
 
 
@@ -57,8 +82,10 @@ 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());
 }
 
 
@@ -75,8 +102,10 @@ 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());
 }
 
 
@@ -84,3 +113,61 @@ void ControlBibtex::rescanBibStyles() const
 {
        rescanTexStyles();
 }
+
+
+bool ControlBibtex::usingBibtopic() const
+{
+       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
+} // namespace lyx