#include "GuiCitation.h"
+#include "GuiSelectionManager.h"
#include "qt_helpers.h"
+
#include "Buffer.h"
+#include "BiblioInfo.h"
#include "BufferParams.h"
#include "FuncRequest.h"
#include "support/lstrings.h"
#include <QCloseEvent>
+#include <QSettings>
#include <QShowEvent>
+#include <QVariant>
#include <vector>
#include <string>
GuiCitation::GuiCitation(GuiView & lv)
- : GuiDialog(lv, "citation", qt_("Citation")),
+ : DialogView(lv, "citation", qt_("Citation")),
params_(insetCode("citation"))
{
setupUi(this);
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;
}
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();
}
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();
+ vector<docstring> const & entries = bibInfo().getEntries();
docstring entry_type;
if (index < 0 || index >= int(entries.size()))
entry_type = from_ascii("");
//availableLV. Currently, we get an automatic reset, since the
//model is reset.
- updateDialog();
+ updateControls();
}
}
-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();
}
}
-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]);
}
-QString GuiCitation::getKeyInfo(QString const & sel)
-{
- return toqstr(getInfo(qstring_to_ucs4(sel)));
-}
-
-
void GuiCitation::setCitedKeys()
{
cited_keys_ = selected_model_.stringList();
InsetCommand::string2params("citation", data, params_);
CiteEngine const engine = buffer().params().citeEngine();
citeStyles_ = citeStyles(engine);
+ init();
return true;
}
}
-vector<docstring> GuiCitation::availableKeys() const
-{
- return bibInfo().getKeys();
-}
-
-
-vector<docstring> GuiCitation::availableFields() const
-{
- return bibInfo().getFields();
-}
-
-
-vector<docstring> GuiCitation::availableEntries() const
-{
- return bibInfo().getEntries();
-}
-
-
void GuiCitation::filterByEntryType(
vector<docstring> & keyVector, docstring entry_type)
{
}
-docstring GuiCitation::getInfo(docstring const & key) const
-{
- if (bibInfo().empty())
- return docstring();
-
- return bibInfo().getInfo(key);
-}
-
-
// Escape special chars.
// All characters are literals except: '.|*?+(){}[]^$\'
// These characters are literals when preceded by a "\", which is done here
}
+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); }