]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiCitation.cpp
Compil fix.
[lyx.git] / src / frontends / qt4 / GuiCitation.cpp
index c70b7c5938eeac5d2478677e10ba33eb823f5805..abc30048c296dd335e28cfaf5b35e8d7cd98c9d9 100644 (file)
 
 #include "GuiCitation.h"
 
+#include "GuiSelectionManager.h"
 #include "qt_helpers.h"
+
 #include "Buffer.h"
+#include "BiblioInfo.h"
 #include "BufferParams.h"
 #include "FuncRequest.h"
 
@@ -28,7 +31,9 @@
 #include "support/lstrings.h"
 
 #include <QCloseEvent>
+#include <QSettings>
 #include <QShowEvent>
+#include <QVariant>
 
 #include <vector>
 #include <string>
@@ -77,7 +82,7 @@ static vector<lyx::docstring> to_docstring_vector(QStringList const & qlist)
 
 
 GuiCitation::GuiCitation(GuiView & lv)
-       : GuiDialog(lv, "citation", qt_("Citation")),
+       : DialogView(lv, "citation", qt_("Citation")),
          params_(insetCode("citation"))
 {
        setupUi(this);
@@ -102,15 +107,22 @@ GuiCitation::GuiCitation(GuiView & lv)
        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;
 }
 
 
@@ -132,7 +144,7 @@ void GuiCitation::closeEvent(QCloseEvent * e)
 
 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();
@@ -146,10 +158,9 @@ void GuiCitation::applyView()
 
 void GuiCitation::showEvent(QShowEvent * e)
 {
-       init();
        findLE->clear();
        availableLV->setFocus();
-       GuiDialog::showEvent(e);
+       DialogView::showEvent(e);
 }
 
 
@@ -177,16 +188,6 @@ void GuiCitation::on_applyPB_clicked()
 void GuiCitation::on_restorePB_clicked()
 {
        init();
-       updateView();
-}
-
-
-void GuiCitation::updateView()
-{
-       init();
-       fillFields();
-       fillEntries();
-       updateDialog();
 }
 
 
@@ -196,7 +197,7 @@ void GuiCitation::updateView()
 // 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())
@@ -211,8 +212,8 @@ void GuiCitation::updateDialog()
        }
        setButtons();
 
-       textBeforeED->setText(textBefore());
-       textAfterED->setText(textAfter());
+       textBeforeED->setText(toqstr(params_["before"]));
+       textAfterED->setText(toqstr(params_["after"]));
        fillStyles();
        updateStyle();
 }
@@ -280,7 +281,7 @@ void GuiCitation::fillStyles()
 
        citationStyleCO->clear();
 
-       QStringList selected_keys = selected()->stringList();
+       QStringList selected_keys = selected_model_.stringList();
        if (selected_keys.empty()) {
                citationStyleCO->setEnabled(false);
                citationStyleLA->setEnabled(false);
@@ -314,7 +315,7 @@ void GuiCitation::fillFields()
        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);
@@ -329,7 +330,7 @@ void GuiCitation::fillEntries()
        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())
@@ -341,7 +342,7 @@ void GuiCitation::fillEntries()
 bool GuiCitation::isSelected(const QModelIndex & idx)
 {
        QString const str = idx.data().toString();
-       return selected()->stringList().contains(str);
+       return selected_model_.stringList().contains(str);
 }
 
 
@@ -356,11 +357,14 @@ void GuiCitation::setButtons()
 
 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);
 }
 
 
@@ -368,7 +372,7 @@ void GuiCitation::findText(QString const & text, bool reset)
 {
        //"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()))
@@ -382,7 +386,7 @@ void GuiCitation::findText(QString const & text, bool reset)
        
        //"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("");
@@ -398,7 +402,7 @@ void GuiCitation::findText(QString const & text, bool reset)
        //availableLV. Currently, we get an automatic reset, since the
        //model is reset.
        
-       updateDialog();
+       updateControls();
 }
 
 
@@ -504,22 +508,10 @@ void GuiCitation::clearSelection()
 }
 
 
-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
@@ -529,6 +521,10 @@ void GuiCitation::init()
        else
                cited_keys_ = str.split(",");
        selected_model_.setStringList(cited_keys_);
+
+       fillFields();
+       fillEntries();
+       updateControls();
 }
 
 
@@ -584,18 +580,6 @@ void GuiCitation::findKey(QString const & str, bool only_keys,
 }
 
 
-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]);
@@ -603,12 +587,6 @@ QStringList GuiCitation::citationStyles(int sel)
 }
 
 
-QString GuiCitation::getKeyInfo(QString const & sel)
-{
-       return toqstr(getInfo(qstring_to_ucs4(sel)));
-}
-
-
 void GuiCitation::setCitedKeys() 
 {
        cited_keys_ = selected_model_.stringList();
@@ -620,6 +598,7 @@ bool GuiCitation::initialiseParams(string const & data)
        InsetCommand::string2params("citation", data, params_);
        CiteEngine const engine = buffer().params().citeEngine();
        citeStyles_ = citeStyles(engine);
+       init();
        return true;
 }
 
@@ -630,24 +609,6 @@ void GuiCitation::clearParams()
 }
 
 
-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) 
 {
@@ -676,15 +637,6 @@ CiteEngine GuiCitation::citeEngine() const
 }
 
 
-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
@@ -780,6 +732,32 @@ BiblioInfo const & GuiCitation::bibInfo() const
 }
 
 
+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); }