mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-26 07:35:41 +00:00
Qt: Add context menu and open directory to game directory list
This commit is contained in:
parent
8956fc27ce
commit
77481f5b23
|
@ -13,6 +13,7 @@
|
||||||
#include <QtNetwork/QNetworkRequest>
|
#include <QtNetwork/QNetworkRequest>
|
||||||
#include <QtWidgets/QFileDialog>
|
#include <QtWidgets/QFileDialog>
|
||||||
#include <QtWidgets/QHeaderView>
|
#include <QtWidgets/QHeaderView>
|
||||||
|
#include <QtWidgets/QMenu>
|
||||||
#include <QtWidgets/QMessageBox>
|
#include <QtWidgets/QMessageBox>
|
||||||
#include <QtWidgets/QProgressDialog>
|
#include <QtWidgets/QProgressDialog>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -152,6 +153,14 @@ public:
|
||||||
m_host_interface->refreshGameList(false);
|
m_host_interface->refreshGameList(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void openEntryInExplorer(QWidget* parent, int row) const
|
||||||
|
{
|
||||||
|
if (row < 0 || row >= static_cast<int>(m_entries.size()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
QtUtils::OpenURL(parent, QUrl::fromLocalFile(m_entries[row].path));
|
||||||
|
}
|
||||||
|
|
||||||
void loadFromSettings()
|
void loadFromSettings()
|
||||||
{
|
{
|
||||||
std::vector<std::string> path_list = m_host_interface->GetSettingStringList("GameList", "Paths");
|
std::vector<std::string> path_list = m_host_interface->GetSettingStringList("GameList", "Paths");
|
||||||
|
@ -212,8 +221,11 @@ GameListSettingsWidget::GameListSettingsWidget(QtHostInterface* host_interface,
|
||||||
m_ui.searchDirectoryList->horizontalHeader()->setHighlightSections(false);
|
m_ui.searchDirectoryList->horizontalHeader()->setHighlightSections(false);
|
||||||
m_ui.searchDirectoryList->verticalHeader()->hide();
|
m_ui.searchDirectoryList->verticalHeader()->hide();
|
||||||
m_ui.searchDirectoryList->setCurrentIndex({});
|
m_ui.searchDirectoryList->setCurrentIndex({});
|
||||||
|
m_ui.searchDirectoryList->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
|
||||||
|
|
||||||
connect(m_ui.searchDirectoryList, &QTableView::clicked, this, &GameListSettingsWidget::onDirectoryListItemClicked);
|
connect(m_ui.searchDirectoryList, &QTableView::clicked, this, &GameListSettingsWidget::onDirectoryListItemClicked);
|
||||||
|
connect(m_ui.searchDirectoryList, &QTableView::customContextMenuRequested, this,
|
||||||
|
&GameListSettingsWidget::onDirectoryListContextMenuRequested);
|
||||||
connect(m_ui.addSearchDirectoryButton, &QPushButton::clicked, this,
|
connect(m_ui.addSearchDirectoryButton, &QPushButton::clicked, this,
|
||||||
&GameListSettingsWidget::onAddSearchDirectoryButtonClicked);
|
&GameListSettingsWidget::onAddSearchDirectoryButtonClicked);
|
||||||
connect(m_ui.removeSearchDirectoryButton, &QPushButton::clicked, this,
|
connect(m_ui.removeSearchDirectoryButton, &QPushButton::clicked, this,
|
||||||
|
@ -246,6 +258,22 @@ void GameListSettingsWidget::onDirectoryListItemClicked(const QModelIndex& index
|
||||||
m_search_directories_model->setEntryRecursive(row, !m_search_directories_model->isEntryRecursive(row));
|
m_search_directories_model->setEntryRecursive(row, !m_search_directories_model->isEntryRecursive(row));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameListSettingsWidget::onDirectoryListContextMenuRequested(const QPoint& point)
|
||||||
|
{
|
||||||
|
QModelIndexList selection = m_ui.searchDirectoryList->selectionModel()->selectedIndexes();
|
||||||
|
if (selection.size() < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const int row = selection[0].row();
|
||||||
|
|
||||||
|
QMenu menu;
|
||||||
|
menu.addAction(tr("Remove"), [this, row]() { m_search_directories_model->removeEntry(row); });
|
||||||
|
menu.addSeparator();
|
||||||
|
menu.addAction(tr("Open Directory..."),
|
||||||
|
[this, row]() { m_search_directories_model->openEntryInExplorer(this, row); });
|
||||||
|
menu.exec(m_ui.searchDirectoryList->mapToGlobal(point));
|
||||||
|
}
|
||||||
|
|
||||||
void GameListSettingsWidget::addSearchDirectory(QWidget* parent_widget)
|
void GameListSettingsWidget::addSearchDirectory(QWidget* parent_widget)
|
||||||
{
|
{
|
||||||
QString dir =
|
QString dir =
|
||||||
|
|
|
@ -21,6 +21,7 @@ public Q_SLOTS:
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onDirectoryListItemClicked(const QModelIndex& index);
|
void onDirectoryListItemClicked(const QModelIndex& index);
|
||||||
|
void onDirectoryListContextMenuRequested(const QPoint& point);
|
||||||
void onAddSearchDirectoryButtonClicked();
|
void onAddSearchDirectoryButtonClicked();
|
||||||
void onRemoveSearchDirectoryButtonClicked();
|
void onRemoveSearchDirectoryButtonClicked();
|
||||||
void onScanForNewGamesClicked();
|
void onScanForNewGamesClicked();
|
||||||
|
|
Loading…
Reference in a new issue