X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiCitation.cpp;h=1135d54aa4f5e14f102836cb082cff725c76daf4;hb=ba76bf5eb85db5a10839fccee3430d906d3f7b70;hp=7e6470b963fb75d904d8c3d9b02d9a89346aacfc;hpb=604c1148ea8beedaebbe0bdbe5a0adc76237a697;p=lyx.git diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp index 7e6470b963..1135d54aa4 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -40,9 +40,8 @@ #include #include -using std::string; -using std::vector; -using std::pair; +using namespace std; +using namespace lyx::support; namespace lyx { namespace frontend { @@ -77,13 +76,12 @@ static vector to_docstring_vector(QStringList const & qlist) 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()), @@ -121,13 +119,13 @@ void GuiCitation::closeEvent(QCloseEvent * e) { 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(); @@ -189,7 +187,7 @@ void GuiCitation::updateView() // 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() { @@ -213,7 +211,7 @@ void GuiCitation::updateDialog() } -void GuiCitation::updateStyle() +void GuiCitation::updateFormatting(biblio::CiteStyle currentStyle) { biblio::CiteEngine const engine = getEngine(); bool const natbib_engine = @@ -223,15 +221,22 @@ void GuiCitation::updateStyle() 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 @@ -256,9 +261,9 @@ void GuiCitation::updateStyle() 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. @@ -284,12 +289,10 @@ void GuiCitation::fillStyles() 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); @@ -373,15 +376,15 @@ void GuiCitation::findText(QString const & text, bool reset) //"All Entry Types" is first. index = entriesCO->currentIndex() - 1; vector 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 @@ -404,6 +407,15 @@ void GuiCitation::on_entriesCO_currentIndexChanged(int /*index*/) } +void GuiCitation::on_citationStyleCO_currentIndexChanged(int index) +{ + if (index >= 0 && index < citationStyleCO->count()) { + vector const & styles = citeStyles_; + updateFormatting(styles[index]); + } +} + + void GuiCitation::on_findLE_textChanged(const QString & text) { clearPB->setDisabled(text.isEmpty()); @@ -427,19 +439,24 @@ void GuiCitation::on_regexCB_stateChanged(int) 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 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(); @@ -488,7 +505,7 @@ void GuiCitation::init() 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. @@ -524,10 +541,10 @@ void GuiCitation::findKey(QString const & str, bool only_keys, 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 keyVector = to_docstring_vector(keys); - filterByEntryType(keyVector, entryType); + filterByEntryType(keyVector, entry_type); if (str.isEmpty()) result = to_qstring_list(keyVector); @@ -576,17 +593,9 @@ bool GuiCitation::initialiseParams(string const & data) 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; } @@ -618,9 +627,9 @@ vector const GuiCitation::availableEntries() const void GuiCitation::filterByEntryType( - vector & keyVector, docstring entryType) + vector & keyVector, docstring entry_type) { - if (entryType.empty()) + if (entry_type.empty()) return; vector::iterator it = keyVector.begin(); @@ -632,7 +641,7 @@ void GuiCitation::filterByEntryType( 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; @@ -684,7 +693,7 @@ vector GuiCitation::searchKeys( { vector foundKeys; - docstring expr = support::trim(search_expression); + docstring expr = trim(search_expression); if (expr.empty()) return foundKeys; @@ -693,8 +702,16 @@ vector GuiCitation::searchKeys( // 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(); + } vector::const_iterator it = keys_to_search.begin(); vector::const_iterator end = keys_to_search.end(); @@ -708,7 +725,7 @@ vector GuiCitation::searchKeys( 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)); @@ -719,7 +736,8 @@ vector GuiCitation::searchKeys( 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(); } }