editable combobox for output mod name

This commit is contained in:
isanae
2020-12-29 02:10:33 -05:00
parent 91e1cc9cca
commit cc997c3704
4 changed files with 69 additions and 4 deletions
+63 -3
View File
@@ -71,6 +71,9 @@ EditExecutablesDialog::EditExecutablesDialog(OrganizerCore& oc, int sel, QWidget
loadCustomOverwrites();
loadForcedLibraries();
QStringList modNames;
for (auto&& m : m_organizerCore.modList()->allMods()) {
auto mod = ModInfo::getByName(m);
if (!mod->hasAnyOfTheseFlags({ ModInfo::FLAG_FOREIGN,
@@ -78,9 +81,16 @@ EditExecutablesDialog::EditExecutablesDialog(OrganizerCore& oc, int sel, QWidget
ModInfo::FLAG_OVERWRITE,
ModInfo::FLAG_SEPARATOR })) {
ui->mods->addItem(m);
modNames.push_back(m);
}
}
auto* c = new QCompleter(modNames);
c->setCaseSensitivity(Qt::CaseInsensitive);
c->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
ui->mods->setCompleter(c);
fillList();
setDirty(false);
@@ -170,9 +180,51 @@ EditExecutablesDialog::getForcedLibraries() const
return m_forcedLibraries;
}
void EditExecutablesDialog::commitChanges()
bool EditExecutablesDialog::checkOutputMods(const ExecutablesList& exes)
{
// make sure the output mods for exes exist since the combobox is editable
//
// it'd be convenient for users to automatically create mods here if they're
// not found, but this is a can of worms: it would require a refresh
// because getIndex() still won't find it after calling
// OrganizerCore::createMod(), which is a problem if the user just clicked
// Apply and continued doing things
//
// triggering a refresh while this dialog is up doesn't sound like a very
// smart thing to do for now, so this just shows an error
for (const auto& e : exes) {
auto modName = m_customOverwrites.find(e.title());
if (modName && modName->enabled) {
if (modName->value.isEmpty()) {
QMessageBox::critical(
this, tr("Empty output mod"),
tr("The output mod for %2 is empty.").arg(e.title()));
return false;
} else if (ModInfo::getIndex(modName->value) == UINT_MAX) {
QMessageBox::critical(
this, tr("Output mod not found"),
tr("The output mod '%1' for %2 does not exist.")
.arg(modName->value).arg(e.title()));
return false;
}
}
}
return true;
}
bool EditExecutablesDialog::commitChanges()
{
const auto newExecutables = getExecutablesList();
if (!checkOutputMods(newExecutables)) {
return false;
}
auto* profile = m_organizerCore.currentProfile();
// remove all the custom overwrites and forced libraries
@@ -201,6 +253,8 @@ void EditExecutablesDialog::commitChanges()
m_organizerCore.setExecutablesList(newExecutables);
setDirty(false);
return true;
}
void EditExecutablesDialog::setDirty(bool b)
@@ -651,6 +705,11 @@ void EditExecutablesDialog::on_createFilesInMod_toggled(bool checked)
ui->mods->setEnabled(checked);
save();
if (checked) {
ui->mods->lineEdit()->selectAll();
ui->mods->setFocus();
}
}
void EditExecutablesDialog::on_forceLoadLibraries_toggled(bool checked)
@@ -776,8 +835,9 @@ void EditExecutablesDialog::on_configureLibraries_clicked()
void EditExecutablesDialog::on_buttons_clicked(QAbstractButton* b)
{
if (b == ui->buttons->button(QDialogButtonBox::Ok)) {
commitChanges();
accept();
if (commitChanges()) {
accept();
}
} else if (b == ui->buttons->button(QDialogButtonBox::Apply)) {
commitChanges();
} else {
+2 -1
View File
@@ -225,9 +225,10 @@ private:
bool canMove(const QListWidgetItem* item, int direction);
void move(QListWidgetItem* item, int direction);
bool isTitleConflicting(const QString& s);
void commitChanges();
bool commitChanges();
void setDirty(bool b);
void selectIndex(int i);
bool checkOutputMods(const ExecutablesList& exes);
void addFromFile();
void addEmpty();
+3
View File
@@ -387,6 +387,9 @@ Right now the only case I know of where this needs to be overwritten is for the
<property name="enabled">
<bool>false</bool>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
+1
View File
@@ -89,6 +89,7 @@
#include <QColorDialog>
#include <QComboBox>
#include <QCommandLinkButton>
#include <QCompleter>
#include <QContextMenuEvent>
#include <QCoreApplication>
#include <QCryptographicHash>