mirror of
https://github.com/lvgl/lvgl.git
synced 2024-11-27 03:33:48 +08:00
fix(file_explorer): fix navigation handling (#7124)
Co-authored-by: Liam <30486941+liamHowatt@users.noreply.github.com>
This commit is contained in:
parent
3963ee2bdd
commit
b1dc25a9af
@ -19,6 +19,7 @@ static void file_explorer_event_handler(lv_event_t * e)
|
||||
}
|
||||
}
|
||||
|
||||
#if LV_FILE_EXPLORER_QUICK_ACCESS
|
||||
static void btn_event_handler(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
@ -50,6 +51,7 @@ static void dd_event_handler(lv_event_t * e)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void lv_example_file_explorer_2(void)
|
||||
{
|
||||
@ -100,6 +102,7 @@ void lv_example_file_explorer_2(void)
|
||||
|
||||
lv_obj_add_event_cb(file_explorer, file_explorer_event_handler, LV_EVENT_ALL, NULL);
|
||||
|
||||
#if LV_FILE_EXPLORER_QUICK_ACCESS
|
||||
/*Quick access status control button*/
|
||||
lv_obj_t * fe_quick_access_obj = lv_file_explorer_get_quick_access_area(file_explorer);
|
||||
lv_obj_t * fe_header_obj = lv_file_explorer_get_header(file_explorer);
|
||||
@ -127,6 +130,7 @@ void lv_example_file_explorer_2(void)
|
||||
lv_obj_align(dd, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
|
||||
lv_obj_add_event_cb(dd, dd_event_handler, LV_EVENT_VALUE_CHANGED, file_explorer);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -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
|
||||
**********************/
|
||||
@ -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);
|
||||
|
||||
str_fn = str_fn + 5;
|
||||
if((lv_strcmp(str_fn, ".") == 0)) return;
|
||||
selected_text = selected_text + 5; /* skip table cell format */
|
||||
|
||||
if((lv_strcmp(str_fn, "..") == 0) && (lv_strlen(explorer->current_path) > 3)) {
|
||||
/* 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(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;
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -604,7 +623,7 @@ static void show_dir(lv_obj_t * obj, const char * path)
|
||||
lv_label_set_text_fmt(explorer->path_label, LV_SYMBOL_EYE_OPEN" %s", path);
|
||||
|
||||
size_t current_path_len = lv_strlen(explorer->current_path);
|
||||
if((*((explorer->current_path) + current_path_len) != '/') && (current_path_len < LV_FILE_EXPLORER_PATH_MAX_LEN)) {
|
||||
if((explorer->current_path[current_path_len - 1] != '/') && (current_path_len < LV_FILE_EXPLORER_PATH_MAX_LEN)) {
|
||||
*((explorer->current_path) + current_path_len) = '/';
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user