#include "GuiCitation.h"
-#include "support/debug.h"
-#include "support/gettext.h"
+#include "GuiSelectionManager.h"
#include "qt_helpers.h"
+
#include "Buffer.h"
+#include "BiblioInfo.h"
#include "BufferParams.h"
-
-#include "support/lstrings.h"
-#include "support/docstring.h"
+#include "FuncRequest.h"
#include "insets/InsetCommand.h"
-#include <vector>
-#include <string>
+#include "support/debug.h"
+#include "support/docstring.h"
+#include "support/gettext.h"
+#include "support/lstrings.h"
#include <QCloseEvent>
+#include <QSettings>
#include <QShowEvent>
+#include <QVariant>
+
+#include <vector>
+#include <string>
#undef KeyPress
namespace lyx {
namespace frontend {
-static vector<biblio::CiteStyle> citeStyles_;
+static vector<CiteStyle> citeStyles_;
template<typename String>
GuiCitation::GuiCitation(GuiView & lv)
- : GuiCommand(lv, "citation", qt_("Citation"))
+ : DialogView(lv, "citation", qt_("Citation")),
+ params_(insetCode("citation"))
{
setupUi(this);
this, SLOT(changed()));
connect(textAfterED, SIGNAL(textChanged(QString)),
this, SLOT(changed()));
- connect(clearPB, SIGNAL(clicked()),
- findLE, SLOT(clear()));
+ connect(findLE, SIGNAL(returnPressed()),
+ this, SLOT(on_searchPB_clicked()));
+ connect(textBeforeED, SIGNAL(returnPressed()),
+ this, SLOT(on_okPB_clicked()));
+ connect(textAfterED, SIGNAL(returnPressed()),
+ this, SLOT(on_okPB_clicked()));
+
connect(this, SIGNAL(rejected()), this, SLOT(cleanUp()));
selectionManager = new GuiSelectionManager(availableLV, selectedLV,
- addPB, deletePB, upPB, downPB, available(), selected());
+ addPB, deletePB, upPB, downPB, &available_model_, &selected_model_);
connect(selectionManager, SIGNAL(selectionChanged()),
this, SLOT(setCitedKeys()));
connect(selectionManager, SIGNAL(updateHook()),
- this, SLOT(updateDialog()));
+ this, SLOT(updateControls()));
connect(selectionManager, SIGNAL(okHook()),
this, SLOT(on_okPB_clicked()));
- bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
+ // FIXME: the sizeHint() for this is _way_ too high
+ infoML->setFixedHeight(60);
+}
+
+
+GuiCitation::~GuiCitation()
+{
+ delete selectionManager;
}
{
clearSelection();
clearParams();
- GuiDialog::closeEvent(e);
+ e->accept();
}
void GuiCitation::applyView()
{
- int const choice = max(0, citationStyleCO->currentIndex());
+ int const choice = max(0, citationStyleCO->currentIndex());
style_ = choice;
bool const full = fulllistCB->isChecked();
bool const force = forceuppercaseCB->isChecked();
void GuiCitation::showEvent(QShowEvent * e)
{
- init();
findLE->clear();
availableLV->setFocus();
- GuiDialog::showEvent(e);
+ DialogView::showEvent(e);
}
void GuiCitation::on_restorePB_clicked()
{
init();
- updateView();
-}
-
-
-void GuiCitation::updateView()
-{
- init();
- fillFields();
- fillEntries();
- updateDialog();
}
// will not have changed. At the moment, however, the division between
// fillStyles() and updateStyle() doesn't lend itself to dividing the
// two methods, though they should be divisible.
-void GuiCitation::updateDialog()
+void GuiCitation::updateControls()
{
if (selectionManager->selectedFocused()) {
if (selectedLV->selectionModel()->selectedIndexes().isEmpty())
}
setButtons();
- textBeforeED->setText(textBefore());
- textAfterED->setText(textAfter());
+ textBeforeED->setText(toqstr(params_["before"]));
+ textAfterED->setText(toqstr(params_["after"]));
fillStyles();
updateStyle();
}
-void GuiCitation::updateFormatting(biblio::CiteStyle currentStyle)
+void GuiCitation::updateFormatting(CiteStyle currentStyle)
{
- biblio::CiteEngine const engine = getEngine();
+ CiteEngine const engine = citeEngine();
bool const natbib_engine =
- engine == biblio::ENGINE_NATBIB_AUTHORYEAR ||
- engine == biblio::ENGINE_NATBIB_NUMERICAL;
- bool const basic_engine = engine == biblio::ENGINE_BASIC;
+ engine == ENGINE_NATBIB_AUTHORYEAR ||
+ engine == ENGINE_NATBIB_NUMERICAL;
+ bool const basic_engine = engine == ENGINE_BASIC;
bool const haveSelection =
selectedLV->model()->rowCount() > 0;
- bool const isNocite = currentStyle == biblio::NOCITE;
+ bool const isNocite = currentStyle == NOCITE;
fulllistCB->setEnabled(natbib_engine && haveSelection && !isNocite);
forceuppercaseCB->setEnabled(natbib_engine && haveSelection && !isNocite);
string const & command = params_.getCmdName();
// Find the style of the citekeys
- vector<biblio::CiteStyle> const & styles = citeStyles_;
- biblio::CitationStyle const cs(command);
+ vector<CiteStyle> const & styles = citeStyles_;
+ CitationStyle const cs = citationStyleFromString(command);
- vector<biblio::CiteStyle>::const_iterator cit =
+ vector<CiteStyle>::const_iterator cit =
std::find(styles.begin(), styles.end(), cs.style);
// restore the latest natbib style
int const i = int(cit - styles.begin());
citationStyleCO->setCurrentIndex(i);
fulllistCB->setChecked(cs.full);
- forceuppercaseCB->setChecked(cs.forceUCase);
+ forceuppercaseCB->setChecked(cs.forceUpperCase);
} else {
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.
+// 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.
void GuiCitation::fillStyles()
{
int const oldIndex = citationStyleCO->currentIndex();
citationStyleCO->clear();
- QStringList selected_keys = selected()->stringList();
+ QStringList selected_keys = selected_model_.stringList();
if (selected_keys.empty()) {
citationStyleCO->setEnabled(false);
citationStyleLA->setEnabled(false);
fieldsCO->blockSignals(true);
int const oldIndex = fieldsCO->currentIndex();
fieldsCO->clear();
- QStringList const & fields = getFieldsAsQStringList();
+ QStringList const fields = to_qstring_list(bibInfo().getFields());
fieldsCO->insertItem(0, qt_("All Fields"));
fieldsCO->insertItem(1, qt_("Keys"));
fieldsCO->insertItems(2, fields);
entriesCO->blockSignals(true);
int const oldIndex = entriesCO->currentIndex();
entriesCO->clear();
- QStringList const & entries = getEntriesAsQStringList();
+ QStringList const entries = to_qstring_list(bibInfo().getEntries());
entriesCO->insertItem(0, qt_("All Entry Types"));
entriesCO->insertItems(1, entries);
if (oldIndex != -1 && oldIndex < entriesCO->count())
bool GuiCitation::isSelected(const QModelIndex & idx)
{
QString const str = idx.data().toString();
- return selected()->stringList().contains(str);
+ return selected_model_.stringList().contains(str);
}
void GuiCitation::updateInfo(QModelIndex const & idx)
{
- if (idx.isValid()) {
- QString const keytxt = getKeyInfo(idx.data().toString());
- infoML->document()->setPlainText(keytxt);
- } else
+ if (!idx.isValid() || bibInfo().empty()) {
infoML->document()->clear();
+ return;
+ }
+
+ QString const keytxt = toqstr(
+ bibInfo().getInfo(qstring_to_ucs4(idx.data().toString())));
+ infoML->document()->setPlainText(keytxt);
}
{
//"All Fields" and "Keys" are the first two
int index = fieldsCO->currentIndex() - 2;
- vector<docstring> const & fields = availableFields();
+ vector<docstring> const & fields = bibInfo().getFields();
docstring field;
if (index <= -1 || index >= int(fields.size()))
//"All Entry Types" is first.
index = entriesCO->currentIndex() - 1;
- vector<docstring> const & entries = availableEntries();
- docstring entryType;
+ vector<docstring> const & entries = bibInfo().getEntries();
+ 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
//availableLV. Currently, we get an automatic reset, since the
//model is reset.
- updateDialog();
+ updateControls();
}
void GuiCitation::on_citationStyleCO_currentIndexChanged(int index)
{
if (index >= 0 && index < citationStyleCO->count()) {
- vector<biblio::CiteStyle> const & styles = citeStyles_;
+ vector<CiteStyle> const & styles = citeStyles_;
updateFormatting(styles[index]);
}
}
void GuiCitation::on_findLE_textChanged(const QString & text)
{
- clearPB->setDisabled(text.isEmpty());
- if (text.isEmpty())
- findLE->setFocus();
- findText(text);
+ bool const searchAsWeGo = (asTypeCB->checkState() == Qt::Checked);
+ searchPB->setDisabled(text.isEmpty() || searchAsWeGo);
+ if (!text.isEmpty()) {
+ if (searchAsWeGo)
+ findText(findLE->text());
+ return;
+ }
+ findText(findLE->text());
+ findLE->setFocus();
+}
+
+void GuiCitation::on_searchPB_clicked()
+{
+ findText(findLE->text(), true);
}
}
+void GuiCitation::on_asTypeCB_stateChanged(int)
+{
+ bool const searchAsWeGo = (asTypeCB->checkState() == Qt::Checked);
+ searchPB->setDisabled(findLE->text().isEmpty() || searchAsWeGo);
+ if (searchAsWeGo)
+ findText(findLE->text(), true);
+}
+
+
void GuiCitation::changed()
{
setButtons();
if (cited_keys_.isEmpty())
return;
- vector<biblio::CiteStyle> const & styles = citeStyles_;
- if (styles[choice] == biblio::NOCITE) {
+ vector<CiteStyle> const & styles = citeStyles_;
+ if (styles[choice] == NOCITE) {
full = false;
force = false;
before.clear();
after.clear();
}
- string const command =
- biblio::CitationStyle(styles[choice], full, force)
- .asLatexStr();
+ CitationStyle s;
+ s.style = styles[choice];
+ s.full = full;
+ s.forceUpperCase = force;
+ string const command = citationStyleToString(s);
params_.setCmdName(command);
params_["key"] = qstring_to_ucs4(cited_keys_.join(","));
}
-QString GuiCitation::textBefore()
-{
- return toqstr(params_["before"]);
-}
-
-
-QString GuiCitation::textAfter()
-{
- return toqstr(params_["after"]);
-}
-
-
void GuiCitation::init()
{
// Make the list of all available bibliography keys
- all_keys_ = to_qstring_list(availableKeys());
+ all_keys_ = to_qstring_list(bibInfo().getKeys());
available_model_.setStringList(all_keys_);
// Ditto for the keys cited in this inset
else
cited_keys_ = str.split(",");
selected_model_.setStringList(cited_keys_);
+
+ fillFields();
+ fillEntries();
+ updateControls();
}
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.
last_case_sensitive = case_sensitive;
last_reg_exp = reg_exp;
- Qt::CaseSensitivity qtcase = case_sensitive?
+ Qt::CaseSensitivity qtcase = case_sensitive ?
Qt::CaseSensitive: Qt::CaseInsensitive;
QStringList keys;
// If new string (str) contains the last searched one...
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);
}
-QStringList GuiCitation::getFieldsAsQStringList()
-{
- return to_qstring_list(availableFields());
-}
-
-
-QStringList GuiCitation::getEntriesAsQStringList()
-{
- return to_qstring_list(availableEntries());
-}
-
-
QStringList GuiCitation::citationStyles(int sel)
{
docstring const key = qstring_to_ucs4(cited_keys_[sel]);
- return to_qstring_list(bibkeysInfo_.getCiteStrings(key, buffer()));
-}
-
-
-QString GuiCitation::getKeyInfo(QString const & sel)
-{
- return toqstr(getInfo(qstring_to_ucs4(sel)));
+ return to_qstring_list(bibInfo().getCiteStrings(key, buffer()));
}
bool GuiCitation::initialiseParams(string const & data)
{
- InsetCommandMailer::string2params(lfun_name_, data, params_);
-
- biblio::CiteEngine const engine = buffer().params().getEngine();
-
- bibkeysInfo_.fillWithBibKeys(&buffer());
-
- citeStyles_ = biblio::getCiteStyles(engine);
-
+ InsetCommand::string2params("citation", data, params_);
+ CiteEngine const engine = buffer().params().citeEngine();
+ citeStyles_ = citeStyles(engine);
+ init();
return true;
}
void GuiCitation::clearParams()
{
params_.clear();
- bibkeysInfo_.clear();
-}
-
-
-vector<docstring> const GuiCitation::availableKeys() const
-{
- return bibkeysInfo_.getKeys();
-}
-
-
-vector<docstring> const GuiCitation::availableFields() const
-{
- return bibkeysInfo_.getFields();
-}
-
-
-vector<docstring> const GuiCitation::availableEntries() const
-{
- return bibkeysInfo_.getEntries();
}
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();
vector<docstring> result;
for (; it != end; ++it) {
docstring const key = *it;
- BiblioInfo::const_iterator cit = bibkeysInfo_.find(key);
- if (cit == bibkeysInfo_.end())
+ BiblioInfo::const_iterator cit = bibInfo().find(key);
+ if (cit == bibInfo().end())
continue;
- if (cit->second.entryType() == entryType)
+ if (cit->second.entryType() == entry_type)
result.push_back(key);
}
keyVector = result;
}
-biblio::CiteEngine GuiCitation::getEngine() const
+CiteEngine GuiCitation::citeEngine() const
{
- return buffer().params().getEngine();
-}
-
-
-docstring GuiCitation::getInfo(docstring const & key) const
-{
- if (bibkeysInfo_.empty())
- return docstring();
-
- return bibkeysInfo_.getInfo(key);
+ return buffer().params().citeEngine();
}
vector<docstring>::const_iterator it = keys_to_search.begin();
vector<docstring>::const_iterator end = keys_to_search.end();
for (; it != end; ++it ) {
- BiblioInfo::const_iterator info = bibkeysInfo_.find(*it);
- if (info == bibkeysInfo_.end())
+ BiblioInfo::const_iterator info = bibInfo().find(*it);
+ if (info == bibInfo().end())
continue;
BibTeXInfo const & kvm = info->second;
}
+void GuiCitation::dispatchParams()
+{
+ std::string const lfun = InsetCommand::params2string("citation", params_);
+ dispatch(FuncRequest(getLfun(), lfun));
+}
+
+
+BiblioInfo const & GuiCitation::bibInfo() const
+{
+ return buffer().masterBibInfo();
+}
+
+
+void GuiCitation::saveSession() const
+{
+ Dialog::saveSession();
+ QSettings settings;
+ settings.setValue(
+ sessionKey() + "/regex", regexCB->isChecked());
+ settings.setValue(
+ sessionKey() + "/casesensitive", caseCB->isChecked());
+ settings.setValue(
+ sessionKey() + "/autofind", asTypeCB->isChecked());
+}
+
+
+void GuiCitation::restoreSession()
+{
+ Dialog::restoreSession();
+ QSettings settings;
+ regexCB->setChecked(
+ settings.value(sessionKey() + "/regex").toBool());
+ caseCB->setChecked(
+ settings.value(sessionKey() + "/casesensitive").toBool());
+ asTypeCB->setChecked(
+ settings.value(sessionKey() + "/autofind").toBool());
+}
+
+
Dialog * createGuiCitation(GuiView & lv) { return new GuiCitation(lv); }