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 authored and GitHub committed 2026-01-07 19:58:49 +11:00
1 parent fe0e2bc5b1
commit aa40e58bff
2 files changed
+14 -1

No files matched your search

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