summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-06-07 23:44:58 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-06-15 14:40:40 -0400
commit6e937f7d09da6ad773874fc6095e2fb5b51d9afc (patch)
treec67bb3f52ba97b14be55e9911ad1ae6b25581adf
parent1897d60134e1cff31375f1c602196a99ece7fc86 (diff)
add executable
-rw-r--r--src/editexecutablesdialog.cpp74
-rw-r--r--src/editexecutablesdialog.h3
2 files changed, 46 insertions, 31 deletions
diff --git a/src/editexecutablesdialog.cpp b/src/editexecutablesdialog.cpp
index 08e2c3d1..570d1396 100644
--- a/src/editexecutablesdialog.cpp
+++ b/src/editexecutablesdialog.cpp
@@ -114,17 +114,21 @@ void EditExecutablesDialog::fillExecutableList()
ui->list->clear();
for(const auto& exe : m_executablesList) {
- QListWidgetItem *newItem = new QListWidgetItem(exe.title());
-
- if (!exe.isCustom()) {
- auto f = newItem->font();
- f.setItalic(true);
+ ui->list->addItem(createListItem(exe));
+ }
+}
- newItem->setFont(f);
- }
+QListWidgetItem* EditExecutablesDialog::createListItem(const Executable& exe)
+{
+ QListWidgetItem *newItem = new QListWidgetItem(exe.title());
- ui->list->addItem(newItem);
+ if (!exe.isCustom()) {
+ auto f = newItem->font();
+ f.setItalic(true);
+ newItem->setFont(f);
}
+
+ return newItem;
}
void EditExecutablesDialog::updateUI(const Executable* e)
@@ -276,6 +280,24 @@ void EditExecutablesDialog::on_list_itemSelectionChanged()
updateUI(selectedExe());
}
+void EditExecutablesDialog::on_add_clicked()
+{
+ auto title = newExecutableTitle();
+ if (title.isNull()) {
+ return;
+ }
+
+ auto e = Executable()
+ .title(title)
+ .flags(Executable::CustomExecutable);
+
+ m_executablesList.setExecutable(e);
+
+ auto* item = createListItem(e);
+ ui->list->addItem(item);
+ item->setSelected(true);
+}
+
void EditExecutablesDialog::on_title_textChanged(const QString& s)
{
if (m_settingUI) {
@@ -405,24 +427,26 @@ void EditExecutablesDialog::setJarBinary(const QString& binaryName)
save();
}
+QString EditExecutablesDialog::newExecutableTitle()
+{
+ const auto prefix = tr("New Executable");
+ QString title = prefix;
+ for (int i=1; i<100; ++i) {
+ if (!m_executablesList.titleExists(title)) {
+ return title;
+ }
-void EditExecutablesDialog::resetInput()
-{
- ui->binary->setText("");
- ui->title->setText("");
- ui->workingDirectory->clear();
- ui->arguments->setText("");
- ui->overwriteSteamAppID->setChecked(false);
- ui->createFilesInMod->setChecked(false);
- ui->forceLoadLibraries->setChecked(false);
- ui->steamAppID->clear();
- ui->useApplicationIcon->setChecked(false);
+ title = prefix + QString(" (%1)").arg(i);
+ }
- m_currentItem = nullptr;
+ qCritical().nospace() << "ran out of new executable titles";
+ return QString::null;
}
+
+
ExecutablesList EditExecutablesDialog::getExecutablesList() const
{
ExecutablesList newList;
@@ -505,15 +529,6 @@ void EditExecutablesDialog::delayedRefresh()
-void EditExecutablesDialog::on_add_clicked()
-{
- if (executableChanged()) {
- saveExecutable();
- }
-
- resetInput();
- //refreshExecutablesWidget();
-}
void EditExecutablesDialog::on_remove_clicked()
{
@@ -524,7 +539,6 @@ void EditExecutablesDialog::on_remove_clicked()
m_executablesList.remove(ui->title->text());
}
- resetInput();
//refreshExecutablesWidget();
}
diff --git a/src/editexecutablesdialog.h b/src/editexecutablesdialog.h
index 1f3f0082..3145c94f 100644
--- a/src/editexecutablesdialog.h
+++ b/src/editexecutablesdialog.h
@@ -94,13 +94,14 @@ private:
Executable* selectedExe();
void fillExecutableList();
+ QListWidgetItem* createListItem(const Executable& exe);
void updateUI(const Executable* e);
void clearEdits();
void setEdits(const Executable& e);
void save();
void setJarBinary(const QString& binaryName);
+ QString newExecutableTitle();
- void resetInput();
bool executableChanged();
void updateButtonStates();
void saveExecutable();