mirror of
https://github.com/MultiMC/MultiMC5.git
synced 2024-12-28 06:18:06 +00:00
Remember the last selected instance and select it on startup
This commit is contained in:
parent
eff38858ef
commit
8831856172
@ -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", ""));
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -362,7 +362,7 @@ int InstanceList::add(InstancePtr t)
|
||||
return count() - 1;
|
||||
}
|
||||
|
||||
InstancePtr InstanceList::getInstanceById(QString instId)
|
||||
InstancePtr InstanceList::getInstanceById(QString instId) const
|
||||
{
|
||||
QListIterator<InstancePtr> 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++)
|
||||
{
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user