diff --git a/MultiMC.cpp b/MultiMC.cpp index 26d7e8c8..1ac84629 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -327,6 +327,7 @@ void MultiMC::initGlobalSettings() m_settings->registerSetting(new Setting("InstSortMode", "Name")); + m_settings->registerSetting(new Setting("SelectedInstance", QString())); // Persistent value for the client ID m_settings->registerSetting(new Setting("YggdrasilClientToken", "")); diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index cb81958b..a3394a82 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -244,6 +244,28 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi connect(assets_downloader, SIGNAL(finished()), SLOT(assetsFinished())); assets_downloader->start(); } + + 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)); + } + + // removing this looks stupid + view->setFocus(); } MainWindow::~MainWindow() @@ -983,10 +1005,14 @@ void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex & m_statusLeft->setText(m_selectedInstance->getStatusbarDescription()); auto ico = MMC->icons()->getIcon(iconKey); ui->actionChangeInstIcon->setIcon(ico); + + MMC->settings()->set("SelectedInstance", m_selectedInstance->id()); } else { selectionBad(); + + MMC->settings()->set("SelectedInstance", QString()); } } diff --git a/logic/lists/InstanceList.cpp b/logic/lists/InstanceList.cpp index 7081dc6f..200b02df 100644 --- a/logic/lists/InstanceList.cpp +++ b/logic/lists/InstanceList.cpp @@ -362,7 +362,7 @@ int InstanceList::add(InstancePtr t) return count() - 1; } -InstancePtr InstanceList::getInstanceById(QString instId) +InstancePtr InstanceList::getInstanceById(QString instId) const { QListIterator iter(m_instances); InstancePtr inst; @@ -378,7 +378,12 @@ InstancePtr InstanceList::getInstanceById(QString instId) return iter.peekPrevious(); } -int InstanceList::getInstIndex(BaseInstance *inst) +QModelIndex InstanceList::getInstanceIndexById(const QString &id) const +{ + return index(getInstIndex(getInstanceById(id).get())); +} + +int InstanceList::getInstIndex(BaseInstance *inst) const { for (int i = 0; i < m_instances.count(); i++) { diff --git a/logic/lists/InstanceList.h b/logic/lists/InstanceList.h index d08501eb..8cd39746 100644 --- a/logic/lists/InstanceList.h +++ b/logic/lists/InstanceList.h @@ -91,7 +91,9 @@ public: int add(InstancePtr t); /// Get an instance by ID - InstancePtr getInstanceById(QString id); + InstancePtr getInstanceById(QString id) const; + + QModelIndex getInstanceIndexById(const QString &id) const; signals: void dataIsInvalid(); @@ -106,7 +108,7 @@ slots: void groupChanged(); private: - int getInstIndex(BaseInstance *inst); + int getInstIndex(BaseInstance *inst) const; protected: QString m_instDir;