summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-08-21 09:00:35 +0200
committerPetr Mrázek <peterix@gmail.com>2015-08-21 09:00:35 +0200
commit40ed2654c7766857f8158e8d9744edc28ac0ef26 (patch)
tree3ee3e341ab5b34385cadb5ab68f1862f2b1a49d9 /application
parent875c707358b5c289fa70dbcd467a3dcf9c2ab302 (diff)
downloadMultiMC-40ed2654c7766857f8158e8d9744edc28ac0ef26.tar
MultiMC-40ed2654c7766857f8158e8d9744edc28ac0ef26.tar.gz
MultiMC-40ed2654c7766857f8158e8d9744edc28ac0ef26.tar.lz
MultiMC-40ed2654c7766857f8158e8d9744edc28ac0ef26.tar.xz
MultiMC-40ed2654c7766857f8158e8d9744edc28ac0ef26.zip
GH-1148 New instance name is either version or modpack 'base name'
Default names now use the placeholder text in the new instance dialog.
Diffstat (limited to 'application')
-rw-r--r--application/dialogs/NewInstanceDialog.cpp50
-rw-r--r--application/dialogs/NewInstanceDialog.h3
2 files changed, 43 insertions, 10 deletions
diff --git a/application/dialogs/NewInstanceDialog.cpp b/application/dialogs/NewInstanceDialog.cpp
index 6cd651e4..661f5c53 100644
--- a/application/dialogs/NewInstanceDialog.cpp
+++ b/application/dialogs/NewInstanceDialog.cpp
@@ -64,14 +64,18 @@ NewInstanceDialog::NewInstanceDialog(QWidget *parent)
resize(minimumSizeHint());
layout()->setSizeConstraint(QLayout::SetFixedSize);
- setSelectedVersion(MMC->minecraftlist()->getRecommended(), true);
+ setSelectedVersion(MMC->minecraftlist()->getRecommended());
InstIconKey = "default";
ui->iconButton->setIcon(ENV.icons()->getIcon(InstIconKey));
ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit));
+
+ ui->instNameTextBox->setAlignment(Qt::AlignHCenter);
+
connect(ui->modpackEdit, &QLineEdit::textChanged, this, &NewInstanceDialog::updateDialogState);
connect(ui->modpackBox, &QRadioButton::clicked, this, &NewInstanceDialog::updateDialogState);
connect(ui->versionBox, &QRadioButton::clicked, this, &NewInstanceDialog::updateDialogState);
+ connect(ui->versionTextBox, &QLineEdit::textChanged, this, &NewInstanceDialog::updateDialogState);
auto groups = MMC->instances()->getGroups().toSet();
auto groupList = QStringList(groups.toList());
@@ -88,6 +92,10 @@ NewInstanceDialog::NewInstanceDialog(QWidget *parent)
}
ui->groupBox->setCurrentIndex(index);
ui->groupBox->lineEdit()->setPlaceholderText(tr("No group"));
+ ui->buttonBox->setFocus();
+
+ originalPlaceholderText = ui->instNameTextBox->placeholderText();
+ updateDialogState();
}
NewInstanceDialog::~NewInstanceDialog()
@@ -97,36 +105,60 @@ NewInstanceDialog::~NewInstanceDialog()
void NewInstanceDialog::updateDialogState()
{
+ QString suggestedName;
+ if(ui->versionBox->isChecked())
+ {
+ suggestedName = ui->versionTextBox->text();
+ }
+ else if (ui->modpackBox->isChecked())
+ {
+ auto url = QUrl::fromUserInput(ui->modpackEdit->text());
+ QFileInfo fi(url.fileName());
+ suggestedName = fi.baseName();
+ }
+ if(suggestedName.isEmpty())
+ {
+ ui->instNameTextBox->setPlaceholderText(originalPlaceholderText);
+ }
+ else
+ {
+ ui->instNameTextBox->setPlaceholderText(suggestedName);
+ }
bool allowOK = !instName().isEmpty() &&
(ui->versionBox->isChecked() && m_selectedVersion ||
(ui->modpackBox->isChecked() && ui->modpackEdit->hasAcceptableInput()));
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(allowOK);
}
-void NewInstanceDialog::setSelectedVersion(BaseVersionPtr version, bool initial)
+void NewInstanceDialog::setSelectedVersion(BaseVersionPtr version)
{
m_selectedVersion = version;
if (m_selectedVersion)
{
ui->versionTextBox->setText(version->name());
- if(ui->instNameTextBox->text().isEmpty() && !initial)
- {
- ui->instNameTextBox->setText(version->name());
- }
}
else
{
ui->versionTextBox->setText("");
}
-
- updateDialogState();
}
QString NewInstanceDialog::instName() const
{
- return ui->instNameTextBox->text();
+ auto result = ui->instNameTextBox->text();
+ if(result.size())
+ {
+ return result;
+ }
+ result = ui->instNameTextBox->placeholderText();
+ if(result.size() && result != originalPlaceholderText)
+ {
+ return result;
+ }
+ return QString();
}
+
QString NewInstanceDialog::instGroup() const
{
return ui->groupBox->currentText();
diff --git a/application/dialogs/NewInstanceDialog.h b/application/dialogs/NewInstanceDialog.h
index bc3152b9..1a2be10c 100644
--- a/application/dialogs/NewInstanceDialog.h
+++ b/application/dialogs/NewInstanceDialog.h
@@ -34,7 +34,7 @@ public:
void updateDialogState();
- void setSelectedVersion(BaseVersionPtr version, bool initial = false);
+ void setSelectedVersion(BaseVersionPtr version);
void loadVersionList();
@@ -56,4 +56,5 @@ private:
BaseVersionPtr m_selectedVersion;
QString InstIconKey;
+ QString originalPlaceholderText;
};