summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--MultiMC.cpp1
-rw-r--r--gui/MainWindow.cpp26
-rw-r--r--logic/lists/InstanceList.cpp14
-rw-r--r--logic/lists/InstanceList.h6
4 files changed, 43 insertions, 4 deletions
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 &current, 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..72748b5f 100644
--- a/logic/lists/InstanceList.cpp
+++ b/logic/lists/InstanceList.cpp
@@ -362,8 +362,13 @@ int InstanceList::add(InstancePtr t)
return count() - 1;
}
-InstancePtr InstanceList::getInstanceById(QString instId)
+InstancePtr InstanceList::getInstanceById(QString instId) const
{
+ if (m_instances.isEmpty())
+ {
+ return InstancePtr();
+ }
+
QListIterator<InstancePtr> iter(m_instances);
InstancePtr inst;
while (iter.hasNext())
@@ -378,7 +383,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;