CResourceBrowser: Allow navigating directories with the Enter keys

Previously the resource browser required you to double click on
everything in order to interact with it (going into directories, or
launching handlers for particular files, etc).

This is kinda stinky workflow-wise long-term when flipping between
assets; so we can make the interface a little less mouse-centric by
allowing the use of the enter keys to also perform the same behavior.
This commit is contained in:
Lioncache
2025-12-02 19:44:33 -05:00
parent 137bed91d8
commit 2e4ddea65b
2 changed files with 34 additions and 0 deletions

View File

@@ -18,6 +18,7 @@
#include <QCheckBox>
#include <QFileDialog>
#include <QInputDialog>
#include <QKeyEvent>
#include <QMenu>
#include <QMessageBox>
#include <QtConcurrent/QtConcurrentRun>
@@ -518,6 +519,38 @@ bool CResourceBrowser::eventFilter(QObject *pWatched, QEvent *pEvent)
return false;
}
void CResourceBrowser::keyPressEvent(QKeyEvent* event)
{
// If we don't have focus for one reason or another, then
// don't do anything. It's unintuitive to listen on key
// inputs when a control isn't in focus.
const auto* resource_view = mpUI->ResourceTableView;
if (!resource_view->hasFocus())
{
event->ignore();
return;
}
// We only want to handle directory drilldown and returning if only one item is selected.
const auto indexes = resource_view->selectionModel()->selectedIndexes();
if (indexes.empty() || indexes.size() > 1)
{
event->ignore();
return;
}
const auto key = event->key();
if (key == Qt::Key_Return || key == Qt::Key_Enter)
{
OnDoubleClickTable(indexes.front());
}
else
{
// Pass down for any alternative handling
event->ignore();
}
}
void CResourceBrowser::RefreshResources()
{
// Fill resource table

View File

@@ -81,6 +81,7 @@ public:
// Interface
bool eventFilter(QObject* pWatched, QEvent* pEvent) override;
void keyPressEvent(QKeyEvent* event) override;
// Accessors
CResourceStore* CurrentStore() const { return mpStore; }