feat:Added remove metadata button
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
8f5bb982cd
commit
589d8b6923
@ -132,17 +132,23 @@ auto Mod::destroy(QDir& index_dir, bool preserve_metadata, bool attempt_trash) -
|
||||
if (!preserve_metadata) {
|
||||
qDebug() << QString("Destroying metadata for '%1' on purpose").arg(name());
|
||||
|
||||
if (metadata()) {
|
||||
Metadata::remove(index_dir, metadata()->slug);
|
||||
} else {
|
||||
auto n = name();
|
||||
Metadata::remove(index_dir, n);
|
||||
}
|
||||
destroyMetadata(index_dir);
|
||||
}
|
||||
|
||||
return Resource::destroy(attempt_trash);
|
||||
}
|
||||
|
||||
void Mod::destroyMetadata(QDir& index_dir)
|
||||
{
|
||||
if (metadata()) {
|
||||
Metadata::remove(index_dir, metadata()->slug);
|
||||
} else {
|
||||
auto n = name();
|
||||
Metadata::remove(index_dir, n);
|
||||
}
|
||||
m_local_details.metadata = nullptr;
|
||||
}
|
||||
|
||||
auto Mod::details() const -> const ModDetails&
|
||||
{
|
||||
return m_local_details;
|
||||
|
@ -93,6 +93,8 @@ class Mod : public Resource {
|
||||
|
||||
// Delete all the files of this mod
|
||||
auto destroy(QDir& index_dir, bool preserve_metadata = false, bool attempt_trash = true) -> bool;
|
||||
// Delete the metadata only
|
||||
void destroyMetadata(QDir& index_dir);
|
||||
|
||||
void finishResolvingWithDetails(ModDetails&& details);
|
||||
|
||||
|
@ -228,6 +228,25 @@ bool ModFolderModel::deleteMods(const QModelIndexList& indexes)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModFolderModel::deleteModsMeatadata(const QModelIndexList& indexes)
|
||||
{
|
||||
if (indexes.isEmpty())
|
||||
return true;
|
||||
|
||||
for (auto i : indexes) {
|
||||
if (i.column() != 0) {
|
||||
continue;
|
||||
}
|
||||
auto m = at(i.row());
|
||||
auto index_dir = indexDir();
|
||||
m->destroyMetadata(index_dir);
|
||||
}
|
||||
|
||||
update();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModFolderModel::isValid()
|
||||
{
|
||||
return m_dir.exists() && m_dir.isReadable();
|
||||
|
@ -79,6 +79,7 @@ class ModFolderModel : public ResourceFolderModel {
|
||||
|
||||
/// Deletes all the selected mods
|
||||
bool deleteMods(const QModelIndexList& indexes);
|
||||
bool deleteModsMeatadata(const QModelIndexList& indexes);
|
||||
|
||||
bool isValid();
|
||||
|
||||
|
@ -128,7 +128,6 @@ struct IndexedPack {
|
||||
return std::any_of(versions.constBegin(), versions.constEnd(), [](auto const& v) { return v.is_currently_selected; });
|
||||
}
|
||||
};
|
||||
QString getMetaURL(ResourceProvider provider, QVariant projectID);
|
||||
|
||||
struct OverrideDep {
|
||||
QString quilt;
|
||||
|
@ -168,6 +168,17 @@
|
||||
<string>Go to mods home page</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRemoveItemMetadata">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove metadata</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Remove selected mod metadata</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
@ -92,6 +92,10 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel>
|
||||
ui->actionsToolbar->addAction(ui->actionVisitItemPage);
|
||||
connect(ui->actionVisitItemPage, &QAction::triggered, this, &ModFolderPage::visitModPages);
|
||||
|
||||
ui->actionRemoveItemMetadata->setToolTip(tr("Remove mod's metadata"));
|
||||
ui->actionsToolbar->insertActionAfter(ui->actionRemoveItem, ui->actionRemoveItemMetadata);
|
||||
connect(ui->actionRemoveItemMetadata, &QAction::triggered, this, &ModFolderPage::deleteModMetadata);
|
||||
|
||||
auto check_allow_update = [this] { return ui->treeView->selectionModel()->hasSelection() || !m_model->empty(); };
|
||||
|
||||
connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [this, check_allow_update] {
|
||||
@ -104,11 +108,16 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel>
|
||||
if (selected <= 1) {
|
||||
ui->actionVisitItemPage->setText(tr("Visit mod's page"));
|
||||
ui->actionVisitItemPage->setToolTip(tr("Go to mod's home page"));
|
||||
|
||||
ui->actionRemoveItemMetadata->setToolTip(tr("Remove mod's metadata"));
|
||||
} else {
|
||||
ui->actionVisitItemPage->setText(tr("Visit mods' pages"));
|
||||
ui->actionVisitItemPage->setToolTip(tr("Go to the pages of the selected mods"));
|
||||
|
||||
ui->actionRemoveItemMetadata->setToolTip(tr("Remove mods' metadata"));
|
||||
}
|
||||
ui->actionVisitItemPage->setEnabled(selected != 0);
|
||||
ui->actionRemoveItemMetadata->setEnabled(selected != 0);
|
||||
});
|
||||
|
||||
connect(mods.get(), &ModFolderModel::rowsInserted, this,
|
||||
@ -297,3 +306,27 @@ void ModFolderPage::visitModPages()
|
||||
DesktopServices::openUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
void ModFolderPage::deleteModMetadata()
|
||||
{
|
||||
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
|
||||
QString text;
|
||||
auto selectionCount = m_model->selectedMods(selection).length();
|
||||
if (selectionCount == 0)
|
||||
return;
|
||||
else if (selectionCount > 1)
|
||||
text = tr("You are about to remove the metadata for %1 mods.\n"
|
||||
"Are you sure?")
|
||||
.arg(selectionCount);
|
||||
else
|
||||
text = tr("You are about to remove the metadata for %1.\n"
|
||||
"Are you sure?")
|
||||
.arg(m_model->at(selection.at(0).row())->name());
|
||||
|
||||
auto response = CustomMessageBox::selectable(this, tr("Confirm Removal"), text, QMessageBox::Warning,
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
|
||||
->exec();
|
||||
|
||||
if (response == QMessageBox::Yes)
|
||||
m_model->deleteModsMeatadata(selection);
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ class ModFolderPage : public ExternalResourcesPage {
|
||||
|
||||
private slots:
|
||||
void removeItems(const QItemSelection& selection) override;
|
||||
void deleteModMetadata();
|
||||
|
||||
void installMods();
|
||||
void updateMods();
|
||||
|
Loading…
Reference in New Issue
Block a user