From dc2ada2a4249917f538938298deb193ed1dd6bb9 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Fri, 6 Nov 2020 13:56:04 -0500 Subject: added ... to the "Delete Instance" button to make it less scary merged InstanceInfo into Instance, most of it was redundant added logging before deleting instance added Instance::readFromIni(), contains stuff that used to be in setup(), used by instance dialog replaced QDir with QString in a few places, I hate QDir --- src/instancemanagerdialog.h | 80 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 7 deletions(-) (limited to 'src/instancemanagerdialog.h') diff --git a/src/instancemanagerdialog.h b/src/instancemanagerdialog.h index 5b08ffc2..94f379ca 100644 --- a/src/instancemanagerdialog.h +++ b/src/instancemanagerdialog.h @@ -6,9 +6,11 @@ namespace Ui { class InstanceManagerDialog; }; -class InstanceInfo; +class Instance; class PluginContainer; +// a dialog to manage existing instances +// class InstanceManagerDialog : public QDialog { Q_OBJECT @@ -19,21 +21,61 @@ public: ~InstanceManagerDialog(); + // selects the instance having the given index in the list + // void select(std::size_t i); + + // selects the instance by name + // void select(const QString& name); + + // select the instance that is currently in use in MO + // void selectActiveInstance(); + + // switches to the selected instance; restarts MO, unless + // was called setRestartOnSelect(false) + // void openSelectedInstance(); + + // renames the currently selected instance + // void rename(); + + // explores the directory of the selected instance + // void exploreLocation(); + + // explores the base directory of the selected instance + // void exploreBaseDirectory(); + + // explores the game directory of the selected instance + // void exploreGame(); + + // converts the selected, portable instance to a global one; not implemented + // void convertToGlobal(); + + // converts the selected, global instance to a portable one; not implemented + // void convertToPortable(); + + // opens the ini of the selected instance in the shell + // void openINI(); + + // deletes the selected instance + // void deleteInstance(); + + // sets whether the dialog should restart MO when selecting an instance; this + // is false on startup when no instances exist + // void setRestartOnSelect(bool b); private: @@ -41,27 +83,51 @@ private: std::unique_ptr ui; const PluginContainer& m_pc; - std::vector> m_instances; + std::vector> m_instances; MOBase::FilterWidget m_filter; QStandardItemModel* m_model; bool m_restartOnSelect; + // refreshes the list instances from disk + // void updateInstances(); + // updates the ui for the selected instance + // void onSelection(); + + // opens the create instance dialog + // void createNew(); + + // returns the index of selected instance, NoSelection if none + // std::size_t singleSelectionIndex() const; - InstanceInfo* singleSelection(); - const InstanceInfo* singleSelection() const; + // returns the InstanceInfo associated with the selected instance, null if + // none + // + const Instance* singleSelection() const; + + // fills the instance list on the ui + // void updateList(); - void fillData(const InstanceInfo& ii); + + // fills the ui for the selected instance + // + void fillData(const Instance& ii); + + // clears the ui when there's no selection + // void clearData(); + + // enables/disables buttons like rename, explore... + // void setButtonsEnabled(bool b); - bool deletePortable(const InstanceInfo& ii); - bool deleteGlobal(const InstanceInfo& ii); + // deletes the given files, returns false on error + // bool doDelete(const QStringList& files, bool recycle); }; -- cgit v1.3.1 From 0b8fbfdc57ad22c996fa88f6d974269afec004fd Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 7 Nov 2020 19:43:11 -0500 Subject: larger initial size for the instance dialog save geometry if settings are available --- src/instancemanagerdialog.cpp | 28 +++++++++++++++++++++++++++- src/instancemanagerdialog.h | 10 ++++++++++ src/instancemanagerdialog.ui | 4 ++-- src/settings.cpp | 8 +++++++- src/settings.h | 10 +++++++++- 5 files changed, 55 insertions(+), 5 deletions(-) (limited to 'src/instancemanagerdialog.h') diff --git a/src/instancemanagerdialog.cpp b/src/instancemanagerdialog.cpp index 71fed78d..d579ea9c 100644 --- a/src/instancemanagerdialog.cpp +++ b/src/instancemanagerdialog.cpp @@ -111,7 +111,7 @@ InstanceManagerDialog::InstanceManagerDialog( { ui->setupUi(this); - ui->splitter->setSizes({200, 1}); + ui->splitter->setSizes({250, 1}); ui->splitter->setStretchFactor(0, 0); ui->splitter->setStretchFactor(1, 1); @@ -146,6 +146,32 @@ InstanceManagerDialog::InstanceManagerDialog( connect(ui->close, &QPushButton::clicked, [&]{ close(); }); } +void InstanceManagerDialog::showEvent(QShowEvent* e) +{ + // 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 (s) { + s->geometry().restoreGeometry(this); + } + + QDialog::showEvent(e); +} + +void InstanceManagerDialog::done(int r) +{ + // there might not be a global Settings object if this is called on startup + // when there's no current instance + auto* s = Settings::maybeInstance(); + + if (s) { + s->geometry().saveGeometry(this); + } + + QDialog::done(r); +} + void InstanceManagerDialog::updateInstances() { auto& m = InstanceManager::singleton(); diff --git a/src/instancemanagerdialog.h b/src/instancemanagerdialog.h index 94f379ca..2641f716 100644 --- a/src/instancemanagerdialog.h +++ b/src/instancemanagerdialog.h @@ -78,6 +78,16 @@ public: // void setRestartOnSelect(bool b); + + // saves geometry + // + void done(int r) override; + +protected: + // restores geometry + // + void showEvent(QShowEvent* e) override; + private: static const std::size_t NoSelection = -1; diff --git a/src/instancemanagerdialog.ui b/src/instancemanagerdialog.ui index 45b99e21..4137d1b6 100644 --- a/src/instancemanagerdialog.ui +++ b/src/instancemanagerdialog.ui @@ -6,8 +6,8 @@ 0 0 - 689 - 413 + 884 + 539 diff --git a/src/settings.cpp b/src/settings.cpp index a8ada6ba..54d32786 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -86,14 +86,20 @@ Settings::~Settings() } } -Settings &Settings::instance() +Settings& Settings::instance() { if (s_Instance == nullptr) { throw std::runtime_error("no instance of \"Settings\""); } + return *s_Instance; } +Settings* Settings::maybeInstance() +{ + return s_Instance; +} + void Settings::processUpdates( const QVersionNumber& currentVersion, const QVersionNumber& lastVersion) { diff --git a/src/settings.h b/src/settings.h index df081c5c..689067d7 100644 --- a/src/settings.h +++ b/src/settings.h @@ -693,7 +693,15 @@ public: Settings(const QString& path, bool globalInstance=false); ~Settings(); - static Settings &instance(); + + // throws if there is no global Settings instance + // + static Settings& instance(); + + // returns null if there is no global Settings instance + // + static Settings* maybeInstance(); + // name of the ini file // -- cgit v1.3.1 From f9feb5fc5b4dc2834827862131035c2c8894f879 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 7 Nov 2020 20:09:16 -0500 Subject: show a confirmation before switching instances --- src/instancemanagerdialog.cpp | 42 ++++++++++++++++++++++++++++++++++++++++-- src/instancemanagerdialog.h | 5 ++++- 2 files changed, 44 insertions(+), 3 deletions(-) (limited to 'src/instancemanagerdialog.h') 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 // -- cgit v1.3.1