From f993368115325b08b884c7b6f348bcfb57d200b2 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Mon, 3 Jul 2023 04:07:06 +0200 Subject: [PATCH] Prev selection on config change in same parent --- .../gui/modules/file_browser_worker.c | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/applications/services/gui/modules/file_browser_worker.c b/applications/services/gui/modules/file_browser_worker.c index 6f5461631..06e95425a 100644 --- a/applications/services/gui/modules/file_browser_worker.c +++ b/applications/services/gui/modules/file_browser_worker.c @@ -336,12 +336,41 @@ static int32_t browser_worker(void* context) { furi_assert((flags & FuriFlagError) == 0); if(flags & WorkerEvtConfigChange) { - // If start path is a path to the file - try finding index of this file in a folder - if(browser_path_is_file(browser->path_next)) { - path_extract_filename(browser->path_next, filename, false); - } + if(furi_string_start_with(path, browser->path_next)) { + // New path is parent of current, keep prev selected in new view + furi_string_set(filename, path); + furi_string_right(filename, furi_string_size(browser->path_next)); + furi_string_trim(filename, "/"); + size_t pos = furi_string_search_char(filename, '/'); + if(pos != FURI_STRING_FAILURE) { + furi_string_left(filename, pos); + } - furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtFolderEnter); + furi_string_set(path, browser->path_next); + bool is_root = browser_folder_check_and_switch(path); + + int32_t file_idx = 0; + browser_folder_init(browser, path, filename, &items_cnt, &file_idx); + furi_string_set(browser->path_current, path); + FURI_LOG_D( + TAG, + "Config to: %s items: %lu idx: %ld", + furi_string_get_cstr(path), + items_cnt, + file_idx); + if(browser->folder_cb) { + browser->folder_cb(browser->cb_ctx, items_cnt, file_idx, is_root); + } + furi_string_reset(filename); + + } else { + // If start path is a path to the file - try finding index of this file in a folder + if(browser_path_is_file(browser->path_next)) { + path_extract_filename(browser->path_next, filename, false); + } + + furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtFolderEnter); + } } if(flags & WorkerEvtFolderEnter) {