X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Ffrontends%2Fcontrollers%2FControlBibtex.C;h=1d13cf3d6063c05ebe6fb160fc51c012ae5f475c;hb=98ebb778411f39db1d144234b5b8bb944c3c05b2;hp=feb5a15cfcb43a6159257a984ec93c88c1475aed;hpb=a52418b360ee26b57dee1969e03e13ef23519037;p=lyx.git diff --git a/src/frontends/controllers/ControlBibtex.C b/src/frontends/controllers/ControlBibtex.C index feb5a15cfc..1d13cf3d60 100644 --- a/src/frontends/controllers/ControlBibtex.C +++ b/src/frontends/controllers/ControlBibtex.C @@ -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. */ @@ -13,34 +13,59 @@ #include #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 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 dir1(_("Documents|#o#O"), - string(lyxrc.document_path)); - return browseRelFile(in_name, kernel().bufferFilepath(), - title, pattern, false, dir1); + // FIXME UNICODE + pair 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 & data) const vector::iterator it = data.begin(); vector::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 & data) const vector::iterator it = data.begin(); vector::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