#include <vector>
using namespace std;
+using namespace lyx::support;
namespace lyx {
namespace frontend {
GuiCitation::GuiCitation(GuiView & lv)
- : GuiCommand(lv, "citation")
+ : GuiCommand(lv, "citation", qt_("Citation"))
{
setupUi(this);
- setViewTitle(_("Citation"));
connect(citationStyleCO, SIGNAL(activated(int)),
- this, SLOT(changed()));
+ this, SLOT(on_citationStyleCO_currentIndexChanged(int)));
connect(fulllistCB, SIGNAL(clicked()),
this, SLOT(changed()));
connect(forceuppercaseCB, SIGNAL(clicked()),
{
clearSelection();
clearParams();
- GuiDialog::closeEvent(e);
+ e->accept();
}
void GuiCitation::applyView()
{
- int const choice = std::max(0, citationStyleCO->currentIndex());
+ int const choice = max(0, citationStyleCO->currentIndex());
style_ = choice;
bool const full = fulllistCB->isChecked();
bool const force = forceuppercaseCB->isChecked();
// called in update() do not need to be called for INTERNAL updates,
// such as when addPB is pressed, as the list of fields, entries, etc,
// will not have changed. At the moment, however, the division between
-// fillStyles() and updateStyles() doesn't lend itself to dividing the
+// fillStyles() and updateStyle() doesn't lend itself to dividing the
// two methods, though they should be divisible.
void GuiCitation::updateDialog()
{
}
-void GuiCitation::updateStyle()
+void GuiCitation::updateFormatting(biblio::CiteStyle currentStyle)
{
biblio::CiteEngine const engine = getEngine();
bool const natbib_engine =
bool const haveSelection =
selectedLV->model()->rowCount() > 0;
- fulllistCB->setEnabled(natbib_engine && haveSelection);
- forceuppercaseCB->setEnabled(natbib_engine && haveSelection);
- textBeforeED->setEnabled(!basic_engine && haveSelection);
- textBeforeLA->setEnabled(!basic_engine && haveSelection);
- textAfterED->setEnabled(haveSelection);
- textAfterLA->setEnabled(haveSelection);
- citationStyleCO->setEnabled(!basic_engine && haveSelection);
- citationStyleLA->setEnabled(!basic_engine && haveSelection);
+ bool const isNocite = currentStyle == biblio::NOCITE;
+
+ fulllistCB->setEnabled(natbib_engine && haveSelection && !isNocite);
+ forceuppercaseCB->setEnabled(natbib_engine && haveSelection && !isNocite);
+ textBeforeED->setEnabled(!basic_engine && haveSelection && !isNocite);
+ textBeforeLA->setEnabled(!basic_engine && haveSelection && !isNocite);
+ textAfterED->setEnabled(haveSelection && !isNocite);
+ textAfterLA->setEnabled(haveSelection && !isNocite);
+ citationStyleCO->setEnabled(haveSelection);
+ citationStyleLA->setEnabled(haveSelection);
+}
+
+
+void GuiCitation::updateStyle()
+{
string const & command = params_.getCmdName();
// Find the style of the citekeys
fulllistCB->setChecked(false);
forceuppercaseCB->setChecked(false);
}
+ updateFormatting(cs.style);
}
-
//This one needs to be called whenever citationStyleCO needs
//to be updated---and this would be on anything that changes the
//selection in selectedLV, or on a general update.
QStringList sty = citationStyles(curr);
- bool const basic_engine = (getEngine() == biblio::ENGINE_BASIC);
+ citationStyleCO->setEnabled(!sty.isEmpty());
+ citationStyleLA->setEnabled(!sty.isEmpty());
- citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine);
- citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine);
-
- if (sty.isEmpty() || basic_engine)
+ if (sty.isEmpty())
return;
citationStyleCO->insertItems(0, sty);
//"All Entry Types" is first.
index = entriesCO->currentIndex() - 1;
vector<docstring> const & entries = availableEntries();
- docstring entryType;
+ docstring entry_type;
if (index < 0 || index >= int(entries.size()))
- entryType = from_ascii("");
+ entry_type = from_ascii("");
else
- entryType = entries[index];
+ entry_type = entries[index];
bool const case_sentitive = caseCB->checkState();
bool const reg_exp = regexCB->checkState();
- findKey(text, onlyKeys, field, entryType,
+ findKey(text, onlyKeys, field, entry_type,
case_sentitive, reg_exp, reset);
//FIXME
//It'd be nice to save and restore the current selection in
}
+void GuiCitation::on_citationStyleCO_currentIndexChanged(int index)
+{
+ if (index >= 0 && index < citationStyleCO->count()) {
+ vector<biblio::CiteStyle> const & styles = citeStyles_;
+ updateFormatting(styles[index]);
+ }
+}
+
+
void GuiCitation::on_findLE_textChanged(const QString & text)
{
clearPB->setDisabled(text.isEmpty());
void GuiCitation::changed()
{
- fillStyles();
setButtons();
}
-void GuiCitation::apply(int const choice, bool const full, bool const force,
+void GuiCitation::apply(int const choice, bool full, bool force,
QString before, QString after)
{
if (cited_keys_.isEmpty())
return;
vector<biblio::CiteStyle> const & styles = citeStyles_;
-
+ if (styles[choice] == biblio::NOCITE) {
+ full = false;
+ force = false;
+ before.clear();
+ after.clear();
+ }
+
string const command =
biblio::CitationStyle(styles[choice], full, force)
.asLatexStr();
void GuiCitation::findKey(QString const & str, bool only_keys,
- docstring field, docstring entryType,
+ docstring field, docstring entry_type,
bool case_sensitive, bool reg_exp, bool reset)
{
// Used for optimisation: store last searched string.
QStringList result;
- // First, filter by entryType, which will be faster than
+ // First, filter by entry_type, which will be faster than
// what follows, so we may get to do that on less.
vector<docstring> keyVector = to_docstring_vector(keys);
- filterByEntryType(keyVector, entryType);
+ filterByEntryType(keyVector, entry_type);
if (str.isEmpty())
result = to_qstring_list(keyVector);
biblio::CiteEngine const engine = buffer().params().getEngine();
- bool use_styles = engine != biblio::ENGINE_BASIC;
-
bibkeysInfo_.fillWithBibKeys(&buffer());
- if (citeStyles_.empty())
- citeStyles_ = biblio::getCiteStyles(engine);
- else {
- if ((use_styles && citeStyles_.size() == 1) ||
- (!use_styles && citeStyles_.size() != 1))
- citeStyles_ = biblio::getCiteStyles(engine);
- }
+ citeStyles_ = biblio::getCiteStyles(engine);
return true;
}
void GuiCitation::filterByEntryType(
- vector<docstring> & keyVector, docstring entryType)
+ vector<docstring> & keyVector, docstring entry_type)
{
- if (entryType.empty())
+ if (entry_type.empty())
return;
vector<docstring>::iterator it = keyVector.begin();
BiblioInfo::const_iterator cit = bibkeysInfo_.find(key);
if (cit == bibkeysInfo_.end())
continue;
- if (cit->second.entryType == entryType)
+ if (cit->second.entryType() == entry_type)
result.push_back(key);
}
keyVector = result;
{
vector<docstring> foundKeys;
- docstring expr = support::trim(search_expression);
+ docstring expr = trim(search_expression);
if (expr.empty())
return foundKeys;
// it is treated as a simple string by boost::regex.
expr = escape_special_chars(expr);
- boost::regex reg_exp(to_utf8(expr), case_sensitive ?
- boost::regex_constants::normal : boost::regex_constants::icase);
+ boost::regex reg_exp;
+ try {
+ reg_exp.assign(to_utf8(expr), case_sensitive ?
+ boost::regex_constants::normal : boost::regex_constants::icase);
+ } catch (boost::regex_error & e) {
+ // boost::regex throws an exception if the regular expression is not
+ // valid.
+ LYXERR(Debug::GUI, e.what());
+ return vector<docstring>();
+ }
vector<docstring>::const_iterator it = keys_to_search.begin();
vector<docstring>::const_iterator end = keys_to_search.end();
if (only_keys)
data = to_utf8(*it);
else if (field.empty())
- data = to_utf8(*it) + ' ' + to_utf8(kvm.allData);
+ data = to_utf8(*it) + ' ' + to_utf8(kvm.allData());
else if (kvm.hasField(field))
data = to_utf8(kvm.getValueForField(field));
if (boost::regex_search(data, reg_exp))
foundKeys.push_back(*it);
}
- catch (boost::regex_error &) {
+ catch (boost::regex_error & e) {
+ LYXERR(Debug::GUI, e.what());
return vector<docstring>();
}
}