X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fcontrollers%2FControlBibtex.C;h=1d13cf3d6063c05ebe6fb160fc51c012ae5f475c;hb=98ebb778411f39db1d144234b5b8bb944c3c05b2;hp=03b6dba6beaac3ada8e895a91960e8af23be4cc9;hpb=00d24ec87650e4ac7db77ad54cb4aa2f688100f3;p=lyx.git diff --git a/src/frontends/controllers/ControlBibtex.C b/src/frontends/controllers/ControlBibtex.C index 03b6dba6be..1d13cf3d60 100644 --- a/src/frontends/controllers/ControlBibtex.C +++ b/src/frontends/controllers/ControlBibtex.C @@ -1,71 +1,173 @@ -/* 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 - * \author Herbert Voss + * Full author contact details are available in file CREDITS. */ -#include - -#ifdef __GNUG__ -#pragma implementation -#endif - #include -#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 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 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 & 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::iterator it = data.begin(); + vector::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 & 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::iterator it = data.begin(); + vector::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 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