summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSky <git@bunnies.cc>2014-01-07 05:02:35 -0800
committerSky <git@bunnies.cc>2014-01-07 05:02:35 -0800
commit28cb66e85cad786f08b40cf242cb17a70d9e7432 (patch)
tree5c35d1aaf52e28350a64bd7cc228e05169e7d211
parent7773e771509935183a99e42ee61314431dd3f478 (diff)
parent093143cfef8959261fc4f66a65d2ecc4cdc2e23c (diff)
downloadMultiMC-28cb66e85cad786f08b40cf242cb17a70d9e7432.tar
MultiMC-28cb66e85cad786f08b40cf242cb17a70d9e7432.tar.gz
MultiMC-28cb66e85cad786f08b40cf242cb17a70d9e7432.tar.lz
MultiMC-28cb66e85cad786f08b40cf242cb17a70d9e7432.tar.xz
MultiMC-28cb66e85cad786f08b40cf242cb17a70d9e7432.zip
Merge pull request #35 from 02JanDal/fix_keep_selection
Fix instances getting deselected after FTB instances are loaded (or when ever the model is reset, like on a reload)
-rw-r--r--gui/MainWindow.cpp37
-rw-r--r--gui/MainWindow.h2
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 &current, 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;