mirror of
https://github.com/MultiMC/MultiMC5.git
synced 2024-12-25 15:16:02 +00:00
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.
This commit is contained in:
parent
00589b247a
commit
ec897aee95
@ -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) {
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -26,6 +26,9 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="2">
|
||||
<widget class="QLineEdit" name="instNameTextBox"/>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QComboBox" name="groupBox">
|
||||
<property name="editable">
|
||||
@ -33,6 +36,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="nameLabel">
|
||||
<property name="text">
|
||||
<string>&Name:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>instNameTextBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="groupLabel">
|
||||
<property name="text">
|
||||
@ -43,19 +56,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLineEdit" name="instNameTextBox"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="nameLabel">
|
||||
<property name="text">
|
||||
<string>&Name:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>instNameTextBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="2">
|
||||
<widget class="QToolButton" name="iconButton">
|
||||
<property name="iconSize">
|
||||
@ -66,6 +66,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QPushButton" name="resetNameButton">
|
||||
<property name="text">
|
||||
<string>Reset</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
Loading…
Reference in New Issue
Block a user