From aa5293e3ad6d4fd6b83da219c6ee5d11d24fe5eb Mon Sep 17 00:00:00 2001 From: DanielSvoboda Date: Tue, 10 Dec 2024 08:12:58 -0300 Subject: [PATCH] Delete Patches Button (#1722) --- src/qt_gui/cheats_patches.cpp | 39 ++++++++++++++++++++++++++++++++ src/qt_gui/translations/pt_BR.ts | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/qt_gui/cheats_patches.cpp b/src/qt_gui/cheats_patches.cpp index 3e7c2245..446b5a0e 100644 --- a/src/qt_gui/cheats_patches.cpp +++ b/src/qt_gui/cheats_patches.cpp @@ -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(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); diff --git a/src/qt_gui/translations/pt_BR.ts b/src/qt_gui/translations/pt_BR.ts index 7ea63b9f..dfe78567 100644 --- a/src/qt_gui/translations/pt_BR.ts +++ b/src/qt_gui/translations/pt_BR.ts @@ -841,7 +841,7 @@ Cheats / Patches for - Cheats / Patches for + Cheats / Patches para