refactor: abstract away update confirmation dialog
... so that we can avoid code duplication. Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
9e17ff884f
commit
08d008a5aa
@ -18,6 +18,29 @@ InstanceNameChange askForChangingInstanceName(QWidget* parent, const QString& ol
|
|||||||
return InstanceNameChange::ShouldKeep;
|
return InstanceNameChange::ShouldKeep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ShouldUpdate askIfShouldUpdate(QWidget *parent, QString original_version_name)
|
||||||
|
{
|
||||||
|
auto info = CustomMessageBox::selectable(
|
||||||
|
parent, QObject::tr("Similar modpack was found!"),
|
||||||
|
QObject::tr("One or more of your instances are from this same modpack%1. Do you want to create a "
|
||||||
|
"separate instance, or update the existing one?\n\nNOTE: Make sure you made a backup of your important instance data before "
|
||||||
|
"updating, as worlds can be corrupted and some configuration may be lost (due to pack overrides).")
|
||||||
|
.arg(original_version_name),
|
||||||
|
QMessageBox::Information, QMessageBox::Ok | QMessageBox::Reset | QMessageBox::Abort);
|
||||||
|
info->setButtonText(QMessageBox::Ok, QObject::tr("Update existing instance"));
|
||||||
|
info->setButtonText(QMessageBox::Abort, QObject::tr("Create new instance"));
|
||||||
|
info->setButtonText(QMessageBox::Reset, QObject::tr("Cancel"));
|
||||||
|
|
||||||
|
info->exec();
|
||||||
|
|
||||||
|
if (info->clickedButton() == info->button(QMessageBox::Ok))
|
||||||
|
return ShouldUpdate::Update;
|
||||||
|
if (info->clickedButton() == info->button(QMessageBox::Abort))
|
||||||
|
return ShouldUpdate::SkipUpdating;
|
||||||
|
return ShouldUpdate::Cancel;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
QString InstanceName::name() const
|
QString InstanceName::name() const
|
||||||
{
|
{
|
||||||
if (!m_modified_name.isEmpty())
|
if (!m_modified_name.isEmpty())
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
/* Helpers */
|
/* Helpers */
|
||||||
enum class InstanceNameChange { ShouldChange, ShouldKeep };
|
enum class InstanceNameChange { ShouldChange, ShouldKeep };
|
||||||
[[nodiscard]] InstanceNameChange askForChangingInstanceName(QWidget* parent, const QString& old_name, const QString& new_name);
|
[[nodiscard]] InstanceNameChange askForChangingInstanceName(QWidget* parent, const QString& old_name, const QString& new_name);
|
||||||
|
enum class ShouldUpdate { Update, SkipUpdating, Cancel };
|
||||||
|
[[nodiscard]] ShouldUpdate askIfShouldUpdate(QWidget* parent, QString original_version_name);
|
||||||
|
|
||||||
struct InstanceName {
|
struct InstanceName {
|
||||||
public:
|
public:
|
||||||
|
@ -102,23 +102,10 @@ bool FlameCreationTask::updateInstance()
|
|||||||
auto version_id = inst->getManagedPackVersionName();
|
auto version_id = inst->getManagedPackVersionName();
|
||||||
auto version_str = !version_id.isEmpty() ? tr(" (version %1)").arg(version_id) : "";
|
auto version_str = !version_id.isEmpty() ? tr(" (version %1)").arg(version_id) : "";
|
||||||
|
|
||||||
auto info = CustomMessageBox::selectable(
|
auto should_update = askIfShouldUpdate(m_parent, version_str);
|
||||||
m_parent, tr("Similar modpack was found!"),
|
if (should_update == ShouldUpdate::SkipUpdating)
|
||||||
tr("One or more of your instances are from this same modpack%1. Do you want to create a "
|
|
||||||
"separate instance, or update the existing one?\n\nNOTE: Make sure you made a backup of your important instance data before "
|
|
||||||
"updating, as worlds can be corrupted and some configuration may be lost (due to pack overrides).")
|
|
||||||
.arg(version_str),
|
|
||||||
QMessageBox::Information, QMessageBox::Ok | QMessageBox::Reset | QMessageBox::Abort);
|
|
||||||
info->setButtonText(QMessageBox::Ok, tr("Update existing instance"));
|
|
||||||
info->setButtonText(QMessageBox::Abort, tr("Create new instance"));
|
|
||||||
info->setButtonText(QMessageBox::Reset, tr("Cancel"));
|
|
||||||
|
|
||||||
info->exec();
|
|
||||||
|
|
||||||
if (info->clickedButton() == info->button(QMessageBox::Abort))
|
|
||||||
return false;
|
return false;
|
||||||
|
if (should_update == ShouldUpdate::Cancel) {
|
||||||
if (info->clickedButton() == info->button(QMessageBox::Reset)) {
|
|
||||||
m_abort = true;
|
m_abort = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -49,23 +49,10 @@ bool ModrinthCreationTask::updateInstance()
|
|||||||
auto version_name = inst->getManagedPackVersionName();
|
auto version_name = inst->getManagedPackVersionName();
|
||||||
auto version_str = !version_name.isEmpty() ? tr(" (version %1)").arg(version_name) : "";
|
auto version_str = !version_name.isEmpty() ? tr(" (version %1)").arg(version_name) : "";
|
||||||
|
|
||||||
auto info = CustomMessageBox::selectable(
|
auto should_update = askIfShouldUpdate(m_parent, version_str);
|
||||||
m_parent, tr("Similar modpack was found!"),
|
if (should_update == ShouldUpdate::SkipUpdating)
|
||||||
tr("One or more of your instances are from this same modpack%1. Do you want to create a "
|
|
||||||
"separate instance, or update the existing one?\n\nNOTE: Make sure you made a backup of your important instance data before "
|
|
||||||
"updating, as worlds can be corrupted and some configuration may be lost (due to pack overrides).")
|
|
||||||
.arg(version_str),
|
|
||||||
QMessageBox::Information, QMessageBox::Ok | QMessageBox::Reset | QMessageBox::Abort);
|
|
||||||
info->setButtonText(QMessageBox::Ok, tr("Create new instance"));
|
|
||||||
info->setButtonText(QMessageBox::Abort, tr("Update existing instance"));
|
|
||||||
info->setButtonText(QMessageBox::Reset, tr("Cancel"));
|
|
||||||
|
|
||||||
info->exec();
|
|
||||||
|
|
||||||
if (info->clickedButton() == info->button(QMessageBox::Ok))
|
|
||||||
return false;
|
return false;
|
||||||
|
if (should_update == ShouldUpdate::Cancel) {
|
||||||
if (info->clickedButton() == info->button(QMessageBox::Reset)) {
|
|
||||||
m_abort = true;
|
m_abort = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user