X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiCitation.cpp;h=1135d54aa4f5e14f102836cb082cff725c76daf4;hb=ba76bf5eb85db5a10839fccee3430d906d3f7b70;hp=d224cf1c85b024f68adac3b328f450b32244e803;hpb=503a41ad15a7a88507ad32cdffd29ea4b4418316;p=lyx.git diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp index d224cf1c85..1135d54aa4 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -41,6 +41,7 @@ #include using namespace std; +using namespace lyx::support; namespace lyx { namespace frontend { @@ -75,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()), @@ -119,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(); @@ -187,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() { @@ -211,7 +211,7 @@ void GuiCitation::updateDialog() } -void GuiCitation::updateStyle() +void GuiCitation::updateFormatting(biblio::CiteStyle currentStyle) { biblio::CiteEngine const engine = getEngine(); bool const natbib_engine = @@ -221,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 @@ -254,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. @@ -282,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); @@ -371,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 @@ -402,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()); @@ -425,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(); @@ -486,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. @@ -522,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); @@ -574,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; } @@ -616,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(); @@ -630,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; @@ -682,7 +693,7 @@ vector GuiCitation::searchKeys( { vector foundKeys; - docstring expr = support::trim(search_expression); + docstring expr = trim(search_expression); if (expr.empty()) return foundKeys; @@ -698,7 +709,7 @@ vector GuiCitation::searchKeys( } catch (boost::regex_error & e) { // boost::regex throws an exception if the regular expression is not // valid. - LYXERR0(Debug::GUI, e.what()); + LYXERR(Debug::GUI, e.what()); return vector(); } @@ -714,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));