From 00589b247a14d2f7ff549740c89f087c2dd8f0bd Mon Sep 17 00:00:00 2001 From: arthomnix Date: Mon, 11 Jul 2022 18:02:20 +0100 Subject: [PATCH 1/3] GH-4812 Prefill instance name to allow making adjustments Fills the instance name in instead of just setting a placeholder. This allows adjustments to be made to the suggested name without typing the whole thing out. The text is selected by default so that typing will overwrite the text, but users who want to adjust the default name instead of typing their own can deselect the text. The placeholder name is still set so it is still visible if the user deletes the text. Also sets the focus to the instance name textbox by default, whereas previously it was on the group name - this is required so the text gets overwritten on typing but also makes more sense generally. Closes issue #4812. --- launcher/ui/dialogs/NewInstanceDialog.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/launcher/ui/dialogs/NewInstanceDialog.cpp b/launcher/ui/dialogs/NewInstanceDialog.cpp index 0b933fb5..135e8b3d 100644 --- a/launcher/ui/dialogs/NewInstanceDialog.cpp +++ b/launcher/ui/dialogs/NewInstanceDialog.cpp @@ -151,6 +151,9 @@ void NewInstanceDialog::setSuggestedPack(const QString& name, InstanceTask* task { creationTask.reset(task); ui->instNameTextBox->setPlaceholderText(name); + ui->instNameTextBox->setText(name); + ui->instNameTextBox->selectAll(); + ui->instNameTextBox->setFocus(); if(!task) { From ec897aee95433603f490438ab2f3710c3388d979 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Mon, 11 Jul 2022 19:51:31 +0100 Subject: [PATCH 2/3] GH-4812 More improvements related to instance name Selects text on focus rather than selecting text and focusing by default. Text is not selected if the user has changed the name from the default. If the user changes the instance name, don't change it when they select a new version or modpack. Add a reset button that changes the instance name back to the default for the selected version/pack, and resets the flag that stops the name from being changed upon selecting a new version/pack. --- launcher/ui/dialogs/NewInstanceDialog.cpp | 32 +++++++++++++++++++--- launcher/ui/dialogs/NewInstanceDialog.h | 6 +++++ launcher/ui/dialogs/NewInstanceDialog.ui | 33 ++++++++++++++--------- 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/launcher/ui/dialogs/NewInstanceDialog.cpp b/launcher/ui/dialogs/NewInstanceDialog.cpp index 135e8b3d..42130f49 100644 --- a/launcher/ui/dialogs/NewInstanceDialog.cpp +++ b/launcher/ui/dialogs/NewInstanceDialog.cpp @@ -103,6 +103,8 @@ NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString importPage->setUrl(url); } + connect(APPLICATION, &QApplication::focusChanged, this, &NewInstanceDialog::onFocusChanged); + updateDialogState(); restoreGeometry(QByteArray::fromBase64(APPLICATION->settings()->get("NewInstanceGeometry").toByteArray())); @@ -150,10 +152,14 @@ NewInstanceDialog::~NewInstanceDialog() void NewInstanceDialog::setSuggestedPack(const QString& name, InstanceTask* task) { creationTask.reset(task); - ui->instNameTextBox->setPlaceholderText(name); - ui->instNameTextBox->setText(name); - ui->instNameTextBox->selectAll(); - ui->instNameTextBox->setFocus(); + + defaultInstName = name; + + if (!instNameChanged) + { + ui->instNameTextBox->setPlaceholderText(name); + ui->instNameTextBox->setText(name); + } if(!task) { @@ -241,11 +247,29 @@ void NewInstanceDialog::on_iconButton_clicked() } } +void NewInstanceDialog::on_resetNameButton_clicked() +{ + ui->instNameTextBox->setText(defaultInstName); + instNameChanged = false; +} + void NewInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1) { updateDialogState(); } +void NewInstanceDialog::on_instNameTextBox_textEdited(const QString &text) +{ + instNameChanged = true; +} + +void NewInstanceDialog::onFocusChanged(QWidget *, QWidget *newWidget) +{ + if (newWidget == ui->instNameTextBox && !instNameChanged) { + QTimer::singleShot(0, ui->instNameTextBox, &QLineEdit::selectAll); + } +} + void NewInstanceDialog::importIconNow() { if(importIcon) { diff --git a/launcher/ui/dialogs/NewInstanceDialog.h b/launcher/ui/dialogs/NewInstanceDialog.h index 3a100b77..a001acea 100644 --- a/launcher/ui/dialogs/NewInstanceDialog.h +++ b/launcher/ui/dialogs/NewInstanceDialog.h @@ -56,10 +56,13 @@ public: public slots: void accept() override; void reject() override; + void onFocusChanged(QWidget *, QWidget *newWidget); private slots: void on_iconButton_clicked(); + void on_resetNameButton_clicked(); void on_instNameTextBox_textChanged(const QString &arg1); + void on_instNameTextBox_textEdited(const QString &text); private: Ui::NewInstanceDialog *ui = nullptr; @@ -75,4 +78,7 @@ private: QString importIconName; void importIconNow(); + + QString defaultInstName; + bool instNameChanged = false; }; diff --git a/launcher/ui/dialogs/NewInstanceDialog.ui b/launcher/ui/dialogs/NewInstanceDialog.ui index 7fb19ff5..90d6bf39 100644 --- a/launcher/ui/dialogs/NewInstanceDialog.ui +++ b/launcher/ui/dialogs/NewInstanceDialog.ui @@ -26,6 +26,9 @@ + + + @@ -33,6 +36,16 @@ + + + + &Name: + + + instNameTextBox + + + @@ -43,19 +56,6 @@ - - - - - - - &Name: - - - instNameTextBox - - - @@ -66,6 +66,13 @@ + + + + Reset + + + From ffec1e1930420e1a1d0aafdabf18f3fd1e06c9a2 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Mon, 11 Jul 2022 19:55:36 +0100 Subject: [PATCH 3/3] GH-4812 Set placeholder even if the user has changed the name --- launcher/ui/dialogs/NewInstanceDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/dialogs/NewInstanceDialog.cpp b/launcher/ui/dialogs/NewInstanceDialog.cpp index 42130f49..28be8fee 100644 --- a/launcher/ui/dialogs/NewInstanceDialog.cpp +++ b/launcher/ui/dialogs/NewInstanceDialog.cpp @@ -154,10 +154,10 @@ void NewInstanceDialog::setSuggestedPack(const QString& name, InstanceTask* task creationTask.reset(task); defaultInstName = name; + ui->instNameTextBox->setPlaceholderText(name); if (!instNameChanged) { - ui->instNameTextBox->setPlaceholderText(name); ui->instNameTextBox->setText(name); }