]> 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 643469f8f3285459b2eb0dbbbcad4a9397703d2b..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()),
@@ -66,7 +63,7 @@ GuiBibtex::GuiBibtex(GuiView & lv)
                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()));
@@ -91,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()));
@@ -106,7 +103,8 @@ 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();
@@ -226,6 +224,7 @@ void GuiBibtex::addDatabase()
                }
        }
 
+       databaseChanged();
        changed();
 }
 
@@ -235,6 +234,7 @@ void GuiBibtex::deletePressed()
        QListWidgetItem *cur = databaseLW->takeItem(databaseLW->currentRow());
        if (cur) {
                delete cur;
+               databaseChanged();
                changed();
        }
 }
@@ -243,8 +243,8 @@ void GuiBibtex::deletePressed()
 void GuiBibtex::upPressed()
 {
        int row = databaseLW->currentRow();
-       QListWidgetItem *cur;
-       databaseLW->insertItem(row - 1, cur = databaseLW->takeItem(row));
+       QListWidgetItem *cur = databaseLW->takeItem(row);
+       databaseLW->insertItem(row - 1, cur);
        databaseLW->setCurrentItem(cur);
        changed();
 }
@@ -253,8 +253,8 @@ void GuiBibtex::upPressed()
 void GuiBibtex::downPressed()
 {
        int row = databaseLW->currentRow();
-       QListWidgetItem *cur;
-       databaseLW->insertItem(row + 1, cur = databaseLW->takeItem(row));
+       QListWidgetItem *cur = databaseLW->takeItem(row);
+       databaseLW->insertItem(row + 1, cur);
        databaseLW->setCurrentItem(cur);
        changed();
 }
@@ -262,9 +262,12 @@ void GuiBibtex::downPressed()
 
 void GuiBibtex::databaseChanged()
 {
-       deletePB->setEnabled(!isBufferReadonly() && databaseLW->currentRow() != -1);
-       upPB->setEnabled(!isBufferReadonly() && databaseLW->count() > 1 && databaseLW->currentRow() > 0);
-       downPB->setEnabled(!isBufferReadonly() && databaseLW->count() > 1 && databaseLW->currentRow() < databaseLW->count() - 1);
+       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);
 }
 
 
@@ -274,13 +277,6 @@ void GuiBibtex::availableChanged()
 }
 
 
-void GuiBibtex::closeEvent(QCloseEvent *e)
-{
-       slotClose();
-       e->accept();
-}
-
-
 void GuiBibtex::updateContents()
 {
        bool bibtopic = usingBibtopic();