]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiBibtex.cpp
do what the FIXME suggested
[lyx.git] / src / frontends / qt4 / GuiBibtex.cpp
index a65b85dc10f276dded0ee14110c097cabd6a108e..052510b425c245360cd0c8347e4fcda6aec83231 100644 (file)
 
 #include "Buffer.h"
 #include "BufferParams.h"
-#include "support/debug.h"
 #include "ui_BibtexAddUi.h"
 #include "qt_helpers.h"
 #include "Validator.h"
 #include "LyXRC.h"
-#include "support/gettext.h"
 
 #include "ButtonPolicy.h"
 
+#include "support/debug.h"
+#include "support/FileFilterList.h"
 #include "support/filetools.h" // changeExtension
+#include "support/gettext.h"
 #include "support/lstrings.h"
-#include "support/FileFilterList.h"
 
 #include <QPushButton>
 #include <QListWidget>
 #include <QCheckBox>
-#include <QCloseEvent>
 #include <QLineEdit>
 
 using namespace std;
@@ -44,12 +43,10 @@ namespace frontend {
 
 
 GuiBibtex::GuiBibtex(GuiView & lv)
-       : GuiCommand(lv, "bibtex")
+       : GuiCommand(lv, "bibtex", qt_("BibTeX Bibliography"))
 {
        setupUi(this);
 
-       setViewTitle( _("BibTeX Bibliography"));
-
        QDialog::setModal(true);
 
        connect(okPB, SIGNAL(clicked()),
@@ -60,9 +57,13 @@ GuiBibtex::GuiBibtex(GuiView & lv)
                this, SLOT(browsePressed()));
        connect(deletePB, SIGNAL(clicked()),
                this, SLOT(deletePressed()));
+       connect(upPB, SIGNAL(clicked()),
+               this, SLOT(upPressed()));
+       connect(downPB, SIGNAL(clicked()),
+               this, SLOT(downPressed()));
        connect(styleCB, SIGNAL(editTextChanged(QString)),
                this, SLOT(change_adaptor()));
-       connect(databaseLW, SIGNAL(itemSelectionChanged()),
+       connect(databaseLW, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
                this, SLOT(databaseChanged()));
        connect(bibtocCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
@@ -87,7 +88,7 @@ GuiBibtex::GuiBibtex(GuiView & lv)
                this, SLOT(addDatabase()));
        connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
                add_, SLOT(accept()));
-       connect(add_->bibLW, SIGNAL(itemSelectionChanged()),
+       connect(add_->bibLW, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
                this, SLOT(availableChanged()));
        connect(add_->browsePB, SIGNAL(clicked()),
                this, SLOT(browseBibPressed()));
@@ -102,7 +103,11 @@ GuiBibtex::GuiBibtex(GuiView & lv)
        bc().addReadOnly(styleCB);
        bc().addReadOnly(bibtocCB);
        bc().addReadOnly(addBibPB);
-       bc().addReadOnly(deletePB);
+       // Delete/Up/Down are handled with more conditions in
+       // databaseChanged().
+
+       // Make sure the delete/up/down buttons are disabled if necessary.
+       databaseChanged();
 }
 
 
@@ -194,8 +199,14 @@ void GuiBibtex::addDatabase()
                        add_->bibLW->setItemSelected(item, false);
                        QList<QListWidgetItem *> matches =
                                databaseLW->findItems(item->text(), Qt::MatchExactly);
-                       if (matches.empty())
-                               databaseLW->addItem(item->text());
+                       if (matches.empty()) {
+                               QString label = item->text();
+                               QListWidgetItem * db = new QListWidgetItem(label);
+                               db->setFlags(db->flags() | Qt::ItemIsSelectable
+                                       | Qt::ItemIsUserCheckable);
+                               db->setCheckState(Qt::Checked);
+                               databaseLW->addItem(db);
+                       }
                }
        }
 
@@ -204,38 +215,65 @@ void GuiBibtex::addDatabase()
                QString const f = toqstr(from_utf8(changeExtension(to_utf8(file), "")));
                QList<QListWidgetItem *> matches =
                        databaseLW->findItems(f, Qt::MatchExactly);
-               if (matches.empty())
-                       databaseLW->addItem(f);
+               if (matches.empty()) {
+                       QListWidgetItem * db = new QListWidgetItem(f);
+                       db->setFlags(db->flags() | Qt::ItemIsSelectable
+                               | Qt::ItemIsUserCheckable);
+                       db->setCheckState(Qt::Checked);
+                       databaseLW->addItem(db);
+               }
        }
 
+       databaseChanged();
        changed();
 }
 
 
 void GuiBibtex::deletePressed()
 {
-       databaseLW->takeItem(databaseLW->currentRow());
-       changed();
+       QListWidgetItem *cur = databaseLW->takeItem(databaseLW->currentRow());
+       if (cur) {
+               delete cur;
+               databaseChanged();
+               changed();
+       }
 }
 
 
+void GuiBibtex::upPressed()
+{
+       int row = databaseLW->currentRow();
+       QListWidgetItem *cur = databaseLW->takeItem(row);
+       databaseLW->insertItem(row - 1, cur);
+       databaseLW->setCurrentItem(cur);
+       changed();
+}
+
 
