Skip to content

Commit

Permalink
fix(file_explorer) Fix navigation handling
Browse files Browse the repository at this point in the history
  • Loading branch information
C47D committed Oct 20, 2024
1 parent f5ef4ae commit 1c1b79d
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions src/others/file_explorer/lv_file_explorer.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

#define quick_access_list_button_style (LV_GLOBAL_DEFAULT()->fe_list_button_style)

#define LV_FILE_NAVIGATION_CURRENT_DIR "."
#define LV_FILE_NAVIGATION_PARENT_DIR ".."

/**********************
* TYPEDEFS
**********************/
Expand Down Expand Up @@ -483,27 +486,43 @@ static void browser_file_event_handler(lv_event_t * e)

if(code == LV_EVENT_VALUE_CHANGED) {
char file_name[LV_FILE_EXPLORER_PATH_MAX_LEN];
const char * str_fn = NULL;
const char * selected_text = NULL;
uint32_t row;
uint32_t col;
uint8_t navigate_to_current_dir = 0;
uint8_t navigate_to_parent_dir = 0;
uint8_t navigate_to_child = 0;

lv_memzero(file_name, sizeof(file_name));
lv_table_get_selected_cell(explorer->file_table, &row, &col);
str_fn = lv_table_get_cell_value(explorer->file_table, row, col);
selected_text = lv_table_get_cell_value(explorer->file_table, row, col);

selected_text = selected_text + 5; // skip table cell format

str_fn = str_fn + 5;
if((lv_strcmp(str_fn, ".") == 0)) return;
/* Three navigation modes are supported:
* - Navigate to current directory
* - Navigate to parent directory
* - Navigate to (current directory) child */
navigate_to_current_dir = (lv_strcmp(selected_text, LV_FILE_NAVIGATION_CURRENT_DIR) == 0);
navigate_to_parent_dir = (lv_strcmp(selected_text, LV_FILE_NAVIGATION_PARENT_DIR) == 0);
navigate_to_child = !navigate_to_parent_dir;

if((lv_strcmp(str_fn, "..") == 0) && (lv_strlen(explorer->current_path) > 3)) {
if(navigate_to_current_dir) return; /* Do nothing */

if((navigate_to_parent_dir) && (lv_strlen(explorer->current_path) > 3)) {
strip_ext(explorer->current_path);
/*Remove the last '/' character*/
strip_ext(explorer->current_path);
lv_snprintf((char *)file_name, sizeof(file_name), "%s", explorer->current_path);
lv_snprintf((char *)file_name, sizeof(file_name), "%s/", explorer->current_path); /* Append / at the end */
}
else {
if(lv_strcmp(str_fn, "..") != 0) {
lv_snprintf((char *)file_name, sizeof(file_name), "%s%s", explorer->current_path, str_fn);
if(navigate_to_child) {
lv_snprintf((char *)file_name, sizeof(file_name), "%s%s", explorer->current_path, selected_text);
}
else if(navigate_to_parent_dir) { /* We are most likely in the drive letter directory, doesn't have parent directory */
return;
}
else { /* Nothing to do*/ }
}

lv_fs_dir_t dir;
Expand All @@ -512,8 +531,8 @@ static void browser_file_event_handler(lv_event_t * e)
show_dir(obj, (char *)file_name);
}
else {
if(lv_strcmp(str_fn, "..") != 0) {
explorer->sel_fn = str_fn;
if(navigate_to_child) {
explorer->sel_fn = selected_text;
lv_obj_send_event(obj, LV_EVENT_VALUE_CHANGED, NULL);
}
}
Expand Down

0 comments on commit 1c1b79d

Please sign in to comment.