Delete Patches Button (#1722)

This commit is contained in:
DanielSvoboda 2024-12-10 08:12:58 -03:00 committed by GitHub
parent cd9fc5d0e9
commit aa5293e3ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 1 deletions

View file

@ -51,6 +51,9 @@ void CheatsPatches::setupUI() {
QString CHEATS_DIR_QString;
Common::FS::PathToQString(CHEATS_DIR_QString,
Common::FS::GetUserPath(Common::FS::PathType::CheatsDir));
QString PATCHS_DIR_QString;
Common::FS::PathToQString(PATCHS_DIR_QString,
Common::FS::GetUserPath(Common::FS::PathType::PatchesDir));
QString NameCheatJson = m_gameSerial + "_" + m_gameVersion + ".json";
m_cheatFilePath = CHEATS_DIR_QString + "/" + NameCheatJson;
@ -237,9 +240,45 @@ void CheatsPatches::setupUI() {
});
patchesControlLayout->addWidget(patchesButton);
QPushButton* deletePatchButton = new QPushButton(tr("Delete File"));
connect(deletePatchButton, &QPushButton::clicked, [this, PATCHS_DIR_QString]() {
QStringListModel* model = qobject_cast<QStringListModel*>(patchesListView->model());
if (!model) {
return;
}
QItemSelectionModel* selectionModel = patchesListView->selectionModel();
if (!selectionModel) {
return;
}
QModelIndexList selectedIndexes = selectionModel->selectedIndexes();
if (selectedIndexes.isEmpty()) {
QMessageBox::warning(this, tr("Delete File"), tr("No files selected."));
return;
}
QModelIndex selectedIndex = selectedIndexes.first();
QString selectedFileName = model->data(selectedIndex).toString();
int ret = QMessageBox::warning(
this, tr("Delete File"),
QString(tr("Do you want to delete the selected file?\\n%1").replace("\\n", "\n"))
.arg(selectedFileName),
QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::Yes) {
QString fileName = selectedFileName.split('|').first().trimmed();
QString directoryName = selectedFileName.split('|').last().trimmed();
QString filePath = PATCHS_DIR_QString + "/" + directoryName + "/" + fileName;
QFile::remove(filePath);
createFilesJson(directoryName);
populateFileListPatches();
}
});
QPushButton* saveButton = new QPushButton(tr("Save"));
connect(saveButton, &QPushButton::clicked, this, &CheatsPatches::onSaveButtonClicked);
patchesControlLayout->addWidget(deletePatchButton);
patchesControlLayout->addWidget(saveButton);
patchesLayout->addLayout(patchesControlLayout);

View file

@ -841,7 +841,7 @@
<message>
<location filename="../cheats_patches.cpp" line="44"/>
<source>Cheats / Patches for </source>
<translation>Cheats / Patches for </translation>
<translation>Cheats / Patches para </translation>
</message>
<message>
<location filename="../cheats_patches.cpp" line="50"/>