mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
Correct restoration of citation style selection between engine switches
We stored the combo position index, but this changes on engine switch. This also fixes a crash due to out-of-bound index at engine switch. Fixes: #10692
This commit is contained in:
parent
9913fe650d
commit
5685080356
@ -1367,21 +1367,21 @@ bool BiblioInfo::isBibtex(docstring const & key) const
|
||||
}
|
||||
|
||||
|
||||
vector<docstring> const BiblioInfo::getCiteStrings(
|
||||
BiblioInfo::CiteStringMap const BiblioInfo::getCiteStrings(
|
||||
vector<docstring> const & keys, vector<CitationStyle> const & styles,
|
||||
Buffer const & buf, CiteItem const & ci) const
|
||||
{
|
||||
if (empty())
|
||||
return vector<docstring>();
|
||||
return vector<pair<docstring,docstring>>();
|
||||
|
||||
string style;
|
||||
vector<docstring> vec(styles.size());
|
||||
for (size_t i = 0; i != vec.size(); ++i) {
|
||||
CiteStringMap csm(styles.size());
|
||||
for (size_t i = 0; i != csm.size(); ++i) {
|
||||
style = styles[i].name;
|
||||
vec[i] = getLabel(keys, buf, style, ci);
|
||||
csm[i] = make_pair(from_ascii(style), getLabel(keys, buf, style, ci));
|
||||
}
|
||||
|
||||
return vec;
|
||||
return csm;
|
||||
}
|
||||
|
||||
|
||||
|
@ -222,10 +222,16 @@ public:
|
||||
/// Is this a reference from a bibtex database
|
||||
/// or from a bibliography environment?
|
||||
bool isBibtex(docstring const & key) const;
|
||||
/// A vector holding a pair of lyx cite command and the respective
|
||||
/// output for a given (list of) key(s).
|
||||
typedef std::vector<std::pair<docstring,docstring>> CiteStringMap;
|
||||
/// Translates the available citation styles into strings for a given
|
||||
/// list of keys, using either numerical or author-year style depending
|
||||
/// upon the active engine.
|
||||
std::vector<docstring> const getCiteStrings(std::vector<docstring> const & keys,
|
||||
/// upon the active engine. The function returns a CiteStringMap with the first
|
||||
/// element being the lyx cite command, the second being the formatted
|
||||
/// citation reference.
|
||||
CiteStringMap const getCiteStrings(
|
||||
std::vector<docstring> const & keys,
|
||||
std::vector<CitationStyle> const & styles, Buffer const & buf,
|
||||
CiteItem const & ci) const;
|
||||
/// A list of BibTeX keys cited in the current document, sorted by
|
||||
|
@ -92,7 +92,7 @@ static vector<lyx::docstring> to_docstring_vector(QStringList const & qlist)
|
||||
|
||||
GuiCitation::GuiCitation(GuiView & lv)
|
||||
: DialogView(lv, "citation", qt_("Citation")),
|
||||
style_(0), params_(insetCode("citation"))
|
||||
style_(QString()), params_(insetCode("citation"))
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
@ -188,7 +188,7 @@ void GuiCitation::closeEvent(QCloseEvent * e)
|
||||
void GuiCitation::applyView()
|
||||
{
|
||||
int const choice = max(0, citationStyleCO->currentIndex());
|
||||
style_ = choice;
|
||||
style_ = citationStyleCO->currentData().toString();
|
||||
bool const full = starredCB->isChecked();
|
||||
bool const force = forceuppercaseCB->isChecked();
|
||||
|
||||
@ -258,7 +258,7 @@ void GuiCitation::updateControls(BiblioInfo const & bi)
|
||||
QModelIndex idx = selectionManager->getSelectedIndex(1);
|
||||
updateInfo(bi, idx);
|
||||
int i = citationStyleCO->currentIndex();
|
||||
if (i == -1)
|
||||
if (i == -1 || i > int(citeStyles_.size()))
|
||||
i = 0;
|
||||
updateFormatting(citeStyles_[i]);
|
||||
selectionManager->update();
|
||||
@ -379,9 +379,9 @@ void GuiCitation::updateStyles(BiblioInfo const & bi)
|
||||
}
|
||||
|
||||
static const size_t max_length = 80;
|
||||
QStringList sty = citationStyles(bi, max_length);
|
||||
BiblioInfo::CiteStringMap sty = citationStyles(bi, max_length);
|
||||
|
||||
if (sty.isEmpty()) {
|
||||
if (sty.empty()) {
|
||||
// some error
|
||||
citationStyleCO->setEnabled(false);
|
||||
citationStyleLA->setEnabled(false);
|
||||
@ -391,16 +391,20 @@ void GuiCitation::updateStyles(BiblioInfo const & bi)
|
||||
|
||||
citationStyleCO->blockSignals(true);
|
||||
|
||||
// save old index
|
||||
int const curindex = citationStyleCO->currentIndex();
|
||||
int const oldIndex = (curindex < 0) ? style_ : curindex;
|
||||
// save old style selection
|
||||
QString const curdata = citationStyleCO->currentData().toString();
|
||||
QString const olddata = (curdata.isEmpty()) ? style_ : curdata;
|
||||
citationStyleCO->clear();
|
||||
citationStyleCO->insertItems(0, sty);
|
||||
BiblioInfo::CiteStringMap::const_iterator cit = sty.begin();
|
||||
BiblioInfo::CiteStringMap::const_iterator end = sty.end();
|
||||
for (int ii = 1; cit != end; ++cit, ++ii)
|
||||
citationStyleCO->addItem(toqstr(cit->second), toqstr(cit->first));
|
||||
citationStyleCO->setEnabled(true);
|
||||
citationStyleLA->setEnabled(true);
|
||||
// restore old index
|
||||
if (oldIndex != -1 && oldIndex < citationStyleCO->count())
|
||||
citationStyleCO->setCurrentIndex(oldIndex);
|
||||
// restore old style selection
|
||||
int const i = citationStyleCO->findData(olddata);
|
||||
if (i != -1)
|
||||
citationStyleCO->setCurrentIndex(i);
|
||||
|
||||
citationStyleCO->blockSignals(false);
|
||||
}
|
||||
@ -855,7 +859,7 @@ void GuiCitation::findKey(BiblioInfo const & bi,
|
||||
}
|
||||
|
||||
|
||||
QStringList GuiCitation::citationStyles(BiblioInfo const & bi, size_t max_size)
|
||||
BiblioInfo::CiteStringMap GuiCitation::citationStyles(BiblioInfo const & bi, size_t max_size)
|
||||
{
|
||||
vector<docstring> const keys = to_docstring_vector(cited_keys_);
|
||||
vector<CitationStyle> styles = citeStyles_;
|
||||
@ -891,8 +895,8 @@ QStringList GuiCitation::citationStyles(BiblioInfo const & bi, size_t max_size)
|
||||
ci.isQualified = qualified;
|
||||
ci.pretexts = pres;
|
||||
ci.posttexts = posts;
|
||||
vector<docstring> ret = bi.getCiteStrings(keys, styles, documentBuffer(), ci);
|
||||
return to_qstring_list(ret);
|
||||
BiblioInfo::CiteStringMap ret = bi.getCiteStrings(keys, styles, documentBuffer(), ci);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -1068,7 +1072,7 @@ void GuiCitation::restoreSession()
|
||||
regexp_->setChecked(settings.value(sessionKey() + "/regex").toBool());
|
||||
casesense_->setChecked(settings.value(sessionKey() + "/casesensitive").toBool());
|
||||
instant_->setChecked(settings.value(sessionKey() + "/autofind", true).toBool());
|
||||
style_ = settings.value(sessionKey() + "/citestyle").toInt();
|
||||
style_ = settings.value(sessionKey() + "/citestyle").toString();
|
||||
literal_ = settings.value(sessionKey() + "/literal", false).toBool();
|
||||
updateFilterHint();
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "insets/InsetCommandParams.h"
|
||||
|
||||
#include "BiblioInfo.h"
|
||||
#include "Citation.h"
|
||||
|
||||
#include <QAbstractListModel>
|
||||
@ -141,8 +142,9 @@ private:
|
||||
bool reset = false //< whether to reset and search all keys
|
||||
);
|
||||
|
||||
/// List of example cite strings
|
||||
QStringList citationStyles(BiblioInfo const & bi, size_t max_size);
|
||||
/// List of example cite strings and their correlating lyx name
|
||||
BiblioInfo::CiteStringMap citationStyles(BiblioInfo const & bi,
|
||||
size_t max_size);
|
||||
|
||||
/// Set the Params variable for the Controller.
|
||||
void applyParams(int const choice, bool const full, bool const force,
|
||||
@ -180,7 +182,7 @@ private:
|
||||
QAction * instant_;
|
||||
|
||||
/// last used citation style
|
||||
int style_;
|
||||
QString style_;
|
||||
/// last set value for literal
|
||||
/// this is used only for new citations
|
||||
bool literal_;
|
||||
|
@ -1592,14 +1592,14 @@ void MenuDefinition::expandCiteStyles(BufferView const * bv)
|
||||
ci.isQualified = qualified;
|
||||
ci.pretexts = pres;
|
||||
ci.posttexts = posts;
|
||||
vector<docstring> citeStrings =
|
||||
BiblioInfo::CiteStringMap citeStrings =
|
||||
buf->masterBibInfo().getCiteStrings(keys, citeStyleList, bv->buffer(), ci);
|
||||
|
||||
vector<docstring>::const_iterator cit = citeStrings.begin();
|
||||
vector<docstring>::const_iterator end = citeStrings.end();
|
||||
BiblioInfo::CiteStringMap::const_iterator cit = citeStrings.begin();
|
||||
BiblioInfo::CiteStringMap::const_iterator end = citeStrings.end();
|
||||
|
||||
for (int ii = 1; cit != end; ++cit, ++ii) {
|
||||
docstring label = *cit;
|
||||
docstring label = cit->second;
|
||||
CitationStyle cs = citeStyleList[ii - 1];
|
||||
cs.forceUpperCase &= force;
|
||||
cs.hasStarredVersion &= star;
|
||||
|
Loading…
Reference in New Issue
Block a user