[FL-1465] Archive application bug fixes. Gui: update TextInput API. (#530)
* Update MLib to latest master. * Archive: update string_t usage, add unsafe usage TODO, change model type to blocking and fix invalid usage. * Gui: update text_input API and it's usage. * fix blocking model issues * fix unsafe string_t usage Co-authored-by: Igor Baranov <bedtimeposts@gmail.com> Co-authored-by: its your bedtime <23366927+itsyourbedtime@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									ed75bc2c39
								
							
						
					
					
						commit
						4cf000f270
					
				@ -5,30 +5,29 @@ static bool archive_get_filenames(ArchiveApp* archive);
 | 
				
			|||||||
static void update_offset(ArchiveApp* archive) {
 | 
					static void update_offset(ArchiveApp* archive) {
 | 
				
			||||||
    furi_assert(archive);
 | 
					    furi_assert(archive);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ArchiveViewModel* model = view_get_model(archive->view_archive_main);
 | 
					    with_view_model(
 | 
				
			||||||
    size_t array_size = files_array_size(model->files);
 | 
					        archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
    uint16_t bounds = array_size > 3 ? 2 : array_size;
 | 
					            size_t array_size = files_array_size(model->files);
 | 
				
			||||||
 | 
					            uint16_t bounds = array_size > 3 ? 2 : array_size;
 | 
				
			||||||
    if(model->list_offset < model->idx - bounds) {
 | 
					            if(model->list_offset < model->idx - bounds) {
 | 
				
			||||||
        model->list_offset = CLAMP(model->list_offset + 1, array_size - (bounds + 2), 0);
 | 
					                model->list_offset = CLAMP(model->list_offset + 1, array_size - (bounds + 2), 0);
 | 
				
			||||||
    } else if(model->list_offset > model->idx - bounds) {
 | 
					            } else if(model->list_offset > model->idx - bounds) {
 | 
				
			||||||
        model->list_offset = CLAMP(model->idx - 1, array_size - (bounds), 0);
 | 
					                model->list_offset = CLAMP(model->idx - 1, array_size - (bounds), 0);
 | 
				
			||||||
    }
 | 
					            }
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
    view_commit_model(archive->view_archive_main, true);
 | 
					        });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void archive_update_last_idx(ArchiveApp* archive) {
 | 
					static void archive_update_last_idx(ArchiveApp* archive) {
 | 
				
			||||||
    furi_assert(archive);
 | 
					    furi_assert(archive);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ArchiveViewModel* model = view_get_model(archive->view_archive_main);
 | 
					    with_view_model(
 | 
				
			||||||
 | 
					        archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
    archive->browser.last_idx[archive->browser.depth] =
 | 
					            archive->browser.last_idx[archive->browser.depth] =
 | 
				
			||||||
        CLAMP(model->idx, files_array_size(model->files) - 1, 0);
 | 
					                CLAMP(model->idx, files_array_size(model->files) - 1, 0);
 | 
				
			||||||
    model->idx = 0;
 | 
					            model->idx = 0;
 | 
				
			||||||
    view_commit_model(archive->view_archive_main, true);
 | 
					            return true;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    model = NULL;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void archive_switch_dir(ArchiveApp* archive, const char* path) {
 | 
					static void archive_switch_dir(ArchiveApp* archive, const char* path) {
 | 
				
			||||||
@ -42,13 +41,12 @@ static void archive_switch_dir(ArchiveApp* archive, const char* path) {
 | 
				
			|||||||
static void archive_switch_tab(ArchiveApp* archive) {
 | 
					static void archive_switch_tab(ArchiveApp* archive) {
 | 
				
			||||||
    furi_assert(archive);
 | 
					    furi_assert(archive);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ArchiveViewModel* model = view_get_model(archive->view_archive_main);
 | 
					    with_view_model(
 | 
				
			||||||
 | 
					        archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
    model->tab_idx = archive->browser.tab_id;
 | 
					            model->tab_idx = archive->browser.tab_id;
 | 
				
			||||||
    model->idx = 0;
 | 
					            model->idx = 0;
 | 
				
			||||||
    view_commit_model(archive->view_archive_main, true);
 | 
					            return true;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    model = NULL;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    archive->browser.depth = 0;
 | 
					    archive->browser.depth = 0;
 | 
				
			||||||
    archive_switch_dir(archive, tab_default_paths[archive->browser.tab_id]);
 | 
					    archive_switch_dir(archive, tab_default_paths[archive->browser.tab_id]);
 | 
				
			||||||
@ -59,23 +57,23 @@ static void archive_switch_tab(ArchiveApp* archive) {
 | 
				
			|||||||
static void archive_leave_dir(ArchiveApp* archive) {
 | 
					static void archive_leave_dir(ArchiveApp* archive) {
 | 
				
			||||||
    furi_assert(archive);
 | 
					    furi_assert(archive);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    char* path_ptr = stringi_get_cstr(archive->browser.path);
 | 
					    size_t last_char =
 | 
				
			||||||
    char* last_char = strrchr(path_ptr, '/');
 | 
					        string_search_rchar(archive->browser.path, '/', string_size(archive->browser.path));
 | 
				
			||||||
    if(last_char) path_ptr[last_char - path_ptr] = '\0';
 | 
					    if(last_char) {
 | 
				
			||||||
 | 
					        string_right(archive->browser.path, last_char);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    archive->browser.depth = CLAMP(archive->browser.depth - 1, MAX_DEPTH, 0);
 | 
					    archive->browser.depth = CLAMP(archive->browser.depth - 1, MAX_DEPTH, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ArchiveViewModel* model = view_get_model(archive->view_archive_main);
 | 
					    with_view_model(
 | 
				
			||||||
    model->idx = archive->browser.last_idx[archive->browser.depth];
 | 
					        archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
    view_commit_model(archive->view_archive_main, true);
 | 
					            model->idx = archive->browser.last_idx[archive->browser.depth];
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    archive_switch_dir(archive, string_get_cstr(archive->browser.path));
 | 
					    archive_switch_dir(archive, string_get_cstr(archive->browser.path));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    update_offset(archive);
 | 
					    update_offset(archive);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    model = NULL;
 | 
					 | 
				
			||||||
    path_ptr = NULL;
 | 
					 | 
				
			||||||
    last_char = NULL;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void archive_enter_dir(ArchiveApp* archive, string_t name) {
 | 
					static void archive_enter_dir(ArchiveApp* archive, string_t name) {
 | 
				
			||||||
@ -93,7 +91,7 @@ static void archive_enter_dir(ArchiveApp* archive, string_t name) {
 | 
				
			|||||||
    update_offset(archive);
 | 
					    update_offset(archive);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool filter_by_extension(ArchiveApp* archive, FileInfo* file_info, char* name) {
 | 
					static bool filter_by_extension(ArchiveApp* archive, FileInfo* file_info, const char* name) {
 | 
				
			||||||
    furi_assert(archive);
 | 
					    furi_assert(archive);
 | 
				
			||||||
    furi_assert(file_info);
 | 
					    furi_assert(file_info);
 | 
				
			||||||
    furi_assert(name);
 | 
					    furi_assert(name);
 | 
				
			||||||
@ -134,54 +132,62 @@ static bool archive_get_filenames(ArchiveApp* archive) {
 | 
				
			|||||||
    ArchiveFile_t item;
 | 
					    ArchiveFile_t item;
 | 
				
			||||||
    FileInfo file_info;
 | 
					    FileInfo file_info;
 | 
				
			||||||
    File directory;
 | 
					    File directory;
 | 
				
			||||||
    string_t name;
 | 
					    char name[MAX_NAME_LEN];
 | 
				
			||||||
    bool result;
 | 
					    bool result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    string_init_printf(name, "%0*d\n", MAX_NAME_LEN, 0);
 | 
					 | 
				
			||||||
    result = dir_api->open(&directory, string_get_cstr(archive->browser.path));
 | 
					    result = dir_api->open(&directory, string_get_cstr(archive->browser.path));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ArchiveViewModel* model = view_get_model(archive->view_archive_main);
 | 
					    with_view_model(
 | 
				
			||||||
    files_array_clear(model->files);
 | 
					        archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
 | 
					            files_array_clean(model->files);
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(!result) {
 | 
					    if(!result) {
 | 
				
			||||||
        dir_api->close(&directory);
 | 
					        dir_api->close(&directory);
 | 
				
			||||||
        string_clear(name);
 | 
					 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while(1) {
 | 
					    while(1) {
 | 
				
			||||||
        char* name_ptr = stringi_get_cstr(name);
 | 
					        result = dir_api->read(&directory, &file_info, name, MAX_NAME_LEN);
 | 
				
			||||||
        result = dir_api->read(&directory, &file_info, name_ptr, MAX_NAME_LEN);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(directory.error_id == FSE_NOT_EXIST || name_ptr[0] == 0) {
 | 
					        if(directory.error_id == FSE_NOT_EXIST || name[0] == 0) {
 | 
				
			||||||
            view_commit_model(archive->view_archive_main, true);
 | 
					 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(result) {
 | 
					        if(result) {
 | 
				
			||||||
            if(directory.error_id == FSE_OK) {
 | 
					            uint16_t files_cnt;
 | 
				
			||||||
                if(filter_by_extension(archive, &file_info, name_ptr)) {
 | 
					            with_view_model(
 | 
				
			||||||
 | 
					                archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
 | 
					                    files_cnt = files_array_size(model->files);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    return true;
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if(files_cnt > MAX_FILES) {
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            } else if(directory.error_id == FSE_OK) {
 | 
				
			||||||
 | 
					                if(filter_by_extension(archive, &file_info, name)) {
 | 
				
			||||||
                    ArchiveFile_t_init(&item);
 | 
					                    ArchiveFile_t_init(&item);
 | 
				
			||||||
                    string_init_set(item.name, name);
 | 
					                    string_init_set(item.name, name);
 | 
				
			||||||
                    set_file_type(&item, &file_info);
 | 
					                    set_file_type(&item, &file_info);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    files_array_push_back(model->files, item);
 | 
					                    with_view_model(
 | 
				
			||||||
 | 
					                        archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
 | 
					                            files_array_push_back(model->files, item);
 | 
				
			||||||
 | 
					                            return true;
 | 
				
			||||||
 | 
					                        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    ArchiveFile_t_clear(&item);
 | 
					                    ArchiveFile_t_clear(&item);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                dir_api->close(&directory);
 | 
					                dir_api->close(&directory);
 | 
				
			||||||
                string_clear(name);
 | 
					 | 
				
			||||||
                view_commit_model(archive->view_archive_main, true);
 | 
					 | 
				
			||||||
                return false;
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    view_commit_model(archive->view_archive_main, true);
 | 
					 | 
				
			||||||
    model = NULL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    dir_api->close(&directory);
 | 
					    dir_api->close(&directory);
 | 
				
			||||||
    string_clear(name);
 | 
					 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -219,9 +225,8 @@ static void archive_add_to_favourites(ArchiveApp* archive) {
 | 
				
			|||||||
    string_clear(buffer_dst);
 | 
					    string_clear(buffer_dst);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void archive_text_input_callback(void* context, char* text) {
 | 
					static void archive_text_input_callback(void* context) {
 | 
				
			||||||
    furi_assert(context);
 | 
					    furi_assert(context);
 | 
				
			||||||
    furi_assert(text);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ArchiveApp* archive = (ArchiveApp*)context;
 | 
					    ArchiveApp* archive = (ArchiveApp*)context;
 | 
				
			||||||
    FS_Common_Api* common_api = &archive->fs_api->common;
 | 
					    FS_Common_Api* common_api = &archive->fs_api->common;
 | 
				
			||||||
@ -236,17 +241,20 @@ static void archive_text_input_callback(void* context, char* text) {
 | 
				
			|||||||
    string_cat(buffer_dst, "/");
 | 
					    string_cat(buffer_dst, "/");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    string_cat(buffer_src, archive->browser.name);
 | 
					    string_cat(buffer_src, archive->browser.name);
 | 
				
			||||||
    string_cat_str(buffer_dst, text);
 | 
					    string_cat_str(buffer_dst, archive->browser.text_input_buffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // append extension
 | 
					    // append extension
 | 
				
			||||||
    ArchiveViewModel* model = view_get_model(archive->view_archive_main);
 | 
					 | 
				
			||||||
    ArchiveFile_t* file =
 | 
					 | 
				
			||||||
        files_array_get(model->files, CLAMP(model->idx, files_array_size(model->files) - 1, 0));
 | 
					 | 
				
			||||||
    string_cat(buffer_src, known_ext[file->type]);
 | 
					 | 
				
			||||||
    string_cat(buffer_dst, known_ext[file->type]);
 | 
					 | 
				
			||||||
    model = NULL;
 | 
					 | 
				
			||||||
    file = NULL;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ArchiveFile_t* file;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    with_view_model(
 | 
				
			||||||
 | 
					        archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
 | 
					            file = files_array_get(
 | 
				
			||||||
 | 
					                model->files, CLAMP(model->idx, files_array_size(model->files) - 1, 0));
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    string_cat(buffer_dst, known_ext[file->type]);
 | 
				
			||||||
    common_api->rename(string_get_cstr(buffer_src), string_get_cstr(buffer_dst));
 | 
					    common_api->rename(string_get_cstr(buffer_src), string_get_cstr(buffer_dst));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewMain);
 | 
					    view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewMain);
 | 
				
			||||||
@ -256,22 +264,25 @@ static void archive_text_input_callback(void* context, char* text) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    archive_get_filenames(archive);
 | 
					    archive_get_filenames(archive);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void archive_enter_text_input(ArchiveApp* archive) {
 | 
					static void archive_enter_text_input(ArchiveApp* archive) {
 | 
				
			||||||
    furi_assert(archive);
 | 
					    furi_assert(archive);
 | 
				
			||||||
 | 
					    *archive->browser.text_input_buffer = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    string_set(archive->browser.text_input_buffer, archive->browser.name);
 | 
					    strlcpy(
 | 
				
			||||||
 | 
					        archive->browser.text_input_buffer,
 | 
				
			||||||
 | 
					        string_get_cstr(archive->browser.name),
 | 
				
			||||||
 | 
					        string_size(archive->browser.name));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    archive_trim_file_ext(archive->browser.text_input_buffer);
 | 
					    archive_trim_file_ext(archive->browser.text_input_buffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    char* text_input_buffer_ptr = stringi_get_cstr(archive->browser.text_input_buffer);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    text_input_set_header_text(archive->text_input, "Rename:");
 | 
					    text_input_set_header_text(archive->text_input, "Rename:");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    text_input_set_result_callback(
 | 
					    text_input_set_result_callback(
 | 
				
			||||||
        archive->text_input,
 | 
					        archive->text_input,
 | 
				
			||||||
        archive_text_input_callback,
 | 
					        archive_text_input_callback,
 | 
				
			||||||
        archive,
 | 
					        archive,
 | 
				
			||||||
        text_input_buffer_ptr,
 | 
					        archive->browser.text_input_buffer,
 | 
				
			||||||
        MAX_NAME_LEN);
 | 
					        MAX_NAME_LEN);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewTextInput);
 | 
					    view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewTextInput);
 | 
				
			||||||
@ -282,10 +293,12 @@ static void archive_show_file_menu(ArchiveApp* archive) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    archive->browser.menu = true;
 | 
					    archive->browser.menu = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ArchiveViewModel* model = view_get_model(archive->view_archive_main);
 | 
					    with_view_model(
 | 
				
			||||||
    model->menu = true;
 | 
					        archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
    model->menu_idx = 0;
 | 
					            model->menu = true;
 | 
				
			||||||
    view_commit_model(archive->view_archive_main, true);
 | 
					            model->menu_idx = 0;
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void archive_close_file_menu(ArchiveApp* archive) {
 | 
					static void archive_close_file_menu(ArchiveApp* archive) {
 | 
				
			||||||
@ -293,10 +306,12 @@ static void archive_close_file_menu(ArchiveApp* archive) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    archive->browser.menu = false;
 | 
					    archive->browser.menu = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ArchiveViewModel* model = view_get_model(archive->view_archive_main);
 | 
					    with_view_model(
 | 
				
			||||||
    model->menu = false;
 | 
					        archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
    model->menu_idx = 0;
 | 
					            model->menu = false;
 | 
				
			||||||
    view_commit_model(archive->view_archive_main, true);
 | 
					            model->menu_idx = 0;
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void archive_open_app(ArchiveApp* archive, const char* app_name, const char* args) {
 | 
					static void archive_open_app(ArchiveApp* archive, const char* app_name, const char* args) {
 | 
				
			||||||
@ -324,18 +339,27 @@ static void archive_delete_file(ArchiveApp* archive, string_t name) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    update_offset(archive);
 | 
					    update_offset(archive);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ArchiveViewModel* model = view_get_model(archive->view_archive_main);
 | 
					    with_view_model(
 | 
				
			||||||
    model->idx = CLAMP(model->idx, files_array_size(model->files) - 1, 0);
 | 
					        archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
    view_commit_model(archive->view_archive_main, true);
 | 
					            model->idx = CLAMP(model->idx, files_array_size(model->files) - 1, 0);
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void archive_file_menu_callback(ArchiveApp* archive) {
 | 
					static void archive_file_menu_callback(ArchiveApp* archive) {
 | 
				
			||||||
    furi_assert(archive);
 | 
					    furi_assert(archive);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ArchiveViewModel* model = view_get_model(archive->view_archive_main);
 | 
					    ArchiveFile_t* selected;
 | 
				
			||||||
    ArchiveFile_t* selected = files_array_get(model->files, model->idx);
 | 
					    uint8_t idx = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    switch(model->menu_idx) {
 | 
					    with_view_model(
 | 
				
			||||||
 | 
					        archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
 | 
					            selected = files_array_get(model->files, model->idx);
 | 
				
			||||||
 | 
					            idx = model->menu_idx;
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    switch(idx) {
 | 
				
			||||||
    case 0:
 | 
					    case 0:
 | 
				
			||||||
        if((selected->type != ArchiveFileTypeFolder && selected->type != ArchiveFileTypeUnknown)) {
 | 
					        if((selected->type != ArchiveFileTypeFolder && selected->type != ArchiveFileTypeUnknown)) {
 | 
				
			||||||
            string_t full_path;
 | 
					            string_t full_path;
 | 
				
			||||||
@ -369,8 +393,6 @@ static void archive_file_menu_callback(ArchiveApp* archive) {
 | 
				
			|||||||
        archive_close_file_menu(archive);
 | 
					        archive_close_file_menu(archive);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    model = NULL;
 | 
					 | 
				
			||||||
    selected = NULL;
 | 
					    selected = NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -378,19 +400,25 @@ static void menu_input_handler(ArchiveApp* archive, InputEvent* event) {
 | 
				
			|||||||
    furi_assert(archive);
 | 
					    furi_assert(archive);
 | 
				
			||||||
    furi_assert(archive);
 | 
					    furi_assert(archive);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ArchiveViewModel* model = view_get_model(archive->view_archive_main);
 | 
					 | 
				
			||||||
    if(event->type == InputTypeShort) {
 | 
					    if(event->type == InputTypeShort) {
 | 
				
			||||||
        if(event->key == InputKeyUp) {
 | 
					        if(event->key == InputKeyUp || event->key == InputKeyDown) {
 | 
				
			||||||
            model->menu_idx = CLAMP(model->menu_idx - 1, MENU_ITEMS - 1, 0);
 | 
					            with_view_model(
 | 
				
			||||||
        } else if(event->key == InputKeyDown) {
 | 
					                archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
            model->menu_idx = CLAMP(model->menu_idx + 1, MENU_ITEMS - 1, 0);
 | 
					                    if(event->key == InputKeyUp) {
 | 
				
			||||||
        } else if(event->key == InputKeyOk) {
 | 
					                        model->menu_idx = CLAMP(model->menu_idx - 1, MENU_ITEMS - 1, 0);
 | 
				
			||||||
 | 
					                    } else if(event->key == InputKeyDown) {
 | 
				
			||||||
 | 
					                        model->menu_idx = CLAMP(model->menu_idx + 1, MENU_ITEMS - 1, 0);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    return true;
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(event->key == InputKeyOk) {
 | 
				
			||||||
            archive_file_menu_callback(archive);
 | 
					            archive_file_menu_callback(archive);
 | 
				
			||||||
        } else if(event->key == InputKeyBack) {
 | 
					        } else if(event->key == InputKeyBack) {
 | 
				
			||||||
            archive_close_file_menu(archive);
 | 
					            archive_close_file_menu(archive);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    view_commit_model(archive->view_archive_main, true);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* main controls */
 | 
					/* main controls */
 | 
				
			||||||
@ -400,7 +428,6 @@ static bool archive_view_input(InputEvent* event, void* context) {
 | 
				
			|||||||
    furi_assert(context);
 | 
					    furi_assert(context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ArchiveApp* archive = context;
 | 
					    ArchiveApp* archive = context;
 | 
				
			||||||
    ArchiveViewModel* model = view_get_model(archive->view_archive_main);
 | 
					 | 
				
			||||||
    bool in_menu = archive->browser.menu;
 | 
					    bool in_menu = archive->browser.menu;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(in_menu) {
 | 
					    if(in_menu) {
 | 
				
			||||||
@ -429,72 +456,77 @@ static bool archive_view_input(InputEvent* event, void* context) {
 | 
				
			|||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    if(event->key == InputKeyUp || event->key == InputKeyDown) {
 | 
				
			||||||
    size_t num_elements = files_array_size(model->files) - 1;
 | 
					        with_view_model(
 | 
				
			||||||
    if((event->type == InputTypeShort || event->type == InputTypeRepeat)) {
 | 
					            archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
        if(event->key == InputKeyUp) {
 | 
					                size_t num_elements = files_array_size(model->files) - 1;
 | 
				
			||||||
            model->idx = CLAMP(model->idx - 1, num_elements, 0);
 | 
					                if((event->type == InputTypeShort || event->type == InputTypeRepeat)) {
 | 
				
			||||||
            update_offset(archive);
 | 
					                    if(event->key == InputKeyUp) {
 | 
				
			||||||
            return true;
 | 
					                        model->idx = CLAMP(model->idx - 1, num_elements, 0);
 | 
				
			||||||
        } else if(event->key == InputKeyDown) {
 | 
					                    } else if(event->key == InputKeyDown) {
 | 
				
			||||||
            model->idx = CLAMP(model->idx + 1, num_elements, 0);
 | 
					                        model->idx = CLAMP(model->idx + 1, num_elements, 0);
 | 
				
			||||||
            update_offset(archive);
 | 
					                    }
 | 
				
			||||||
            return true;
 | 
					                }
 | 
				
			||||||
        }
 | 
					                return true;
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        update_offset(archive);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(event->key == InputKeyOk) {
 | 
					    if(event->key == InputKeyOk) {
 | 
				
			||||||
        if(files_array_size(model->files) > 0) {
 | 
					        ArchiveFile_t* selected;
 | 
				
			||||||
            ArchiveFile_t* selected = files_array_get(model->files, model->idx);
 | 
					        with_view_model(
 | 
				
			||||||
            string_set(archive->browser.name, selected->name);
 | 
					            archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
            model = NULL;
 | 
					                if(files_array_size(model->files) > 0) {
 | 
				
			||||||
 | 
					                    selected = files_array_get(model->files, model->idx);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if(selected->type == ArchiveFileTypeFolder) {
 | 
					                return true;
 | 
				
			||||||
                if(event->type == InputTypeShort) {
 | 
					            });
 | 
				
			||||||
                    archive_enter_dir(archive, archive->browser.name);
 | 
					
 | 
				
			||||||
                } else if(event->type == InputTypeLong) {
 | 
					        string_set(archive->browser.name, selected->name);
 | 
				
			||||||
                    archive_show_file_menu(archive);
 | 
					        if(selected->type == ArchiveFileTypeFolder) {
 | 
				
			||||||
                }
 | 
					            if(event->type == InputTypeShort) {
 | 
				
			||||||
            } else {
 | 
					                archive_enter_dir(archive, archive->browser.name);
 | 
				
			||||||
                if(event->type == InputTypeShort) {
 | 
					            } else if(event->type == InputTypeLong) {
 | 
				
			||||||
                    archive_show_file_menu(archive);
 | 
					                archive_show_file_menu(archive);
 | 
				
			||||||
                }
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            if(event->type == InputTypeShort) {
 | 
				
			||||||
 | 
					                archive_show_file_menu(archive);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    update_offset(archive);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void archive_free(ArchiveApp* archive) {
 | 
					void archive_free(ArchiveApp* archive) {
 | 
				
			||||||
    furi_assert(archive);
 | 
					    furi_assert(archive);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ArchiveViewModel* model = view_get_model(archive->view_archive_main);
 | 
					    view_dispatcher_remove_view(archive->view_dispatcher, ArchiveViewMain);
 | 
				
			||||||
    files_array_clear(model->files);
 | 
					    view_dispatcher_remove_view(archive->view_dispatcher, ArchiveViewTextInput);
 | 
				
			||||||
    model = NULL;
 | 
					    view_dispatcher_free(archive->view_dispatcher);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    with_view_model(
 | 
				
			||||||
 | 
					        archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
 | 
					            files_array_clear(model->files);
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    view_free(archive->view_archive_main);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    string_clear(archive->browser.name);
 | 
					    string_clear(archive->browser.name);
 | 
				
			||||||
    string_clear(archive->browser.path);
 | 
					    string_clear(archive->browser.path);
 | 
				
			||||||
    string_clear(archive->browser.text_input_buffer);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    text_input_free(archive->text_input);
 | 
					    text_input_free(archive->text_input);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    furi_record_close("sdcard");
 | 
					    furi_record_close("sdcard");
 | 
				
			||||||
    archive->fs_api = NULL;
 | 
					    archive->fs_api = NULL;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    view_free(archive->view_archive_main);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    view_dispatcher_remove_view(archive->view_dispatcher, ArchiveViewMain);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    view_dispatcher_remove_view(archive->view_dispatcher, ArchiveViewTextInput);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    view_dispatcher_free(archive->view_dispatcher);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    furi_record_close("gui");
 | 
					    furi_record_close("gui");
 | 
				
			||||||
    archive->gui = NULL;
 | 
					    archive->gui = NULL;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    furi_thread_free(archive->app_thread);
 | 
					    furi_thread_free(archive->app_thread);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    furi_check(osMessageQueueDelete(archive->event_queue) == osOK);
 | 
					    furi_check(osMessageQueueDelete(archive->event_queue) == osOK);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    free(archive);
 | 
					    free(archive);
 | 
				
			||||||
@ -503,10 +535,9 @@ void archive_free(ArchiveApp* archive) {
 | 
				
			|||||||
ArchiveApp* archive_alloc() {
 | 
					ArchiveApp* archive_alloc() {
 | 
				
			||||||
    ArchiveApp* archive = furi_alloc(sizeof(ArchiveApp));
 | 
					    ArchiveApp* archive = furi_alloc(sizeof(ArchiveApp));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    archive->event_queue = osMessageQueueNew(2, sizeof(AppEvent), NULL);
 | 
					    archive->event_queue = osMessageQueueNew(8, sizeof(AppEvent), NULL);
 | 
				
			||||||
    archive->app_thread = furi_thread_alloc();
 | 
					    archive->app_thread = furi_thread_alloc();
 | 
				
			||||||
    archive->gui = furi_record_open("gui");
 | 
					    archive->gui = furi_record_open("gui");
 | 
				
			||||||
    archive->view_dispatcher = view_dispatcher_alloc();
 | 
					 | 
				
			||||||
    archive->fs_api = furi_record_open("sdcard");
 | 
					    archive->fs_api = furi_record_open("sdcard");
 | 
				
			||||||
    archive->text_input = text_input_alloc();
 | 
					    archive->text_input = text_input_alloc();
 | 
				
			||||||
    archive->view_archive_main = view_alloc();
 | 
					    archive->view_archive_main = view_alloc();
 | 
				
			||||||
@ -514,13 +545,21 @@ ArchiveApp* archive_alloc() {
 | 
				
			|||||||
    furi_check(archive->event_queue);
 | 
					    furi_check(archive->event_queue);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    view_allocate_model(
 | 
					    view_allocate_model(
 | 
				
			||||||
        archive->view_archive_main, ViewModelTypeLockFree, sizeof(ArchiveViewModel));
 | 
					        archive->view_archive_main, ViewModelTypeLocking, sizeof(ArchiveViewModel));
 | 
				
			||||||
 | 
					    with_view_model(
 | 
				
			||||||
 | 
					        archive->view_archive_main, (ArchiveViewModel * model) {
 | 
				
			||||||
 | 
					            files_array_init(model->files);
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    view_set_context(archive->view_archive_main, archive);
 | 
					    view_set_context(archive->view_archive_main, archive);
 | 
				
			||||||
    view_set_draw_callback(archive->view_archive_main, archive_view_render);
 | 
					    view_set_draw_callback(archive->view_archive_main, archive_view_render);
 | 
				
			||||||
    view_set_input_callback(archive->view_archive_main, archive_view_input);
 | 
					    view_set_input_callback(archive->view_archive_main, archive_view_input);
 | 
				
			||||||
    view_set_previous_callback(
 | 
					    view_set_previous_callback(
 | 
				
			||||||
        text_input_get_view(archive->text_input), archive_previous_callback);
 | 
					        text_input_get_view(archive->text_input), archive_previous_callback);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // View Dispatcher
 | 
				
			||||||
 | 
					    archive->view_dispatcher = view_dispatcher_alloc();
 | 
				
			||||||
    view_dispatcher_add_view(
 | 
					    view_dispatcher_add_view(
 | 
				
			||||||
        archive->view_dispatcher, ArchiveViewMain, archive->view_archive_main);
 | 
					        archive->view_dispatcher, ArchiveViewMain, archive->view_archive_main);
 | 
				
			||||||
    view_dispatcher_add_view(
 | 
					    view_dispatcher_add_view(
 | 
				
			||||||
 | 
				
			|||||||
@ -15,7 +15,7 @@
 | 
				
			|||||||
#include "applications.h"
 | 
					#include "applications.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MAX_DEPTH 32
 | 
					#define MAX_DEPTH 32
 | 
				
			||||||
#define MAX_NAME_LEN 255
 | 
					#define MAX_FILES 100 //temp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef enum {
 | 
					typedef enum {
 | 
				
			||||||
    ArchiveViewMain,
 | 
					    ArchiveViewMain,
 | 
				
			||||||
@ -47,7 +47,7 @@ static const char* known_ext[] = {
 | 
				
			|||||||
    [ArchiveFileTypeNFC] = ".nfc",
 | 
					    [ArchiveFileTypeNFC] = ".nfc",
 | 
				
			||||||
    [ArchiveFileTypeSubOne] = ".sub1",
 | 
					    [ArchiveFileTypeSubOne] = ".sub1",
 | 
				
			||||||
    [ArchiveFileTypeLFRFID] = ".rfid",
 | 
					    [ArchiveFileTypeLFRFID] = ".rfid",
 | 
				
			||||||
    [ArchiveFileTypeIrda] = ".irda",
 | 
					    [ArchiveFileTypeIrda] = ".ir",
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const char* tab_default_paths[] = {
 | 
					static const char* tab_default_paths[] = {
 | 
				
			||||||
@ -94,7 +94,7 @@ typedef struct {
 | 
				
			|||||||
    ArchiveTabEnum tab_id;
 | 
					    ArchiveTabEnum tab_id;
 | 
				
			||||||
    string_t name;
 | 
					    string_t name;
 | 
				
			||||||
    string_t path;
 | 
					    string_t path;
 | 
				
			||||||
    string_t text_input_buffer;
 | 
					    char text_input_buffer[MAX_NAME_LEN];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    uint8_t depth;
 | 
					    uint8_t depth;
 | 
				
			||||||
    uint16_t last_idx[MAX_DEPTH];
 | 
					    uint16_t last_idx[MAX_DEPTH];
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
#include "archive_views.h"
 | 
					#include "archive_views.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const char* ArchiveTabNames[] =
 | 
					static const char* ArchiveTabNames[] =
 | 
				
			||||||
    {"Favourites", "iButton", "NFC", "SubOne", "Rfid", "Infared", "Browser"};
 | 
					    {"Favourites", "iButton", "NFC", "SubOne", "Rfid", "Infrared", "Browser"};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const IconName ArchiveItemIcons[] = {
 | 
					static const IconName ArchiveItemIcons[] = {
 | 
				
			||||||
    [ArchiveFileTypeIButton] = I_ibutt_10px,
 | 
					    [ArchiveFileTypeIButton] = I_ibutt_10px,
 | 
				
			||||||
@ -47,14 +47,13 @@ static void render_item_menu(Canvas* canvas, ArchiveViewModel* model) {
 | 
				
			|||||||
    canvas_draw_icon_name(canvas, 64, 20 + model->menu_idx * 11, I_ButtonRight_4x7);
 | 
					    canvas_draw_icon_name(canvas, 64, 20 + model->menu_idx * 11, I_ButtonRight_4x7);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void archive_trim_file_ext(string_t name) {
 | 
					void archive_trim_file_ext(char* name) {
 | 
				
			||||||
    size_t str_len = string_size(name);
 | 
					    size_t str_len = strlen(name);
 | 
				
			||||||
    char* buff_ptr = stringi_get_cstr(name);
 | 
					    char* end = name + str_len;
 | 
				
			||||||
    char* end = buff_ptr + str_len;
 | 
					    while(end > name && *end != '.' && *end != '\\' && *end != '/') {
 | 
				
			||||||
    while(end > buff_ptr && *end != '.' && *end != '\\' && *end != '/') {
 | 
					 | 
				
			||||||
        --end;
 | 
					        --end;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if((end > buff_ptr && *end == '.') && (*(end - 1) != '\\' && *(end - 1) != '/')) {
 | 
					    if((end > name && *end == '.') && (*(end - 1) != '\\' && *(end - 1) != '/')) {
 | 
				
			||||||
        *end = '\0';
 | 
					        *end = '\0';
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -80,15 +79,17 @@ static void draw_list(Canvas* canvas, ArchiveViewModel* model) {
 | 
				
			|||||||
    bool scrollbar = array_size > 4;
 | 
					    bool scrollbar = array_size > 4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    string_t str_buff;
 | 
					    string_t str_buff;
 | 
				
			||||||
 | 
					    char cstr_buff[MAX_NAME_LEN];
 | 
				
			||||||
    string_init(str_buff);
 | 
					    string_init(str_buff);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for(size_t i = 0; i < MIN(MENU_ITEMS, array_size); ++i) {
 | 
					    for(size_t i = 0; i < MIN(MENU_ITEMS, array_size); ++i) {
 | 
				
			||||||
        size_t idx = CLAMP(i + model->list_offset, array_size, 0);
 | 
					        size_t idx = CLAMP(i + model->list_offset, array_size, 0);
 | 
				
			||||||
        ArchiveFile_t* file = files_array_get(model->files, CLAMP(idx, array_size - 1, 0));
 | 
					        ArchiveFile_t* file = files_array_get(model->files, CLAMP(idx, array_size - 1, 0));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        string_set(str_buff, file->name);
 | 
					        strlcpy(cstr_buff, string_get_cstr(file->name), string_size(file->name));
 | 
				
			||||||
 | 
					        if(is_known_app(file->type)) archive_trim_file_ext(cstr_buff);
 | 
				
			||||||
 | 
					        string_set_str(str_buff, cstr_buff);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(is_known_app(file->type)) archive_trim_file_ext(str_buff);
 | 
					 | 
				
			||||||
        elements_string_fit_width(canvas, str_buff, scrollbar ? MAX_LEN_PX - 6 : MAX_LEN_PX);
 | 
					        elements_string_fit_width(canvas, str_buff, scrollbar ? MAX_LEN_PX - 6 : MAX_LEN_PX);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(model->idx == idx) {
 | 
					        if(model->idx == idx) {
 | 
				
			||||||
@ -98,7 +99,7 @@ static void draw_list(Canvas* canvas, ArchiveViewModel* model) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        canvas_draw_icon_name(canvas, 2, 16 + i * FRAME_HEIGHT, ArchiveItemIcons[file->type]);
 | 
					        canvas_draw_icon_name(canvas, 2, 16 + i * FRAME_HEIGHT, ArchiveItemIcons[file->type]);
 | 
				
			||||||
        canvas_draw_str(canvas, 15, 24 + i * FRAME_HEIGHT, stringi_get_cstr(str_buff));
 | 
					        canvas_draw_str(canvas, 15, 24 + i * FRAME_HEIGHT, string_get_cstr(str_buff));
 | 
				
			||||||
        string_clean(str_buff);
 | 
					        string_clean(str_buff);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,8 @@
 | 
				
			|||||||
#include <filesystem-api.h>
 | 
					#include <filesystem-api.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MAX_LEN_PX 98
 | 
					#define MAX_LEN_PX 98
 | 
				
			||||||
 | 
					#define MAX_NAME_LEN 255
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define FRAME_HEIGHT 12
 | 
					#define FRAME_HEIGHT 12
 | 
				
			||||||
#define MENU_ITEMS 4
 | 
					#define MENU_ITEMS 4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -63,4 +65,4 @@ typedef struct {
 | 
				
			|||||||
} ArchiveViewModel;
 | 
					} ArchiveViewModel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void archive_view_render(Canvas* canvas, void* model);
 | 
					void archive_view_render(Canvas* canvas, void* model);
 | 
				
			||||||
void archive_trim_file_ext(string_t name);
 | 
					void archive_trim_file_ext(char* name);
 | 
				
			||||||
@ -118,7 +118,7 @@ static void dialog_ex_callback(DialogExResult result, void* context) {
 | 
				
			|||||||
    next_view(context);
 | 
					    next_view(context);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void text_input_callback(void* context, char* text) {
 | 
					static void text_input_callback(void* context) {
 | 
				
			||||||
    next_view(context);
 | 
					    next_view(context);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -14,8 +14,8 @@ typedef struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
    const char* header;
 | 
					    const char* header;
 | 
				
			||||||
    char* text;
 | 
					    char* text_buffer;
 | 
				
			||||||
    uint8_t max_text_length;
 | 
					    size_t text_buffer_size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    TextInputCallback callback;
 | 
					    TextInputCallback callback;
 | 
				
			||||||
    void* callback_context;
 | 
					    void* callback_context;
 | 
				
			||||||
@ -128,19 +128,19 @@ static const char char_to_uppercase(const char letter) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void text_input_backspace_cb(TextInputModel* model) {
 | 
					static void text_input_backspace_cb(TextInputModel* model) {
 | 
				
			||||||
    uint8_t text_length = strlen(model->text);
 | 
					    uint8_t text_length = strlen(model->text_buffer);
 | 
				
			||||||
    if(text_length > 0) {
 | 
					    if(text_length > 0) {
 | 
				
			||||||
        model->text[text_length - 1] = 0;
 | 
					        model->text_buffer[text_length - 1] = 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void text_input_view_draw_callback(Canvas* canvas, void* _model) {
 | 
					static void text_input_view_draw_callback(Canvas* canvas, void* _model) {
 | 
				
			||||||
    TextInputModel* model = _model;
 | 
					    TextInputModel* model = _model;
 | 
				
			||||||
    uint8_t text_length = strlen(model->text);
 | 
					    uint8_t text_length = strlen(model->text_buffer);
 | 
				
			||||||
    uint8_t needed_string_width = canvas_width(canvas) - 8;
 | 
					    uint8_t needed_string_width = canvas_width(canvas) - 8;
 | 
				
			||||||
    uint8_t start_pos = 4;
 | 
					    uint8_t start_pos = 4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    char* text = model->text;
 | 
					    const char* text = model->text_buffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    canvas_clear(canvas);
 | 
					    canvas_clear(canvas);
 | 
				
			||||||
    canvas_set_color(canvas, ColorBlack);
 | 
					    canvas_set_color(canvas, ColorBlack);
 | 
				
			||||||
@ -286,20 +286,20 @@ static void text_input_handle_ok(TextInput* text_input) {
 | 
				
			|||||||
    with_view_model(
 | 
					    with_view_model(
 | 
				
			||||||
        text_input->view, (TextInputModel * model) {
 | 
					        text_input->view, (TextInputModel * model) {
 | 
				
			||||||
            char selected = get_selected_char(model);
 | 
					            char selected = get_selected_char(model);
 | 
				
			||||||
            uint8_t text_length = strlen(model->text);
 | 
					            uint8_t text_length = strlen(model->text_buffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if(selected == ENTER_KEY) {
 | 
					            if(selected == ENTER_KEY) {
 | 
				
			||||||
                if(model->callback != 0 && text_length > 0) {
 | 
					                if(model->callback != 0 && text_length > 0) {
 | 
				
			||||||
                    model->callback(model->callback_context, model->text);
 | 
					                    model->callback(model->callback_context);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } else if(selected == BACKSPACE_KEY) {
 | 
					            } else if(selected == BACKSPACE_KEY) {
 | 
				
			||||||
                text_input_backspace_cb(model);
 | 
					                text_input_backspace_cb(model);
 | 
				
			||||||
            } else if(text_length < model->max_text_length) {
 | 
					            } else if(text_length < (model->text_buffer_size - 1)) {
 | 
				
			||||||
                if(text_length == 0 && char_is_lowercase(selected)) {
 | 
					                if(text_length == 0 && char_is_lowercase(selected)) {
 | 
				
			||||||
                    selected = char_to_uppercase(selected);
 | 
					                    selected = char_to_uppercase(selected);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                model->text[text_length] = selected;
 | 
					                model->text_buffer[text_length] = selected;
 | 
				
			||||||
                model->text[text_length + 1] = 0;
 | 
					                model->text_buffer[text_length + 1] = 0;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
@ -361,7 +361,7 @@ TextInput* text_input_alloc() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    with_view_model(
 | 
					    with_view_model(
 | 
				
			||||||
        text_input->view, (TextInputModel * model) {
 | 
					        text_input->view, (TextInputModel * model) {
 | 
				
			||||||
            model->max_text_length = 0;
 | 
					            model->text_buffer_size = 0;
 | 
				
			||||||
            model->header = "";
 | 
					            model->header = "";
 | 
				
			||||||
            model->selected_row = 0;
 | 
					            model->selected_row = 0;
 | 
				
			||||||
            model->selected_column = 0;
 | 
					            model->selected_column = 0;
 | 
				
			||||||
@ -386,14 +386,14 @@ void text_input_set_result_callback(
 | 
				
			|||||||
    TextInput* text_input,
 | 
					    TextInput* text_input,
 | 
				
			||||||
    TextInputCallback callback,
 | 
					    TextInputCallback callback,
 | 
				
			||||||
    void* callback_context,
 | 
					    void* callback_context,
 | 
				
			||||||
    char* text,
 | 
					    char* text_buffer,
 | 
				
			||||||
    uint8_t max_text_length) {
 | 
					    size_t text_buffer_size) {
 | 
				
			||||||
    with_view_model(
 | 
					    with_view_model(
 | 
				
			||||||
        text_input->view, (TextInputModel * model) {
 | 
					        text_input->view, (TextInputModel * model) {
 | 
				
			||||||
            model->callback = callback;
 | 
					            model->callback = callback;
 | 
				
			||||||
            model->callback_context = callback_context;
 | 
					            model->callback_context = callback_context;
 | 
				
			||||||
            model->text = text;
 | 
					            model->text_buffer = text_buffer;
 | 
				
			||||||
            model->max_text_length = max_text_length;
 | 
					            model->text_buffer_size = text_buffer_size;
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -7,7 +7,7 @@ extern "C" {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* Text input anonymous structure */
 | 
					/* Text input anonymous structure */
 | 
				
			||||||
typedef struct TextInput TextInput;
 | 
					typedef struct TextInput TextInput;
 | 
				
			||||||
typedef void (*TextInputCallback)(void* context, char* text);
 | 
					typedef void (*TextInputCallback)(void* context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** 
 | 
					/** 
 | 
				
			||||||
 * @brief Allocate and initialize text input
 | 
					 * @brief Allocate and initialize text input
 | 
				
			||||||
@ -37,15 +37,15 @@ View* text_input_get_view(TextInput* text_input);
 | 
				
			|||||||
 * @param text_input - Text input instance
 | 
					 * @param text_input - Text input instance
 | 
				
			||||||
 * @param callback - callback fn
 | 
					 * @param callback - callback fn
 | 
				
			||||||
 * @param callback_context - callback context
 | 
					 * @param callback_context - callback context
 | 
				
			||||||
 * @param text - text buffer to use
 | 
					 * @param text_buffer - pointer to YOUR text buffer, that we going to modify
 | 
				
			||||||
 * @param max_text_length - text buffer length
 | 
					 * @param text_buffer_size - YOUR text buffer size in bytes. Max string length will be text_buffer_size - 1.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void text_input_set_result_callback(
 | 
					void text_input_set_result_callback(
 | 
				
			||||||
    TextInput* text_input,
 | 
					    TextInput* text_input,
 | 
				
			||||||
    TextInputCallback callback,
 | 
					    TextInputCallback callback,
 | 
				
			||||||
    void* callback_context,
 | 
					    void* callback_context,
 | 
				
			||||||
    char* text,
 | 
					    char* text_buffer,
 | 
				
			||||||
    uint8_t max_text_length);
 | 
					    size_t text_buffer_size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** 
 | 
					/** 
 | 
				
			||||||
 * @brief Set text input header text
 | 
					 * @brief Set text input header text
 | 
				
			||||||
 | 
				
			|||||||
@ -51,7 +51,7 @@ void iButtonSceneSaveName::on_exit(iButtonApp* app) {
 | 
				
			|||||||
    text_input_set_result_callback(text_input, NULL, NULL, NULL, 0);
 | 
					    text_input_set_result_callback(text_input, NULL, NULL, NULL, 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void iButtonSceneSaveName::text_input_callback(void* context, char* text) {
 | 
					void iButtonSceneSaveName::text_input_callback(void* context) {
 | 
				
			||||||
    iButtonApp* app = static_cast<iButtonApp*>(context);
 | 
					    iButtonApp* app = static_cast<iButtonApp*>(context);
 | 
				
			||||||
    iButtonEvent event;
 | 
					    iButtonEvent event;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -8,5 +8,5 @@ public:
 | 
				
			|||||||
    void on_exit(iButtonApp* app) final;
 | 
					    void on_exit(iButtonApp* app) final;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void text_input_callback(void* context, char* text);
 | 
					    void text_input_callback(void* context);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@ -126,7 +126,7 @@ uint8_t IrdaApp::get_text_store_size() {
 | 
				
			|||||||
    return text_store_size;
 | 
					    return text_store_size;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void IrdaApp::text_input_callback(void* context, char* text) {
 | 
					void IrdaApp::text_input_callback(void* context) {
 | 
				
			||||||
    IrdaApp* app = static_cast<IrdaApp*>(context);
 | 
					    IrdaApp* app = static_cast<IrdaApp*>(context);
 | 
				
			||||||
    IrdaAppEvent event;
 | 
					    IrdaAppEvent event;
 | 
				
			||||||
    event.type = IrdaAppEvent::Type::TextEditDone;
 | 
					    event.type = IrdaAppEvent::Type::TextEditDone;
 | 
				
			||||||
 | 
				
			|||||||
@ -82,7 +82,7 @@ public:
 | 
				
			|||||||
    void notify_click();
 | 
					    void notify_click();
 | 
				
			||||||
    void notify_click_and_blink();
 | 
					    void notify_click_and_blink();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static void text_input_callback(void* context, char* text);
 | 
					    static void text_input_callback(void* context);
 | 
				
			||||||
    static void popup_callback(void* context);
 | 
					    static void popup_callback(void* context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    IrdaApp() {
 | 
					    IrdaApp() {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								lib/mlib
									
									
									
									
									
								
							
							
								
								
								
								
								
								
									
									
								
							
						
						
									
										2
									
								
								lib/mlib
									
									
									
									
									
								
							@ -1 +1 @@
 | 
				
			|||||||
Subproject commit a03b2e80c646a7db208a73362a764aa1ac7246fe
 | 
					Subproject commit 3c83e4088ccb6d5513c08a7c6475b3cbdba76796
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user