Qt: Add context menu to game list exclusion list

And allow multiple items to be selected.
pull/3799/head
Stenzek 1 week ago
parent 5b056fc8df
commit 024face27d
No known key found for this signature in database

@ -228,6 +228,8 @@ GameListSettingsWidget::GameListSettingsWidget(SettingsWindow* dialog, QWidget*
&GameListSettingsWidget::onRemoveExcludedPathButtonClicked);
connect(m_ui.excludedPaths, &QListWidget::itemSelectionChanged, this,
&GameListSettingsWidget::onExcludedPathsSelectionChanged);
connect(m_ui.excludedPaths, &QListWidget::customContextMenuRequested, this,
&GameListSettingsWidget::onExcludedPathsContextMenuRequested);
connect(m_ui.rescanAllGames, &QPushButton::clicked, this, &GameListSettingsWidget::onRescanAllGamesClicked);
connect(m_ui.scanForNewGames, &QPushButton::clicked, this, &GameListSettingsWidget::onScanForNewGamesClicked);
@ -356,14 +358,20 @@ void GameListSettingsWidget::onAddExcludedFolderButtonClicked()
void GameListSettingsWidget::onRemoveExcludedPathButtonClicked()
{
const int row = m_ui.excludedPaths->currentRow();
QListWidgetItem* item = (row >= 0) ? m_ui.excludedPaths->takeItem(row) : nullptr;
if (!item)
const QList<QListWidgetItem*> items = m_ui.excludedPaths->selectedItems();
if (items.isEmpty())
return;
if (Core::RemoveValueFromBaseStringListSetting("GameList", "ExcludedPaths", item->text().toUtf8().constData()))
bool changed = false;
for (QListWidgetItem* const item : items)
{
changed |=
Core::RemoveValueFromBaseStringListSetting("GameList", "ExcludedPaths", item->text().toUtf8().constData());
delete item;
}
if (changed)
Host::CommitBaseSettingChanges();
delete item;
g_main_window->refreshGameList(false);
}
@ -373,6 +381,23 @@ void GameListSettingsWidget::onExcludedPathsSelectionChanged()
m_ui.removeExcludedPath->setEnabled(!m_ui.excludedPaths->selectedItems().isEmpty());
}
void GameListSettingsWidget::onExcludedPathsContextMenuRequested(const QPoint& point)
{
QMenu* const menu = QtUtils::NewPopupMenu(this);
if (!m_ui.excludedPaths->selectedItems().isEmpty())
{
menu->addAction(QIcon(u":/icons/monochrome/svg/folder-reduce-line.svg"_s), tr("Remove"), this,
&GameListSettingsWidget::onRemoveExcludedPathButtonClicked);
menu->addSeparator();
}
menu->addAction(QIcon(u":/icons/monochrome/svg/file-add-line.svg"_s), tr("Add File..."), this,
&GameListSettingsWidget::onAddExcludedFileButtonClicked);
menu->addAction(QIcon(u":/icons/monochrome/svg/folder-add-line.svg"_s), tr("Add Folder..."), this,
&GameListSettingsWidget::onAddExcludedFolderButtonClicked);
menu->popup(m_ui.excludedPaths->mapToGlobal(point));
}
void GameListSettingsWidget::onRescanAllGamesClicked()
{
g_main_window->refreshGameList(true);

@ -72,6 +72,7 @@ private:
void onAddExcludedFolderButtonClicked();
void onRemoveExcludedPathButtonClicked();
void onExcludedPathsSelectionChanged();
void onExcludedPathsContextMenuRequested(const QPoint& point);
void onScanForNewGamesClicked();
void onRescanAllGamesClicked();

@ -183,6 +183,12 @@
</item>
<item>
<widget class="QListWidget" name="excludedPaths">
<property name="contextMenuPolicy">
<enum>Qt::ContextMenuPolicy::CustomContextMenu</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SelectionMode::ExtendedSelection</enum>
</property>
<property name="iconSize">
<size>
<width>20</width>

Loading…
Cancel
Save