From cd7b409c1045bfc42961467d2250ad6b7c9f007c Mon Sep 17 00:00:00 2001 From: Tom Tanner Date: Sat, 5 Sep 2015 17:18:37 +0100 Subject: Weren't getting warned if you changed an executable then selected another This fixes that and also redisplays the newly selected item properly --- src/editexecutablesdialog.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/editexecutablesdialog.cpp') diff --git a/src/editexecutablesdialog.cpp b/src/editexecutablesdialog.cpp index 73fb1d03..b9d548a6 100644 --- a/src/editexecutablesdialog.cpp +++ b/src/editexecutablesdialog.cpp @@ -111,10 +111,10 @@ void EditExecutablesDialog::saveExecutable() void EditExecutablesDialog::delayedRefresh() { - int index = ui->executablesListBox->currentIndex().row(); + QModelIndex index = ui->executablesListBox->currentIndex(); resetInput(); refreshExecutablesWidget(); - ui->executablesListBox->setCurrentRow(index); + on_executablesListBox_clicked(index); } @@ -263,24 +263,26 @@ void EditExecutablesDialog::on_closeButton_clicked() void EditExecutablesDialog::on_executablesListBox_clicked(const QModelIndex ¤t) { if (current.isValid()) { - ui->executablesListBox->selectionModel()->clearSelection(); - ui->executablesListBox->selectionModel()->select(current, QItemSelectionModel::SelectCurrent); if (executableChanged()) { QMessageBox::StandardButton res = QMessageBox::question(this, tr("Save Changes?"), tr("You made changes to the current executable, do you want to save them?"), - QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); - if (res == QMessageBox::Cancel) { - return; - } else if (res == QMessageBox::Yes) { - // this invalidates the item passed as a a parameter + QMessageBox::Yes | QMessageBox::No); + if (res == QMessageBox::Yes) { saveExecutable(); + //This is necessary if we're adding a new item, but it doesn't look very nice. + //Ideally we'd end up with the correct row displayed + ui->executablesListBox->selectionModel()->clearSelection(); + ui->executablesListBox->selectionModel()->select(current, QItemSelectionModel::SelectCurrent); QTimer::singleShot(50, this, SLOT(delayedRefresh())); return; } } + ui->executablesListBox->selectionModel()->clearSelection(); + ui->executablesListBox->selectionModel()->select(current, QItemSelectionModel::SelectCurrent); + m_CurrentItem = ui->executablesListBox->item(current.row()); Executable const &selectedExecutable(m_ExecutablesList.find(m_CurrentItem->text())); -- cgit v1.3.1