summaryrefslogtreecommitdiff
path: root/src/instancemanagerdialog.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2020-11-07 20:09:16 -0500
committerisanae <14251494+isanae@users.noreply.github.com>2020-11-07 20:16:28 -0500
commitf9feb5fc5b4dc2834827862131035c2c8894f879 (patch)
treea92fb9cfceaef4f92a539ed0f66aea4c462e87e7 /src/instancemanagerdialog.cpp
parenta28aeb2b1871b5626dedfaedafcdb3102eaeea5d (diff)
show a confirmation before switching instances
Diffstat (limited to 'src/instancemanagerdialog.cpp')
-rw-r--r--src/instancemanagerdialog.cpp42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/instancemanagerdialog.cpp b/src/instancemanagerdialog.cpp
index d579ea9c..b461d39d 100644
--- a/src/instancemanagerdialog.cpp
+++ b/src/instancemanagerdialog.cpp
@@ -294,10 +294,16 @@ void InstanceManagerDialog::openSelectedInstance()
return;
}
- if (m_instances[i]->isPortable()) {
+ const auto& to = *m_instances[i];
+
+ if (!confirmSwitch(to)) {
+ return;
+ }
+
+ if (to.isPortable()) {
InstanceManager::singleton().setCurrentInstance("");
} else {
- InstanceManager::singleton().setCurrentInstance(m_instances[i]->name());
+ InstanceManager::singleton().setCurrentInstance(to.name());
}
if (m_restartOnSelect) {
@@ -307,6 +313,38 @@ void InstanceManagerDialog::openSelectedInstance()
accept();
}
+bool InstanceManagerDialog::confirmSwitch(const Instance& to)
+{
+ // there might not be a global Settings object if this is called on startup
+ // when there's no current instance
+ const auto* s = Settings::maybeInstance();
+
+ // if there is are no settings, no instances are loaded and the confirmation
+ // wouldn't make sense
+ if (!s) {
+ return true;
+ }
+
+ if (!s->interface().showChangeGameConfirmation()) {
+ // user disabled confirmation
+ return true;
+ }
+
+ MOBase::TaskDialog dlg(this);
+
+ const auto r = dlg
+ .title(tr("Switching instances"))
+ .main(tr("Mod Organizer must restart to manage the instance '%1'.")
+ .arg(to.name()))
+ .content(tr("This confirmation can be disabled in the settings."))
+ .icon(QMessageBox::Question)
+ .button({tr("Restart Mod Organizer"), QMessageBox::Ok})
+ .button({tr("Cancel"), QMessageBox::Cancel})
+ .exec();
+
+ return (r == QMessageBox::Ok);
+}
+
void InstanceManagerDialog::rename()
{
auto* i = singleSelection();