Requires natbib
CiteEngineType authoryear|numerical
-DefaultBiblio plainnat
+DefaultBiblio authoryear:plainnat|numerical:plainnat
CiteEngine authoryear
Citet*[][]
## It has been automatically generated by configure
## Use "Options/Reconfigure" if you need to update it after a
## configuration change.
-## "CiteEngineName" "filename" "CiteEngineType" "Description" "Packages" "Requires" "Excludes"
+## "CiteEngineName" "filename" "CiteEngineType" "DefaultBiblio" "Description" "Packages" "Requires" "Excludes"
''')
# build the list of available modules
#Excludes: [list of excluded engines]
The last two lines are optional.
We expect output:
- "CiteEngineName" "filename" "CiteEngineType" "Description" "Packages" "Requires" "Excludes"
+ "CiteEngineName" "filename" "CiteEngineType" "DefaultBiblio" "Description" "Packages" "Requires" "Excludes"
'''
remods = re.compile(r'\DeclareLyXCiteEngine\s*(?:\[([^]]*?)\])?{(.*)}')
- rereqs = re.compile(r'#+\s*Requires: (.*)')
- reexcs = re.compile(r'#+\s*Excludes: (.*)')
+ rereqs = re.compile(r'#+\s*Requires:\s*(.*)')
+ reexcs = re.compile(r'#+\s*Excludes:\s*(.*)')
redbeg = re.compile(r'#+\s*DescriptionBegin\s*$')
redend = re.compile(r'#+\s*DescriptionEnd\s*$')
- recet = re.compile(r'\s*CiteEngineType (.*)')
+ recet = re.compile(r'\s*CiteEngineType\s*(.*)')
+ redb = re.compile(r'\s*DefaultBiblio\s*(.*)')
- modname = desc = pkgs = req = excl = cet = ""
+ modname = desc = pkgs = req = excl = cet = db = ""
readingDescription = False
descLines = []
if res != None:
cet = res.group(1)
continue
+ res = redb.search(line)
+ if res != None:
+ db = res.group(1)
+ continue
if modname == "":
logger.warning("Cite Engine File file without \DeclareLyXCiteEngine line. ")
cm.write(line + '\n')
cm.close()
- return '"%s" "%s" "%s" "%s" "%s" "%s" "%s"\n' % (modname, filename, cet, desc, pkgs, req, excl)
+ return '"%s" "%s" "%s" "%s" "%s" "%s" "%s" "%s"\n' % (modname, filename, cet, db, desc, pkgs, req, excl)
def checkTeXAllowSpaces():
string const & BufferParams::defaultBiblioStyle() const
{
- return documentClass().defaultBiblioStyle();
+ map<string, string> bs = documentClass().defaultBiblioStyle();
+ return bs[documentClass().opt_enginetype()];
}
LyXCiteEngine::LyXCiteEngine(string const & n, string const & i,
- vector<string> const & cet, string const & d,
- vector<string> const & p,
+ vector<string> const & cet, vector<string> const & dbs,
+ string const & d, vector<string> const & p,
vector<string> const & r, vector<string> const & e):
- name_(n), id_(i), engine_types_(cet), description_(d), package_list_(p),
- required_engines_(r), excluded_engines_(e),
+ name_(n), id_(i), engine_types_(cet), default_biblios_(dbs), description_(d),
+ package_list_(p), required_engines_(r), excluded_engines_(e),
checked_(false), available_(false)
{
filename_ = id_ + ".citeengine";
}
+string LyXCiteEngine::getDefaultBiblio(CiteEngineType const & cet) const
+{
+ string res;
+ string const etp = theCiteEnginesList.getTypeAsString(cet) + ":";
+ //check whether all of the required packages are available
+ vector<string>::const_iterator it = default_biblios_.begin();
+ vector<string>::const_iterator end = default_biblios_.end();
+ for (; it != end; ++it) {
+ string const s = *it;
+ if (prefixIs(s, etp))
+ res = split(s, ':');
+ else if (!contains(s, ':') && res.empty())
+ res = s;
+ }
+ return res;
+}
+
+
+bool LyXCiteEngine::isDefaultBiblio(string const & bf) const
+{
+ if (find(default_biblios_.begin(), default_biblios_.end(), bf) != default_biblios_.end())
+ return true;
+ string const bfp = ":" + bf;
+ return find(default_biblios_.begin(), default_biblios_.end(), bfp) != default_biblios_.end();
+}
+
+
// used when sorting the cite engine list.
class EngineSorter {
public:
cet = split(cet, p, '|');
cets.push_back(p);
}
+ if (!lex.next(true))
+ break;
+ string db = lex.getString();
+ LYXERR(Debug::TCLASS, "Default Biblio: " << db);
+ vector<string> dbs;
+ while (!db.empty()) {
+ string p;
+ db = split(db, p, '|');
+ dbs.push_back(p);
+ }
if (!lex.next(true))
break;
string const desc = lex.getString();
}
// This code is run when we have
// cename, fname, desc, pkgs, req and exc
- addCiteEngine(cename, fname, cets, desc, pkgs, req, exc);
+ addCiteEngine(cename, fname, cets, dbs, desc, pkgs, req, exc);
} // end switch
} //end while
void CiteEnginesList::addCiteEngine(string const & cename,
- string const & filename, vector<string> const & cets, string const & description,
+ string const & filename, vector<string> const & cets,
+ vector<string> const & dbs, string const & description,
vector<string> const & pkgs, vector<string> const & req,
vector<string> const & exc)
{
- LyXCiteEngine ce(cename, filename, cets, description, pkgs, req, exc);
+ LyXCiteEngine ce(cename, filename, cets, dbs, description, pkgs, req, exc);
englist_.push_back(ce);
}
///
LyXCiteEngine(std::string const & name, std::string const & id,
std::vector<std::string> const & enginetypes,
+ std::vector<std::string> const & defaultbiblios,
std::string const & description,
std::vector<std::string> const & packagelist,
std::vector<std::string> const & requires,
///
bool hasEngineType(CiteEngineType const &) const;
///
+ std::string getDefaultBiblio(CiteEngineType const &) const;
+ ///
+ bool isDefaultBiblio(std::string const &) const;
+ ///
std::string const & getDescription() const { return description_; }
///
std::vector<std::string> const & getPackageList() const
std::string filename_;
/// the engine type(s)
std::vector<std::string> engine_types_;
+ /// default bibliography styles
+ std::vector<std::string> default_biblios_;
/// a short description for use in the ui
std::string description_;
/// the LaTeX packages on which this depends, if any
void operator=(CiteEnginesList const &);
/// add an engine to the list
void addCiteEngine(std::string const &, std::string const &,
- std::vector<std::string> const &, std::string const &, std::vector<std::string> const &,
+ std::vector<std::string> const &, std::vector<std::string> const &,
+ std::string const &, std::vector<std::string> const &,
std::vector<std::string> const &, std::vector<std::string> const &);
///
std::vector<LyXCiteEngine> englist_;
break;
case TC_DEFAULTBIBLIO:
- if (lexrc.next())
- cite_default_biblio_style_ = rtrim(lexrc.getString());
+ if (lexrc.next()) {
+ vector<string> const dbs =
+ getVectorFromString(rtrim(lexrc.getString()), "|");
+ vector<string>::const_iterator it = dbs.begin();
+ vector<string>::const_iterator end = dbs.end();
+ for (; it != end; ++it) {
+ if (!contains(*it, ':'))
+ cite_default_biblio_style_[opt_enginetype_] = *it;
+ else {
+ string eng;
+ string const db = split(*it, eng, ':');
+ cite_default_biblio_style_[eng] = db;
+ }
+ }
+ }
break;
case TC_FULLAUTHORLIST:
/// Citation macros
std::map<CiteEngineType, std::map<std::string, std::string> > cite_macros_;
/// The default BibTeX bibliography style file
- std::string cite_default_biblio_style_;
+ std::map<std::string, std::string> cite_default_biblio_style_;
/// Whether full author lists are supported
bool cite_full_author_list_;
/// The possible citation styles
///
std::vector<CitationStyle> const & citeStyles(CiteEngineType const &) const;
///
- std::string const & defaultBiblioStyle() const { return cite_default_biblio_style_; }
+ std::map<std::string, std::string> const & defaultBiblioStyle() const
+ { return cite_default_biblio_style_; }
///
bool const & fullAuthorList() const { return cite_full_author_list_; }
protected:
connect(biblioModule->citeEngineCO, SIGNAL(activated(int)),
this, SLOT(citeEngineChanged(int)));
connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
- this, SLOT(biblioChanged()));
+ this, SLOT(citeStyleChanged()));
connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
this, SLOT(biblioChanged()));
connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
this, SLOT(bibtexChanged(int)));
connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
this, SLOT(biblioChanged()));
- connect(biblioModule->bibtexStyleLE, SIGNAL(textChanged(QString)),
+ connect(biblioModule->defaultBiblioCO, SIGNAL(activated(int)),
+ this, SLOT(biblioChanged()));
+ connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
this, SLOT(biblioChanged()));
+ connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
+ this, SLOT(updateResetDefaultBiblio()));
+ connect(biblioModule->rescanBibliosPB, SIGNAL(clicked()),
+ this, SLOT(rescanBibFiles()));
+ connect(biblioModule->resetDefaultBiblioPB, SIGNAL(clicked()),
+ this, SLOT(resetDefaultBibfile()));
biblioModule->citeEngineCO->clear();
for (LyXCiteEngine const & cet : theCiteEnginesList) {
biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
biblioModule->bibtexOptionsLE));
- biblioModule->bibtexStyleLE->setValidator(new NoNewLineValidator(
- biblioModule->bibtexStyleLE));
+ biblioModule->defaultBiblioCO->lineEdit()->setValidator(new NoNewLineValidator(
+ biblioModule->defaultBiblioCO->lineEdit()));
// NOTE: we do not provide "custom" here for security reasons!
biblioModule->bibtexCO->clear();
}
+void GuiDocument::rescanBibFiles()
+{
+ rescanTexStyles("bst");
+}
+
+
+void GuiDocument::resetDefaultBibfile()
+{
+ QString const engine =
+ biblioModule->citeEngineCO->itemData(
+ biblioModule->citeEngineCO->currentIndex()).toString();
+
+ CiteEngineType const cet =
+ CiteEngineType(biblioModule->citeStyleCO->itemData(
+ biblioModule->citeStyleCO->currentIndex()).toInt());
+
+ updateDefaultBiblio(theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet));
+}
+
+
void GuiDocument::citeEngineChanged(int n)
{
- QString const engine = biblioModule->citeEngineCO->itemData(n).toString();
+ QString const engine =
+ biblioModule->citeEngineCO->itemData(n).toString();
vector<string> const engs =
theCiteEnginesList[fromqstr(engine)]->getEngineType();
updateCiteStyles(engs);
+ resetDefaultBibfile();
biblioChanged();
}
-void GuiDocument::bibtexChanged(int n)
+void GuiDocument::citeStyleChanged()
{
- biblioModule->bibtexOptionsLE->setEnabled(
- biblioModule->bibtexCO->itemData(n).toString() != "default");
- biblioChanged();
-}
-
+ QString const engine =
+ biblioModule->citeEngineCO->itemData(
+ biblioModule->citeEngineCO->currentIndex()).toString();
+ if (theCiteEnginesList[fromqstr(engine)]->isDefaultBiblio(
+ fromqstr(biblioModule->defaultBiblioCO->currentText())))
+ resetDefaultBibfile();
-void GuiDocument::setAuthorYear(bool authoryear)
-{
- if (authoryear)
- biblioModule->citeStyleCO->setCurrentIndex(
- biblioModule->citeStyleCO->findData(ENGINE_TYPE_AUTHORYEAR));
biblioChanged();
}
-void GuiDocument::setNumerical(bool numerical)
+void GuiDocument::bibtexChanged(int n)
{
- if (numerical)
- biblioModule->citeStyleCO->setCurrentIndex(
- biblioModule->citeStyleCO->findData(ENGINE_TYPE_NUMERICAL));
+ biblioModule->bibtexOptionsLE->setEnabled(
+ biblioModule->bibtexCO->itemData(n).toString() != "default");
biblioChanged();
}
bp_.use_bibtopic =
biblioModule->bibtopicCB->isChecked();
- bp_.biblio_style = fromqstr(biblioModule->bibtexStyleLE->text());
+ bp_.biblio_style = fromqstr(biblioModule->defaultBiblioCO->currentText());
string const bibtex_command =
fromqstr(biblioModule->bibtexCO->itemData(
biblioModule->bibtopicCB->setChecked(
bp_.use_bibtopic);
- biblioModule->bibtexStyleLE->setText(toqstr(bp_.biblio_style));
+ updateDefaultBiblio(bp_.defaultBiblioStyle());
string command;
string options =
}
+void GuiDocument::updateDefaultBiblio(string const & style)
+{
+ QString const bibstyle = toqstr(style);
+ biblioModule->defaultBiblioCO->clear();
+
+ int item_nr = -1;
+
+ QStringList str = texFileList("bstFiles.lst");
+ // test whether we have a valid list, otherwise run rescan
+ if (str.isEmpty()) {
+ rescanTexStyles("bst");
+ str = texFileList("bstFiles.lst");
+ }
+ for (int i = 0; i != str.size(); ++i)
+ str[i] = onlyFileName(str[i]);
+ // sort on filename only (no path)
+ str.sort();
+
+ for (int i = 0; i != str.count(); ++i) {
+ QString item = changeExtension(str[i], "");
+ if (item == bibstyle)
+ item_nr = i;
+ biblioModule->defaultBiblioCO->addItem(item);
+ }
+
+ if (item_nr == -1 && !bibstyle.isEmpty()) {
+ biblioModule->defaultBiblioCO->addItem(bibstyle);
+ item_nr = biblioModule->defaultBiblioCO->count() - 1;
+ }
+
+ if (item_nr != -1)
+ biblioModule->defaultBiblioCO->setCurrentIndex(item_nr);
+ else
+ biblioModule->defaultBiblioCO->clearEditText();
+
+ updateResetDefaultBiblio();
+}
+
+
+void GuiDocument::updateResetDefaultBiblio()
+{
+ QString const engine =
+ biblioModule->citeEngineCO->itemData(
+ biblioModule->citeEngineCO->currentIndex()).toString();
+ CiteEngineType const cet =
+ CiteEngineType(biblioModule->citeStyleCO->itemData(
+ biblioModule->citeStyleCO->currentIndex()).toInt());
+ biblioModule->resetDefaultBiblioPB->setEnabled(
+ theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet)
+ != fromqstr(biblioModule->defaultBiblioCO->currentText()));
+}
+
+
void GuiDocument::updateContents()
{
// Nothing to do here as the document settings is not cursor dependant.
void classChanged_adaptor();
void languagePackageChanged(int);
void biblioChanged();
+ void rescanBibFiles();
+ void resetDefaultBibfile();
void citeEngineChanged(int);
+ void citeStyleChanged();
void bibtexChanged(int);
- void setAuthorYear(bool);
- void setNumerical(bool);
+ void updateResetDefaultBiblio();
void updateModuleInfo();
void modulesChanged();
void changeBackgroundColor();
void updateSelectedModules();
///
void updateIncludeonlys();
+ ///
+ void updateDefaultBiblio(std::string const & style);
/// save as default template
void saveDocDefault();
/// reset to default params
<rect>
<x>0</x>
<y>0</y>
- <width>418</width>
+ <width>475</width>
<height>394</height>
</rect>
</property>
<string/>
</property>
<property name="text">
- <string>Sty&le Engine:</string>
+ <string>Sty&le engine:</string>
</property>
<property name="buddy">
<cstring>citeEngineCO</cstring>
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_1">
+ <item row="1" column="0">
+ <widget class="QCheckBox" name="bibtopicCB">
+ <property name="toolTip">
+ <string>Select this if you want to split your bibliography into sections</string>
+ </property>
+ <property name="text">
+ <string>S&ectioned bibliography</string>
+ </property>
+ </widget>
+ </item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_1">
<item>
<widget class="QLabel" name="bibtexStyleLA">
<property name="text">
- <string>Default st&yle:</string>
+ <string>Default BibTeX st&yle:</string>
</property>
<property name="buddy">
- <cstring>bibtexStyleLE</cstring>
+ <cstring>defaultBiblioCO</cstring>
</property>
</widget>
</item>
<item>
- <widget class="QLineEdit" name="bibtexStyleLE">
+ <widget class="QComboBox" name="defaultBiblioCO">
<property name="toolTip">
- <string>Define the default BibTeX style</string>
+ <string>Here, you can define a BibTeX style that is suggested in the BibTeX dialog by default</string>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="rescanBibliosPB">
+ <property name="toolTip">
+ <string>Rescan style files</string>
+ </property>
+ <property name="text">
+ <string>Re&scan</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="resetDefaultBiblioPB">
+ <property name="toolTip">
+ <string>Reset to the preset default</string>
+ </property>
+ <property name="text">
+ <string>&Reset</string>
</property>
</widget>
</item>
</layout>
</item>
- <item row="1" column="0">
- <widget class="QCheckBox" name="bibtopicCB">
- <property name="toolTip">
- <string>Select this if you want to split your bibliography into sections</string>
+ <item row="0" column="1">
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
</property>
- <property name="text">
- <string>S&ectioned bibliography</string>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
</property>
- </widget>
+ </spacer>
</item>
</layout>
</widget>
}
if (style == "default")
- style = buffer().params().biblio_style;
+ style = buffer().params().defaultBiblioStyle();
if (!style.empty() && !buffer().params().use_bibtopic) {
string base = normalizeName(buffer(), runparams, style, ".bst");