more cleanup:

- clear selected keys on ok/cancel
 - update info when navigating with keyboard
 - add clear search button
 - don't allow search strings that return empty selection

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16277 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Edwin Leuven 2006-12-15 09:58:44 +00:00
parent a66f7e4029
commit 2c832e6578
6 changed files with 289 additions and 233 deletions

View File

@ -93,14 +93,6 @@ DIALOGS
of LaTeX errors and export to LaTeX afterwards you will get the old error
list again, although the export succeded.
* Citation dialog: Create some citation; open the citation dialog a second time for
another new citation => the selected entry from the first citations is
already selected for the second citation (which is wrong)
* Citation dialog: If you use the cursor up/down keys to browse through the
list of available citations, the "preview" (in the middle of the dialog)
is not updated
MATH CONTROL PANEL

View File

@ -56,7 +56,7 @@ QCitation::QCitation(Dialog & parent)
void QCitation::apply(int const choice, bool const full, bool const force,
QString before, QString after)
{
if (!isValid())
if (selected_keys_.rowCount() == 0)
return;
vector<biblio::CiteStyle> const & styles =
@ -74,6 +74,12 @@ void QCitation::apply(int const choice, bool const full, bool const force,
}
void QCitation::clearSelection()
{
selected_keys_.setStringList(QStringList());
}
QString QCitation::textBefore()
{
return toqstr(params()["before"]);
@ -101,12 +107,6 @@ void QCitation::updateModel()
}
bool QCitation::isValid()
{
return selected_keys_.rowCount() > 0;
}
void QCitation::findKey(QString const & str)
{
QStringList sl = available_keys_.stringList().filter(str, Qt::CaseInsensitive);

View File

@ -43,6 +43,9 @@ public:
/// Get key description
QString getKeyInfo(QString const &);
/// Clear selected keys
void clearSelection();
/// Find keys containing the string (not case-sens)
void findKey(QString const &);
@ -61,9 +64,6 @@ public:
/// List of example cite strings
QStringList citationStyles(int);
/// Check whether there are keys to select
virtual bool isValid();
/// Set the Params variable for the Controller.
virtual void apply(int const choice, bool const full, bool const force,
QString before, QString after);

View File

@ -57,6 +57,14 @@ QCitationDialog::QCitationDialog(Dialog & dialog, QCitation * form)
this, SLOT(changed()));
connect(textAfterED, SIGNAL(textChanged(const QString&)),
this, SLOT(changed()));
connect(clearPB, SIGNAL(clicked()),
findLE, SLOT(clear()));
connect(availableLV->selectionModel(),
SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
this, SLOT(availableChanged(const QModelIndex &, const QModelIndex &)));
connect(selectedLV->selectionModel(),
SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
this, SLOT(selectedChanged(const QModelIndex &, const QModelIndex &)));
}
@ -100,12 +108,14 @@ bool QCitationDialog::isVisible() const
void QCitationDialog::on_okPB_clicked()
{
apply();
form_->clearSelection();
accept();
}
void QCitationDialog::on_cancelPB_clicked()
{
form_->clearSelection();
accept();
}
@ -126,12 +136,12 @@ void QCitationDialog::update()
{
form_->updateModel();
QModelIndex idxa = availableLV->currentIndex();
if (!idxa.isValid())
QModelIndex const idxa = availableLV->currentIndex();
if (form_->available()->rowCount() > 0 && !idxa.isValid())
availableLV->setCurrentIndex(availableLV->model()->index(0,0));
QModelIndex idx = selectedLV->currentIndex();
if (form_->isValid() && !idx.isValid()) {
QModelIndex const idx = selectedLV->currentIndex();
if (form_->selected()->rowCount() > 0 && !idx.isValid()) {
selectedLV->setCurrentIndex(selectedLV->model()->index(0,0));
updateInfo(selectedLV->currentIndex());
} else
@ -158,6 +168,7 @@ void QCitationDialog::updateStyle()
fulllistCB->setEnabled(natbib_engine);
forceuppercaseCB->setEnabled(natbib_engine);
textBeforeED->setEnabled(!basic_engine);
textBeforeLA->setEnabled(!basic_engine);
string const & command = form_->params().getCmdName();
@ -200,10 +211,12 @@ void QCitationDialog::fillStyles()
return;
}
if (selectedLV->selectionModel()->selectedIndexes().empty())
int curr = selectedLV->model()->rowCount() - 1;
if (curr < 0)
return;
int curr = selectedLV->selectionModel()->selectedIndexes()[0].row();//selectedLV->currentItem();
if (!selectedLV->selectionModel()->selectedIndexes().empty())
curr = selectedLV->selectionModel()->selectedIndexes()[0].row();
QStringList sty = form_->citationStyles(curr);
@ -213,6 +226,9 @@ void QCitationDialog::fillStyles()
citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine);
citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine);
if (sty.isEmpty() || basic_engine)
return;
citationStyleCO->insertItems(0, sty);
if (orig != -1 && orig < citationStyleCO->count())
@ -254,12 +270,37 @@ void QCitationDialog::updateInfo(const QModelIndex & idx)
void QCitationDialog::on_selectedLV_clicked(const QModelIndex & idx)
{
availableLV->selectionModel()->clear();
updateInfo(idx);
changed();
}
void QCitationDialog::selectedChanged(const QModelIndex & idx, const QModelIndex &)
{
if (!idx.isValid())
return;
updateInfo(idx);
changed();
}
void QCitationDialog::on_availableLV_clicked(const QModelIndex & idx)
{
selectedLV->selectionModel()->clear();
updateInfo(idx);
setButtons();
}
void QCitationDialog::availableChanged(const QModelIndex & idx, const QModelIndex &)
{
if (!idx.isValid())
return;
updateInfo(idx);
setButtons();
}
@ -322,7 +363,15 @@ void QCitationDialog::on_downPB_clicked()
void QCitationDialog::on_findLE_textChanged(const QString & text)
{
clearPB->setDisabled(text.isEmpty());
if (text.isEmpty())
findLE->setFocus();
form_->findKey(text);
if (form_->found()->rowCount() == 0) {
findLE->backspace();
return;
}
availableLV->setModel(form_->found());
changed();
}