-void GuiBibtex::databaseChanged()
+void GuiBibtex::downPressed()
 {
-       deletePB->setEnabled(!isBufferReadonly() && databaseLW->currentRow() != -1);
+       int row = databaseLW->currentRow();
+       QListWidgetItem *cur = databaseLW->takeItem(row);
+       databaseLW->insertItem(row + 1, cur);
+       databaseLW->setCurrentItem(cur);
+       changed();
 }
 
 
-void GuiBibtex::availableChanged()
+void GuiBibtex::databaseChanged()
 {
-       add_bc_.setValid(true);
+       bool readOnly = isBufferReadonly();
+       int count = databaseLW->count();
+       int row = databaseLW->currentRow();
+       deletePB->setEnabled(!readOnly && row != -1);
+       upPB->setEnabled(!readOnly && count > 1 && row > 0);
+       downPB->setEnabled(!readOnly && count > 1 && row < count - 1);
 }
 
 
-void GuiBibtex::closeEvent(QCloseEvent *e)
+void GuiBibtex::availableChanged()
 {
-       slotClose();
-       e->accept();
+       add_bc_.setValid(true);
 }
 
 
@@ -246,13 +284,21 @@ void GuiBibtex::updateContents()
        databaseLW->clear();
 
        docstring bibs = params_["bibfiles"];
+       docstring embs = params_["embed"];
        docstring bib;
+       docstring emb;
 
        while (!bibs.empty()) {
                bibs = split(bibs, bib, ',');
+               embs = split(embs, emb, ',');
                bib = trim(bib);
-               if (!bib.empty())
-                       databaseLW->addItem(toqstr(bib));
+               if (!bib.empty()) {
+                       QListWidgetItem * db = new QListWidgetItem(toqstr(bib));
+                       db->setFlags(db->flags() | Qt::ItemIsSelectable
+                               | Qt::ItemIsUserCheckable);
+                       db->setCheckState(emb.empty() ? Qt::Unchecked : Qt::Checked);
+                       databaseLW->addItem(db);
+               }
        }
 
        add_->bibLW->clear();
@@ -270,15 +316,20 @@ void GuiBibtex::updateContents()
        bibtocCB->setChecked(bibtotoc() && !bibtopic);
        bibtocCB->setEnabled(!bibtopic);
 
+       if (!bibtopic && btPrintCO->count() == 3)
+               btPrintCO->removeItem(1);
+       else if (bibtopic && btPrintCO->count() < 3)
+               btPrintCO->insertItem(1, qt_("all uncited references", 0));
+
        docstring btprint = params_["btprint"];
        int btp = 0;
-       if (btprint == "btPrintNotCited")
+       if ((bibtopic && btprint == "btPrintNotCited") ||
+          (!bibtopic && btprint == "btPrintAll"))
                btp = 1;
-       else if (btprint == "btPrintAll")
+       else if (bibtopic && btprint == "btPrintAll")
                btp = 2;
 
        btPrintCO->setCurrentIndex(btp);
-       btPrintCO->setEnabled(bibtopic);
 
        styleCB->clear();
 
@@ -309,14 +360,18 @@ void GuiBibtex::updateContents()
 void GuiBibtex::applyView()
 {
        docstring dbs = qstring_to_ucs4(databaseLW->item(0)->text());
+       docstring emb = databaseLW->item(0)->checkState() == Qt::Checked ? _("true") : _("false");
 
        unsigned int maxCount = databaseLW->count();
        for (unsigned int i = 1; i < maxCount; i++) {
                dbs += ',';
                dbs += qstring_to_ucs4(databaseLW->item(i)->text());
+               emb += ',';
+               emb += databaseLW->item(i)->checkState() == Qt::Checked ? _("true") : _("false");
        }
 
        params_["bibfiles"] = dbs;
+       params_["embed"] = emb;
 
        docstring const bibstyle = qstring_to_ucs4(styleCB->currentText());
        bool const bibtotoc = bibtocCB->isChecked();
@@ -334,26 +389,35 @@ void GuiBibtex::applyView()
                params_["options"] = bibstyle;
        }
 
-       // bibtopic allows three kinds of sections:
-       // 1. sections that include all cited references of the database(s)
-       // 2. sections that include all uncited references of the database(s)
-       // 3. sections that include all references of the database(s), cited or not
        int btp = btPrintCO->currentIndex();
 
-       switch (btp) {
-       case 0:
-               params_["btprint"] = from_ascii("btPrintCited");
-               break;
-       case 1:
-               params_["btprint"] = from_ascii("btPrintNotCited");
-               break;
-       case 2:
-               params_["btprint"] = from_ascii("btPrintAll");
-               break;
+       if (usingBibtopic()) {
+               // bibtopic allows three kinds of sections:
+               // 1. sections that include all cited references of the database(s)
+               // 2. sections that include all uncited references of the database(s)
+               // 3. sections that include all references of the database(s), cited or not
+               switch (btp) {
+               case 0:
+                       params_["btprint"] = from_ascii("btPrintCited");
+                       break;
+               case 1:
+                       params_["btprint"] = from_ascii("btPrintNotCited");
+                       break;
+               case 2:
+                       params_["btprint"] = from_ascii("btPrintAll");
+                       break;
+               }
+       } else {
+               switch (btp) {
+               case 0:
+                       params_["btprint"] = docstring();
+                       break;
+               case 1:
+                       // use \nocite{*}
+                       params_["btprint"] = from_ascii("btPrintAll");
+                       break;
+               }               
        }
-
-       if (!usingBibtopic())
-               params_["btprint"] = docstring();
 }