]> 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 03b6dba6beaac3ada8e895a91960e8af23be4cc9..1d13cf3d6063c05ebe6fb160fc51c012ae5f475c 100644 (file)
-/* This file is part of
- * ====================================================== 
+/**
+ * \file ControlBibtex.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author John Levon
+ * \author Angus Leeming
+ * \author Herbert Voß
  *
- *           Copyright 2001 The LyX Team.
- *
- * ======================================================
- *
- * \file ControlBibtex.C
- * \author John Levon, moz@compsoc.man.ac.uk
- * \author Angus Leeming <a.leeming@ic.ac.uk>
- * \author Herbert Voss <voss@lyx.org>
+ * Full author contact details are available in file CREDITS.
  */
 
-#include <algorithm>
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include <config.h>
-#include "ViewBase.h"
-#include "ButtonControllerBase.h"
+
 #include "ControlBibtex.h"
-#include "Dialogs.h"
-#include "LyXView.h"
+#include "frontend_helpers.h"
+
 #include "buffer.h"
-#include "BufferView.h"
+#include "bufferparams.h"
+
 #include "lyxrc.h"
-#include "helper_funcs.h"
 #include "gettext.h"
 
-using SigC::slot;
+#include "support/filefilterlist.h"
+#include "support/filetools.h"
+#include "support/lstrings.h"
+
 using std::pair;
-using std::make_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", "bibtex")
+{}
+
+
+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);
+}
+
 
-ControlBibtex::ControlBibtex(LyXView & lv, Dialogs & d)
-       : ControlCommand(lv, d)
+docstring const ControlBibtex::browseBst(docstring const & in_name) const
 {
-       d_.showBibtex.connect(slot(this, &ControlBibtex::showInset));
+       // 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);
 }
 
-void ControlBibtex::applyParamsToInset()
+
+void ControlBibtex::getBibStyles(vector<string> & data) const
+{
+       data.clear();
+
+       getTexFileList("bstFiles.lst", data);
+       // test, if we have a valid list, otherwise run rescan
+       if (data.empty()) {
+               rescanBibStyles();
+               getTexFileList("bstFiles.lst", data);
+       }
+       vector<string>::iterator it  = data.begin();
+       vector<string>::iterator end = data.end();
+       for (; it != end; ++it) {
+               *it = onlyFilename(*it);
+       }
+       // sort on filename only (no path)
+       std::sort(data.begin(), data.end());
+}
+
+
+void ControlBibtex::getBibFiles(vector<string> & data) const
 {
-       if (params().getContents() != inset()->params().getContents())
-               lv_.view()->ChangeCitationsIfUnique(inset()->params().getContents(),
-                                                   params().getContents());
+       data.clear();
+
+       getTexFileList("bibFiles.lst", data);
+       // test, if we have a valid list, otherwise run rescan
+       if (data.empty()) {
+               rescanBibStyles();
+               getTexFileList("bibFiles.lst", data);
+       }
+       vector<string>::iterator it  = data.begin();
+       vector<string>::iterator end = data.end();
+       for (; it != end; ++it) {
+               *it = onlyFilename(*it);
+       }
+       // sort on filename only (no path)
+       std::sort(data.begin(), data.end());
+}
 
-       inset()->setParams(params());
-       lv_.view()->updateInset(inset(), true);
 
-       // We need to do a redraw because the maximum
-       // InsetBibKey width could have changed
-       lv_.view()->redraw();
-       lv_.view()->fitCursor();
+void ControlBibtex::rescanBibStyles() const
+{
+       rescanTexStyles();
 }
 
 
-void ControlBibtex::applyParamsNoInset()
-{}
+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::Browse(string const & in_name, 
-                                   string const & title,
-                                  string const & pattern)
+string const ControlBibtex::getStylefile() const
 {
-       pair<string, string> dir1(N_("Documents"), string(lyxrc.document_path));
-       return browseFile(&lv_, in_name, title, pattern, 
-                         dir1,make_pair(string(), string()));
+       // 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