View File

@ -57,8 +57,10 @@ protected Q_SLOTS:
void on_downPB_clicked();
void on_findLE_textChanged(const QString & text);
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 availableChanged(const QModelIndex &, const QModelIndex &);
virtual void changed();
/// check whether key is already selected
bool isSelected(const QModelIndex &);

View File

@ -26,14 +26,230 @@
<property name="sizeGripEnabled" >
<bool>true</bool>
</property>
<layout class="QVBoxLayout" >
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<item row="1" column="0" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="findKeysLA" >
<property name="text" >
<string>&amp;Find:</string>
</property>
<property name="alignment" >
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="buddy" >
<cstring>selectedLV</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="findLE" >
<property name="text" >
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearPB" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>&lt;- Clear</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="restorePB" >
<property name="text" >
<string>&amp;Restore</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB" >
<property name="text" >
<string>&amp;OK</string>
</property>
<property name="autoDefault" >
<bool>true</bool>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applyPB" >
<property name="text" >
<string>A&amp;pply</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelPB" >
<property name="text" >
<string>&amp;Cancel</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0" >
<widget class="QGroupBox" name="styleGB" >
<property name="title" >
<string>Formatting</string>
</property>
<property name="flat" >
<bool>true</bool>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="1" colspan="2" >
<widget class="QComboBox" name="citationStyleCO" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Natbib citation style to use</string>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="citationStyleLA" >
<property name="text" >
<string>Citation &amp;style:</string>
</property>
<property name="buddy" >
<cstring>citationStyleCO</cstring>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2" >
<widget class="QCheckBox" name="fulllistCB" >
<property name="toolTip" >
<string>List all authors</string>
</property>
<property name="text" >
<string>&amp;Full author list</string>
</property>
</widget>
</item>
<item row="3" column="2" >
<widget class="QCheckBox" name="forceuppercaseCB" >
<property name="toolTip" >
<string>Force upper case in citation</string>
</property>
<property name="text" >
<string>Force &amp;upper case</string>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="textAfterLA" >
<property name="text" >
<string>&amp;Text after:</string>
</property>
<property name="buddy" >
<cstring>textAfterED</cstring>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2" >
<widget class="QLineEdit" name="textAfterED" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Text to place after citation</string>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="textBeforeLA" >
<property name="text" >
<string>Text &amp;before:</string>
</property>
<property name="buddy" >
<cstring>textAfterED</cstring>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2" >
<widget class="QLineEdit" name="textBeforeED" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Text to place before citation</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0" >
<widget class="QTextBrowser" name="infoML" />
</item>
<item row="0" column="0" >
<layout class="QGridLayout" >
<property name="margin" >
<number>0</number>
@ -152,215 +368,9 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="findKeysLA" >
<property name="text" >
<string>&amp;Find:</string>
</property>
<property name="alignment" >
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="buddy" >
<cstring>selectedLV</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="findLE" >
<property name="text" >
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTextBrowser" name="infoML" />
</item>
<item>
<widget class="QGroupBox" name="styleGB" >
<property name="title" >
<string>Formatting</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="1" colspan="2" >
<widget class="QComboBox" name="citationStyleCO" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Natbib citation style to use</string>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="citationStyleLA" >
<property name="text" >
<string>Citation &amp;style:</string>
</property>
<property name="buddy" >
<cstring>citationStyleCO</cstring>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2" >
<widget class="QCheckBox" name="fulllistCB" >
<property name="toolTip" >
<string>List all authors</string>
</property>
<property name="text" >
<string>&amp;Full author list</string>
</property>
</widget>
</item>
<item row="3" column="2" >
<widget class="QCheckBox" name="forceuppercaseCB" >
<property name="toolTip" >
<string>Force upper case in citation</string>
</property>
<property name="text" >
<string>Force &amp;upper case</string>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="textAfterLA" >
<property name="text" >
<string>&amp;Text after:</string>
</property>
<property name="buddy" >
<cstring>textAfterED</cstring>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2" >
<widget class="QLineEdit" name="textAfterED" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Text to place after citation</string>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="textBeforeLA" >
<property name="text" >
<string>Text &amp;before:</string>
</property>
<property name="buddy" >
<cstring>textAfterED</cstring>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2" >
<widget class="QLineEdit" name="textBeforeED" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Text to place before citation</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="restorePB" >
<property name="text" >
<string>&amp;Restore</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB" >
<property name="text" >
<string>&amp;OK</string>
</property>
<property name="autoDefault" >
<bool>true</bool>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applyPB" >
<property name="text" >
<string>A&amp;pply</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelPB" >
<property name="text" >
<string>&amp;Cancel</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<pixmapfunction></pixmapfunction>
<includes>
<include location="local" >qt_helpers.h</include>
</includes>
<tabstops>
<tabstop>availableLV</tabstop>
<tabstop>selectedLV</tabstop>
@ -380,6 +390,9 @@
<tabstop>applyPB</tabstop>
<tabstop>cancelPB</tabstop>
</tabstops>
<includes>
<include location="local" >qt_helpers.h</include>
</includes>
<resources/>
<connections/>
</ui>