[FL-3001] File browser base folder (#2091)
* File browser base folder * Format sources * FuriHal: bump api version Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -14,6 +14,7 @@ void dialog_file_browser_set_basic_options(
|
||||
options->hide_ext = true;
|
||||
options->item_loader_callback = NULL;
|
||||
options->item_loader_context = NULL;
|
||||
options->base_path = NULL;
|
||||
}
|
||||
|
||||
static DialogsApp* dialogs_app_alloc() {
|
||||
|
@@ -18,6 +18,7 @@ typedef struct DialogsApp DialogsApp;
|
||||
/**
|
||||
* File browser dialog extra options
|
||||
* @param extension file extension to be offered for selection
|
||||
* @param base_path root folder path for navigation with back key
|
||||
* @param skip_assets true - do not show assets folders
|
||||
* @param hide_dot_files true - hide dot files
|
||||
* @param icon file icon pointer, NULL for default icon
|
||||
@@ -27,6 +28,7 @@ typedef struct DialogsApp DialogsApp;
|
||||
*/
|
||||
typedef struct {
|
||||
const char* extension;
|
||||
const char* base_path;
|
||||
bool skip_assets;
|
||||
bool hide_dot_files;
|
||||
const Icon* icon;
|
||||
|
@@ -24,6 +24,7 @@ bool dialog_file_browser_show(
|
||||
.preselected_filename = path,
|
||||
.item_callback = options ? options->item_loader_callback : NULL,
|
||||
.item_callback_context = options ? options->item_loader_context : NULL,
|
||||
.base_path = options ? options->base_path : NULL,
|
||||
}};
|
||||
|
||||
DialogsAppReturn return_data;
|
||||
|
@@ -17,6 +17,7 @@ typedef struct {
|
||||
FuriString* preselected_filename;
|
||||
FileBrowserLoadItemCallback item_callback;
|
||||
void* item_callback_context;
|
||||
const char* base_path;
|
||||
} DialogsAppMessageDataFileBrowser;
|
||||
|
||||
typedef struct {
|
||||
|
@@ -40,6 +40,7 @@ bool dialogs_app_process_module_file_browser(const DialogsAppMessageDataFileBrow
|
||||
file_browser_configure(
|
||||
file_browser,
|
||||
data->extension,
|
||||
data->base_path,
|
||||
data->skip_assets,
|
||||
data->hide_dot_files,
|
||||
data->file_icon,
|
||||
|
@@ -83,6 +83,7 @@ struct FileBrowser {
|
||||
View* view;
|
||||
BrowserWorker* worker;
|
||||
const char* ext_filter;
|
||||
const char* base_path;
|
||||
bool skip_assets;
|
||||
bool hide_dot_files;
|
||||
bool hide_ext;
|
||||
@@ -163,6 +164,7 @@ View* file_browser_get_view(FileBrowser* browser) {
|
||||
void file_browser_configure(
|
||||
FileBrowser* browser,
|
||||
const char* extension,
|
||||
const char* base_path,
|
||||
bool skip_assets,
|
||||
bool hide_dot_files,
|
||||
const Icon* file_icon,
|
||||
@@ -172,6 +174,7 @@ void file_browser_configure(
|
||||
browser->ext_filter = extension;
|
||||
browser->skip_assets = skip_assets;
|
||||
browser->hide_ext = hide_ext;
|
||||
browser->base_path = base_path;
|
||||
browser->hide_dot_files = hide_dot_files;
|
||||
|
||||
with_view_model(
|
||||
@@ -187,7 +190,11 @@ void file_browser_configure(
|
||||
void file_browser_start(FileBrowser* browser, FuriString* path) {
|
||||
furi_assert(browser);
|
||||
browser->worker = file_browser_worker_alloc(
|
||||
path, browser->ext_filter, browser->skip_assets, browser->hide_dot_files);
|
||||
path,
|
||||
browser->base_path,
|
||||
browser->ext_filter,
|
||||
browser->skip_assets,
|
||||
browser->hide_dot_files);
|
||||
file_browser_worker_set_callback_context(browser->worker, browser);
|
||||
file_browser_worker_set_folder_callback(browser->worker, browser_folder_open_cb);
|
||||
file_browser_worker_set_list_callback(browser->worker, browser_list_load_cb);
|
||||
|
@@ -29,6 +29,7 @@ View* file_browser_get_view(FileBrowser* browser);
|
||||
void file_browser_configure(
|
||||
FileBrowser* browser,
|
||||
const char* extension,
|
||||
const char* base_path,
|
||||
bool skip_assets,
|
||||
bool hide_dot_files,
|
||||
const Icon* file_icon,
|
||||
|
@@ -371,6 +371,7 @@ static int32_t browser_worker(void* context) {
|
||||
|
||||
BrowserWorker* file_browser_worker_alloc(
|
||||
FuriString* path,
|
||||
const char* base_path,
|
||||
const char* filter_ext,
|
||||
bool skip_assets,
|
||||
bool hide_dot_files) {
|
||||
@@ -381,12 +382,13 @@ BrowserWorker* file_browser_worker_alloc(
|
||||
browser->filter_extension = furi_string_alloc_set(filter_ext);
|
||||
browser->skip_assets = skip_assets;
|
||||
browser->hide_dot_files = hide_dot_files;
|
||||
browser->path_start = furi_string_alloc_set(path);
|
||||
|
||||
browser->path_current = furi_string_alloc_set(path);
|
||||
browser->path_next = furi_string_alloc_set(path);
|
||||
|
||||
if(browser_path_is_file(browser->path_start)) {
|
||||
browser_path_trim(browser->path_start);
|
||||
browser->path_start = furi_string_alloc();
|
||||
if(base_path) {
|
||||
furi_string_set_str(browser->path_start, base_path);
|
||||
}
|
||||
|
||||
browser->thread = furi_thread_alloc_ex("BrowserWorker", 2048, browser_worker, browser);
|
||||
|
@@ -23,6 +23,7 @@ typedef void (*BrowserWorkerLongLoadCallback)(void* context);
|
||||
|
||||
BrowserWorker* file_browser_worker_alloc(
|
||||
FuriString* path,
|
||||
const char* base_path,
|
||||
const char* filter_ext,
|
||||
bool skip_assets,
|
||||
bool hide_dot_files);
|
||||
|
Reference in New Issue
Block a user