mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-14 05:48:35 -07:00
Fix file browser back history
This commit is contained in:
@@ -58,8 +58,9 @@ static void archive_list_load_cb(void* context, uint32_t list_load_offset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
archive_list_item_cb(void* context, FuriString* item_path, bool is_folder, bool is_last) {
|
archive_list_item_cb(void* context, FuriString* item_path, uint32_t idx, bool is_folder, bool is_last) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
|
UNUSED(idx);
|
||||||
ArchiveBrowserView* browser = (ArchiveBrowserView*)context;
|
ArchiveBrowserView* browser = (ArchiveBrowserView*)context;
|
||||||
|
|
||||||
if(!is_last) {
|
if(!is_last) {
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ typedef enum {
|
|||||||
} BrowserItemType;
|
} BrowserItemType;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
uint32_t unsorted_idx;
|
||||||
FuriString* path;
|
FuriString* path;
|
||||||
BrowserItemType type;
|
BrowserItemType type;
|
||||||
uint8_t* custom_icon_data;
|
uint8_t* custom_icon_data;
|
||||||
@@ -41,6 +42,7 @@ typedef struct {
|
|||||||
} BrowserItem_t;
|
} BrowserItem_t;
|
||||||
|
|
||||||
static void BrowserItem_t_init(BrowserItem_t* obj) {
|
static void BrowserItem_t_init(BrowserItem_t* obj) {
|
||||||
|
obj->unsorted_idx = 0;
|
||||||
obj->type = BrowserItemTypeLoading;
|
obj->type = BrowserItemTypeLoading;
|
||||||
obj->path = furi_string_alloc();
|
obj->path = furi_string_alloc();
|
||||||
obj->display_name = furi_string_alloc();
|
obj->display_name = furi_string_alloc();
|
||||||
@@ -48,6 +50,7 @@ static void BrowserItem_t_init(BrowserItem_t* obj) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void BrowserItem_t_init_set(BrowserItem_t* obj, const BrowserItem_t* src) {
|
static void BrowserItem_t_init_set(BrowserItem_t* obj, const BrowserItem_t* src) {
|
||||||
|
obj->unsorted_idx = src->unsorted_idx;
|
||||||
obj->type = src->type;
|
obj->type = src->type;
|
||||||
obj->path = furi_string_alloc_set(src->path);
|
obj->path = furi_string_alloc_set(src->path);
|
||||||
obj->display_name = furi_string_alloc_set(src->display_name);
|
obj->display_name = furi_string_alloc_set(src->display_name);
|
||||||
@@ -60,6 +63,7 @@ static void BrowserItem_t_init_set(BrowserItem_t* obj, const BrowserItem_t* src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void BrowserItem_t_set(BrowserItem_t* obj, const BrowserItem_t* src) {
|
static void BrowserItem_t_set(BrowserItem_t* obj, const BrowserItem_t* src) {
|
||||||
|
obj->unsorted_idx = src->unsorted_idx;
|
||||||
obj->type = src->type;
|
obj->type = src->type;
|
||||||
furi_string_set(obj->path, src->path);
|
furi_string_set(obj->path, src->path);
|
||||||
furi_string_set(obj->display_name, src->display_name);
|
furi_string_set(obj->display_name, src->display_name);
|
||||||
@@ -158,7 +162,7 @@ static void
|
|||||||
browser_folder_open_cb(void* context, uint32_t item_cnt, int32_t file_idx, bool is_root);
|
browser_folder_open_cb(void* context, uint32_t item_cnt, int32_t file_idx, bool is_root);
|
||||||
static void browser_list_load_cb(void* context, uint32_t list_load_offset);
|
static void browser_list_load_cb(void* context, uint32_t list_load_offset);
|
||||||
static void
|
static void
|
||||||
browser_list_item_cb(void* context, FuriString* item_path, bool is_folder, bool is_last);
|
browser_list_item_cb(void* context, FuriString* item_path, uint32_t idx, bool is_folder, bool is_last);
|
||||||
static void browser_long_load_cb(void* context);
|
static void browser_long_load_cb(void* context);
|
||||||
|
|
||||||
static void file_browser_scroll_timer_callback(void* context) {
|
static void file_browser_scroll_timer_callback(void* context) {
|
||||||
@@ -413,12 +417,13 @@ static void browser_list_load_cb(void* context, uint32_t list_load_offset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
browser_list_item_cb(void* context, FuriString* item_path, bool is_folder, bool is_last) {
|
browser_list_item_cb(void* context, FuriString* item_path, uint32_t idx, bool is_folder, bool is_last) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
FileBrowser* browser = (FileBrowser*)context;
|
FileBrowser* browser = (FileBrowser*)context;
|
||||||
|
|
||||||
BrowserItem_t item;
|
BrowserItem_t item;
|
||||||
item.custom_icon_data = NULL;
|
item.custom_icon_data = NULL;
|
||||||
|
item.unsorted_idx = idx;
|
||||||
|
|
||||||
if(!is_last) {
|
if(!is_last) {
|
||||||
item.path = furi_string_alloc_set(item_path);
|
item.path = furi_string_alloc_set(item_path);
|
||||||
@@ -465,10 +470,23 @@ static void
|
|||||||
browser->view,
|
browser->view,
|
||||||
FileBrowserModel * model,
|
FileBrowserModel * model,
|
||||||
{
|
{
|
||||||
|
FuriString* selected = NULL;
|
||||||
|
if(model->item_idx > 0) {
|
||||||
|
selected = furi_string_alloc_set(items_array_get(model->items, model->item_idx)->path);
|
||||||
|
}
|
||||||
items_array_sort(model->items);
|
items_array_sort(model->items);
|
||||||
|
if(selected) {
|
||||||
|
for(uint32_t i = 0; i < model->item_cnt; i++) {
|
||||||
|
if(!furi_string_cmp(items_array_get(model->items, i)->path, selected)) {
|
||||||
|
model->item_idx = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
model->list_loading = false;
|
model->list_loading = false;
|
||||||
},
|
},
|
||||||
true);
|
true);
|
||||||
|
browser_update_offset(browser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -667,10 +685,7 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
|
|||||||
if(browser_is_item_in_array(model, model->item_idx)) {
|
if(browser_is_item_in_array(model, model->item_idx)) {
|
||||||
selected_item =
|
selected_item =
|
||||||
items_array_get(model->items, model->item_idx - model->array_offset);
|
items_array_get(model->items, model->item_idx - model->array_offset);
|
||||||
select_index = model->item_idx;
|
select_index = selected_item->unsorted_idx;
|
||||||
if((!model->is_root) && (select_index > 0)) {
|
|
||||||
select_index -= 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
false);
|
false);
|
||||||
|
|||||||
@@ -247,13 +247,13 @@ static bool
|
|||||||
furi_string_printf(name_str, "%s/%s", furi_string_get_cstr(path), name_temp);
|
furi_string_printf(name_str, "%s/%s", furi_string_get_cstr(path), name_temp);
|
||||||
if(browser->list_item_cb) {
|
if(browser->list_item_cb) {
|
||||||
browser->list_item_cb(
|
browser->list_item_cb(
|
||||||
browser->cb_ctx, name_str, (file_info.flags & FSF_DIRECTORY), false);
|
browser->cb_ctx, name_str, items_cnt, (file_info.flags & FSF_DIRECTORY), false);
|
||||||
}
|
}
|
||||||
items_cnt++;
|
items_cnt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(browser->list_item_cb) {
|
if(browser->list_item_cb) {
|
||||||
browser->list_item_cb(browser->cb_ctx, NULL, false, true);
|
browser->list_item_cb(browser->cb_ctx, NULL, 0, false, true);
|
||||||
}
|
}
|
||||||
ret = true;
|
ret = true;
|
||||||
} while(0);
|
} while(0);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ typedef void (*BrowserWorkerListLoadCallback)(void* context, uint32_t list_load_
|
|||||||
typedef void (*BrowserWorkerListItemCallback)(
|
typedef void (*BrowserWorkerListItemCallback)(
|
||||||
void* context,
|
void* context,
|
||||||
FuriString* item_path,
|
FuriString* item_path,
|
||||||
|
uint32_t idx,
|
||||||
bool is_folder,
|
bool is_folder,
|
||||||
bool is_last);
|
bool is_last);
|
||||||
typedef void (*BrowserWorkerLongLoadCallback)(void* context);
|
typedef void (*BrowserWorkerLongLoadCallback)(void* context);
|
||||||
|
|||||||
Reference in New Issue
Block a user