#include <config.h>
#include "ControlBibtex.h"
+#include "biblio.h"
#include "buffer.h"
#include "bufferparams.h"
#include "support/filefilterlist.h"
#include "support/filetools.h"
+#include "support/lstrings.h"
using std::pair;
using std::string;
namespace lyx {
+using support::contains;
using support::FileFilterList;
using support::OnlyFilename;
+using support::prefixIs;
+using support::split;
namespace frontend {
bool ControlBibtex::usingBibtopic() const
{
- return kernel().buffer().params().use_bibtopic;
+ return kernel().buffer().params().use_bibtopic;
+}
+
+
+bool ControlBibtex::bibtotoc() const
+{
+ return prefixIs(params().getOptions(), "bibtotoc");
+}
+
+
+string const ControlBibtex::getStylefile() const
+{
+ // the different bibtex packages have (and need) their
+ // own "plain" stylefiles
+ biblio::CiteEngine_enum const & engine =
+ biblio::getEngine(kernel().buffer());
+ string defaultstyle;
+ switch (engine) {
+ case biblio::ENGINE_BASIC:
+ defaultstyle = "plain";
+ break;
+ case biblio::ENGINE_NATBIB_AUTHORYEAR:
+ defaultstyle = "plainnat";
+ break;
+ case biblio::ENGINE_NATBIB_NUMERICAL:
+ defaultstyle = "plainnat";
+ break;
+ case biblio::ENGINE_JURABIB:
+ defaultstyle = "jurabib";
+ break;
+ }
+
+ string bst = params().getOptions();
+ if (bibtotoc()){
+ // bibstyle exists?
+ if (contains(bst,',')) {
+ string bibtotoc = "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().getContents().empty())
+ bst = defaultstyle;
+
+ return bst;
}
} // namespace frontend
void rescanBibStyles() const;
/// do we use bibtopic (for sectioned bibliography)?
bool usingBibtopic() const;
+ /// should we put the bibliography to the TOC?
+ bool bibtotoc() const;
+ /// which stylefile do we use?
+ std::string const getStylefile() const;
};
} // namespace frontend
#include <libglademm.h>
using lyx::support::ChangeExtension;
-using lyx::support::contains;
-using lyx::support::prefixIs;
using lyx::support::split;
using lyx::support::trim;
}
}
- string bibtotoc = "bibtotoc";
- string bibstyle(controller().params().getOptions());
-
- // bibtotoc exists?
- if (prefixIs(bibstyle, bibtotoc)){
- // bibstyle exists?
- if (contains(bibstyle,','))
- bibstyle = split(bibstyle, bibtotoc, ',');
- else
- bibstyle.erase();
- }
+ string bibstyle(controller().getStylefile());
bool const bibtopic = controller().usingBibtopic();
- if (prefixIs(bibstyle, bibtotoc) && !bibtopic)
+ if (controller().bibtotoc() && !bibtopic)
toccheck_->set_active(true);
else
toccheck_->set_active(false);
using lyx::support::ChangeExtension;
-using lyx::support::contains;
-using lyx::support::prefixIs;
using lyx::support::split;
using lyx::support::trim;
dialog_->add_->bibLB->insertItem(toqstr(bibItem));
}
- string bibtotoc = "bibtotoc";
- string bibstyle(controller().params().getOptions());
-
- // bibtotoc exists?
- if (prefixIs(bibstyle, bibtotoc)){
- // bibstyle exists?
- if (contains(bibstyle,','))
- bibstyle = split(bibstyle, bibtotoc, ',');
- else
- bibstyle.erase();
- }
-
- if (prefixIs(bibstyle, bibtotoc) && !bibtopic)
- dialog_->bibtocCB->setChecked(true);
- else
- dialog_->bibtocCB->setChecked(false);
-
+ dialog_->bibtocCB->setChecked(controller().bibtotoc() && !bibtopic);
dialog_->bibtocCB->setEnabled(!bibtopic);
string btprint(controller().params().getSecOptions());
dialog_->styleCB->clear();
int item_nr(-1);
+ string bibstyle(controller().getStylefile());
vector<string> str;
controller().getBibStyles(str);
using lyx::support::ChangeExtension;
-using lyx::support::contains;
-using lyx::support::prefixIs;
using lyx::support::split;
using lyx::support::trim;
dialog_->add_->bibLB->insertItem(toqstr(bibItem));
}
- string bibtotoc = "bibtotoc";
- string bibstyle(controller().params().getOptions());
-
- // bibtotoc exists?
- if (prefixIs(bibstyle, bibtotoc)){
- // bibstyle exists?
- if (contains(bibstyle,','))
- bibstyle = split(bibstyle, bibtotoc, ',');
- else
- bibstyle.erase();
- }
-
- if (prefixIs(bibstyle, bibtotoc) && !bibtopic)
- dialog_->bibtocCB->setChecked(true);
- else
- dialog_->bibtocCB->setChecked(false);
+ string bibstyle(controller().getStylefile());
+ dialog_->bibtocCB->setChecked(controller().bibtotoc() && !bibtopic);
dialog_->bibtocCB->setEnabled(!bibtopic);
string btprint(controller().params().getSecOptions());
using support::ChangeExtension;
using support::compare;
-using support::contains;
using support::FileFilterList;
using support::getStringFromVector;
using support::getVectorFromString;
using support::OnlyFilename;
-using support::prefixIs;
using support::split;
namespace frontend {
fl_set_input(dialog_->input_database,
controller().params().getContents().c_str());
- string bibtotoc = "bibtotoc";
- string bibstyle = controller().params().getOptions();
+ string bibstyle = controller().getStylefile();
bool const bibtopic = controller().usingBibtopic();
- bool const bibtotoc_exists = prefixIs(bibstyle, bibtotoc);
- fl_set_button(dialog_->check_bibtotoc, bibtotoc_exists && !bibtopic);
+ fl_set_button(dialog_->check_bibtotoc,
+ controller().bibtotoc() && !bibtopic);
setEnabled(dialog_->check_bibtotoc, !bibtopic);
- if (bibtotoc_exists) {
- if (contains(bibstyle, ',')) { // bibstyle exists?
- bibstyle = split(bibstyle, bibtotoc, ',');
- } else {
- bibstyle.erase();
- }
- }
+
fl_set_input(dialog_->input_style, bibstyle.c_str());
string btprint = controller().params().getSecOptions();