diff options
Diffstat (limited to 'gui')
-rw-r--r-- | gui/MainWindow.cpp | 37 | ||||
-rw-r--r-- | gui/MainWindow.h | 2 |
2 files changed, 21 insertions, 18 deletions
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 968fecb7..905d14cf 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -289,24 +289,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi this, &MainWindow::notificationsChanged); } - const QString currentInstanceId = MMC->settings()->get("SelectedInstance").toString(); - if (!currentInstanceId.isNull()) - { - const QModelIndex index = MMC->instances()->getInstanceIndexById(currentInstanceId); - if (index.isValid()) - { - const QModelIndex mappedIndex = proxymodel->mapFromSource(index); - view->setCurrentIndex(mappedIndex); - } - else - { - view->setCurrentIndex(proxymodel->index(0, 0)); - } - } - else - { - view->setCurrentIndex(proxymodel->index(0, 0)); - } + setSelectedInstanceById(MMC->settings()->get("SelectedInstance").toString()); // removing this looks stupid view->setFocus(); @@ -788,6 +771,20 @@ void MainWindow::updateInstanceToolIcon(QString new_icon) ui->actionChangeInstIcon->setIcon(MMC->icons()->getIcon(m_currentInstIcon)); } +void MainWindow::setSelectedInstanceById(const QString &id) +{ + QModelIndex selectionIndex = proxymodel->index(0, 0); + if (!id.isNull()) + { + const QModelIndex index = MMC->instances()->getInstanceIndexById(id); + if (index.isValid()) + { + selectionIndex = proxymodel->mapFromSource(index); + } + } + view->selectionModel()->setCurrentIndex(selectionIndex, QItemSelectionModel::ClearAndSelect); +} + void MainWindow::on_actionChangeInstGroup_triggered() { if (!m_selectedInstance) @@ -1274,12 +1271,16 @@ void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex & void MainWindow::selectionBad() { + // start by reseting everything... m_selectedInstance = nullptr; statusBar()->clearMessage(); ui->instanceToolBar->setEnabled(false); renameButton->setText(tr("Rename Instance")); updateInstanceToolIcon("infinity"); + + // ...and then see if we can enable the previously selected instance + setSelectedInstanceById(MMC->settings()->get("SelectedInstance").toString()); } void MainWindow::on_actionEditInstNotes_triggered() diff --git a/gui/MainWindow.h b/gui/MainWindow.h index af2f1dca..12d76da4 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -179,6 +179,8 @@ protected: void setCatBackground(bool enabled); void updateInstanceToolIcon(QString new_icon); + void setSelectedInstanceById(const QString &id); + private: Ui::MainWindow *ui; KCategoryDrawer *drawer; |