feat: remember parent folder index in menu when ascending folders (#260)

## Summary

Adds feature to file selection activity for better user navigation when
ascending folders. The activity now remembers the index of the parent
folder instead of always resetting to the first element.

I don't have any means of testing this, so if someone could test it
that'd be great

Resolves #259
This commit is contained in:
Justin
2026-01-07 03:58:49 -05:00
committed by GitHub
parent b792b792bf
commit 0edb2baced
2 changed files with 14 additions and 1 deletions

View File

@@ -29,7 +29,6 @@ void FileSelectionActivity::taskTrampoline(void* param) {
void FileSelectionActivity::loadFiles() { void FileSelectionActivity::loadFiles() {
files.clear(); files.clear();
selectorIndex = 0;
auto root = SdMan.open(basepath.c_str()); auto root = SdMan.open(basepath.c_str());
if (!root || !root.isDirectory()) { if (!root || !root.isDirectory()) {
@@ -132,9 +131,16 @@ void FileSelectionActivity::loop() {
// Short press: go up one directory, or go home if at root // Short press: go up one directory, or go home if at root
if (mappedInput.getHeldTime() < GO_HOME_MS) { if (mappedInput.getHeldTime() < GO_HOME_MS) {
if (basepath != "/") { if (basepath != "/") {
const std::string oldPath = basepath;
basepath.replace(basepath.find_last_of('/'), std::string::npos, ""); basepath.replace(basepath.find_last_of('/'), std::string::npos, "");
if (basepath.empty()) basepath = "/"; if (basepath.empty()) basepath = "/";
loadFiles(); loadFiles();
auto pos = oldPath.find_last_of('/');
std::string dirName = oldPath.substr(pos + 1) + "/";
selectorIndex = findEntry(dirName);
updateRequired = true; updateRequired = true;
} else { } else {
onGoHome(); onGoHome();
@@ -194,3 +200,9 @@ void FileSelectionActivity::render() const {
renderer.displayBuffer(); renderer.displayBuffer();
} }
int FileSelectionActivity::findEntry(const std::string& name) const {
for (size_t i = 0; i < files.size(); i++)
if (files[i] == name) return i;
return 0;
}

View File

@@ -23,6 +23,7 @@ class FileSelectionActivity final : public Activity {
[[noreturn]] void displayTaskLoop(); [[noreturn]] void displayTaskLoop();
void render() const; void render() const;
void loadFiles(); void loadFiles();
int findEntry(const std::string& name) const;
public: public:
explicit FileSelectionActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, explicit FileSelectionActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,