mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-12 05:07:46 +02:00
Make actions more consistent
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
@ -81,15 +81,28 @@ ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared
|
||||
connect(ui->treeView, &ModListView::activated, this, &ExternalResourcesPage::itemActivated);
|
||||
|
||||
auto selection_model = ui->treeView->selectionModel();
|
||||
connect(selection_model, &QItemSelectionModel::currentChanged, this, &ExternalResourcesPage::current);
|
||||
|
||||
connect(selection_model, &QItemSelectionModel::currentChanged, this, [this](const QModelIndex& current, const QModelIndex& previous) {
|
||||
if (!current.isValid()) {
|
||||
ui->frame->clear();
|
||||
return;
|
||||
}
|
||||
|
||||
updateFrame(current, previous);
|
||||
});
|
||||
|
||||
auto updateExtra = [this]() {
|
||||
if (updateExtraInfo)
|
||||
updateExtraInfo(id(), extraHeaderInfoString());
|
||||
};
|
||||
|
||||
connect(selection_model, &QItemSelectionModel::selectionChanged, this, updateExtra);
|
||||
connect(model.get(), &ResourceFolderModel::updateFinished, this, updateExtra);
|
||||
|
||||
connect(ui->filterEdit, &QLineEdit::textChanged, this, &ExternalResourcesPage::filterTextChanged);
|
||||
connect(selection_model, &QItemSelectionModel::selectionChanged, this, [this] { updateActions(); });
|
||||
connect(m_model.get(), &ResourceFolderModel::rowsInserted, this, [this] { updateActions(); });
|
||||
connect(m_model.get(), &ResourceFolderModel::rowsRemoved, this, [this] { updateActions(); });
|
||||
connect(m_model.get(), &ResourceFolderModel::updateFinished, this, [this] { updateActions(); });
|
||||
|
||||
auto viewHeader = ui->treeView->header();
|
||||
viewHeader->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
@ -298,23 +311,22 @@ void ExternalResourcesPage::viewFolder()
|
||||
DesktopServices::openPath(m_model->dir().absolutePath(), true);
|
||||
}
|
||||
|
||||
bool ExternalResourcesPage::current(const QModelIndex& current, const QModelIndex& previous)
|
||||
void ExternalResourcesPage::updateActions()
|
||||
{
|
||||
if (!current.isValid()) {
|
||||
ui->frame->clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
return onSelectionChanged(current, previous);
|
||||
const bool hasSelection = ui->treeView->selectionModel()->hasSelection();
|
||||
ui->actionUpdateItem->setEnabled(!m_model->empty());
|
||||
ui->actionResetItemMetadata->setEnabled(hasSelection);
|
||||
ui->actionRemoveItem->setEnabled(hasSelection);
|
||||
ui->actionEnableItem->setEnabled(hasSelection);
|
||||
ui->actionDisableItem->setEnabled(hasSelection);
|
||||
}
|
||||
|
||||
bool ExternalResourcesPage::onSelectionChanged(const QModelIndex& current, [[maybe_unused]] const QModelIndex& previous)
|
||||
void ExternalResourcesPage::updateFrame(const QModelIndex& current, [[maybe_unused]] const QModelIndex& previous)
|
||||
{
|
||||
auto sourceCurrent = m_filterModel->mapToSource(current);
|
||||
int row = sourceCurrent.row();
|
||||
Resource const& resource = m_model->at(row);
|
||||
ui->frame->updateWithResource(resource);
|
||||
return true;
|
||||
}
|
||||
|
||||
QString ExternalResourcesPage::extraHeaderInfoString()
|
||||
|
Reference in New Issue
Block a user