The attached patch addresses these bugs
http://bugzilla.lyx.org/show_bug.cgi?id=3741
http://bugzilla.lyx.org/show_bug.cgi?id=3756
in a way that is compatible with earlier discussion with Abdel and now
with some improvements due to Lars and Andre. Here's what it does:
* In the "Available" list, double clicking or hitting Enter adds a
citation. Hitting Ctrl-Enter adds the citation and closes the
dialog. Previously, Enter did what Ctrl-Enter now does if there
was no other citation already selected and double clicking would
close the dialog after adding the citation.
* In the "Selected" list, Delete and Backspace delete the
selection.
Ctrl-Delete and Ctrl-Backspace clear the whole list.
Now seeking to commit.
Richard
--
==================================================================
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==================================================================
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto
Index: QCitationDialog.h
===================================================================
--- QCitationDialog.h (revision 18626)
+++ QCitationDialog.h (working copy)
@@ -48,14 +48,16 @@
/// \return true if the dialog is visible.
bool isVisible() const;
+
+ ///
+ bool eventFilter(QObject *, QEvent *);
protected:
void closeEvent (QCloseEvent * e);
- void keyPressEvent (QKeyEvent * event);
void findText(QString const & text);
protected Q_SLOTS:
-
+ void cleanUp();
void on_okPB_clicked();
void on_cancelPB_clicked();
void on_restorePB_clicked();
@@ -70,7 +72,7 @@
void on_selectedLV_clicked(const QModelIndex &);
void selectedChanged(const QModelIndex &, const QModelIndex &);
void on_availableLV_clicked(const QModelIndex &);
- void on_availableLV_activated(const QModelIndex &);
+ void on_availableLV_doubleClicked(const QModelIndex &);
void on_availableLV_entered(const QModelIndex &);
void availableChanged(const QModelIndex &, const QModelIndex &);
virtual void changed();
@@ -88,14 +90,13 @@
/// set the styles combo
void updateStyle();
-
+
/// last used citation style
int style_;
-
+
QCitation * form_;
};
-
} // namespace frontend
} // namespace lyx
Index: QCitationDialog.cpp
===================================================================
--- QCitationDialog.cpp (revision 18626)
+++ QCitationDialog.cpp (working copy)
@@ -65,6 +65,9 @@
connect(selectedLV->selectionModel(),
SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
this, SLOT(selectedChanged(const QModelIndex &, const QModelIndex &)));
+ connect(this, SIGNAL(rejected()), this, SLOT(cleanUp()));
+ availableLV->installEventFilter(this);
+ selectedLV->installEventFilter(this);
}
@@ -73,18 +76,68 @@
}
-void QCitationDialog::keyPressEvent(QKeyEvent * event)
+bool QCitationDialog::eventFilter(QObject * obj, QEvent * event)
{
- if (event->key() == Qt::Key_Escape) {
- form_->clearSelection();
- form_->clearParams();
- event->accept();
- close();
- } else
- event->ignore();
+ if (obj == availableLV) {
+ if (event->type() != QEvent::KeyPress)
+ return QObject::eventFilter(obj, event);
+ QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
+ int const keyPressed = keyEvent->key();
+ Qt::KeyboardModifiers const keyModifiers = keyEvent->modifiers();
+ //Enter key without modifier will add current item.
+ //Ctrl-Enter will add it and close the dialog.
+ //This is designed to work both with the main enter key
+ //and the one on the numeric keypad.
+ if ((keyPressed == Qt::Key_Enter || keyPressed == Qt::Key_Return) &&
+ //We want one or both of Control and Keypad, and nothing else
+ //(KeypadModifier is what you get if you use the Enter key on the
+ //numeric keypad.)
+ (!keyModifiers ||
+ (keyModifiers == Qt::ControlModifier) ||
+ (keyModifiers == Qt::KeypadModifier) ||
+ (keyModifiers == (Qt::ControlModifier | Qt::KeypadModifier))
+ )
+ ) {
+ if (addPB->isEnabled())
+ on_addPB_clicked();
+ if (keyModifiers & Qt::ControlModifier)
+ on_okPB_clicked();
+ event->accept();
+ return true;
+ }
+ } else if (obj == selectedLV) {
+ //Delete or backspace key will delete current item
+ //...with control modifier will clear the list
+ if (event->type() != QEvent::KeyPress)
+ return QObject::eventFilter(obj, event);
+ QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
+ int const keyPressed = keyEvent->key();
+ Qt::KeyboardModifiers const keyModifiers = keyEvent->modifiers();
+ if (keyPressed == Qt::Key_Delete || keyPressed == Qt::Key_Backspace) {
+ if (keyModifiers == Qt::NoModifier && deletePB->isEnabled())
+ on_deletePB_clicked();
+ else if (keyModifiers == Qt::ControlModifier) {
+ form_->clearSelection();
+ update();
+ } else
+ //ignore it otherwise
+ return QObject::eventFilter(obj, event);
+ event->accept();
+ return true;
+ }
+ }
+ return QObject::eventFilter(obj, event);
}
+void QCitationDialog::cleanUp()
+{
+ form_->clearSelection();
+ form_->clearParams();
+ close();
+}
+
+
void QCitationDialog::closeEvent(QCloseEvent * e)
{
form_->clearSelection();
@@ -323,15 +376,13 @@
}
-void QCitationDialog::on_availableLV_activated(const QModelIndex & idx)
+void QCitationDialog::on_availableLV_doubleClicked(const QModelIndex & idx)
{
if (isSelected(idx))
return;
selectedLV->selectionModel()->reset();
on_addPB_clicked();
- if (selectedLV->model()->rowCount() == 1)
- on_okPB_clicked();
}
@@ -340,10 +391,26 @@
}
+namespace {
+//helper function for next two
+QModelIndex getSelectedIndex(QListView * lv) {
+ QModelIndexList selIdx =
+ lv->selectionModel()->selectedIndexes();
+ if (selIdx.empty())
+ return QModelIndex();
+ else
+ return selIdx.first();
+}
+}//anonymous namespace
+
+
void QCitationDialog::on_addPB_clicked()
{
+ QModelIndex const idxToAdd = getSelectedIndex(availableLV);
+ if (!idxToAdd.isValid())
+ return;
QModelIndex idx = selectedLV->currentIndex();
- form_->addKey(availableLV->currentIndex());
+ form_->addKey(idxToAdd);
if (idx.isValid())
selectedLV->setCurrentIndex(idx);
selectedLV->selectionModel()->reset();
@@ -353,7 +420,9 @@
void QCitationDialog::on_deletePB_clicked()
{
- QModelIndex idx = selectedLV->currentIndex();
+ QModelIndex idx = getSelectedIndex(selectedLV);
+ if (!idx.isValid())
+ return;
int nrows = selectedLV->model()->rowCount();
form_->deleteKey(idx);