diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2020-11-07 20:09:16 -0500 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2020-11-07 20:16:28 -0500 |
| commit | f9feb5fc5b4dc2834827862131035c2c8894f879 (patch) | |
| tree | a92fb9cfceaef4f92a539ed0f66aea4c462e87e7 /src | |
| parent | a28aeb2b1871b5626dedfaedafcdb3102eaeea5d (diff) | |
show a confirmation before switching instances
Diffstat (limited to 'src')
| -rw-r--r-- | src/instancemanagerdialog.cpp | 42 | ||||
| -rw-r--r-- | src/instancemanagerdialog.h | 5 |
2 files changed, 44 insertions, 3 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(); diff --git a/src/instancemanagerdialog.h b/src/instancemanagerdialog.h index 2641f716..86fe0dac 100644 --- a/src/instancemanagerdialog.h +++ b/src/instancemanagerdialog.h @@ -38,7 +38,6 @@ public: // void openSelectedInstance(); - // renames the currently selected instance // void rename(); @@ -110,6 +109,10 @@ private: // void createNew(); + // shows a confirmation to the user before switching + // + bool confirmSwitch(const Instance& to); + // returns the index of selected instance, NoSelection if none // |
