[FL-2491] File browser GUI module (#1237)
* File browser module and test app * nfc: Add support for saved files in subdirectories * nfc: Use helper function to get shadow path when loading data * File browser dialog integration pt.1 * File browser dialog integration pt.2 * Gui,Dialogs: drop file select * Correct use of dynamic string_t(string_ptr) Co-authored-by: Yukai Li <yukaili.geek@gmail.com> Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#include "file_browser_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const file_browser_scene_on_enter_handlers[])(void*) = {
|
||||
#include "file_browser_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const file_browser_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "file_browser_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const file_browser_scene_on_exit_handlers[])(void* context) = {
|
||||
#include "file_browser_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers file_browser_scene_handlers = {
|
||||
.on_enter_handlers = file_browser_scene_on_enter_handlers,
|
||||
.on_event_handlers = file_browser_scene_on_event_handlers,
|
||||
.on_exit_handlers = file_browser_scene_on_exit_handlers,
|
||||
.scene_num = FileBrowserSceneNum,
|
||||
};
|
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) FileBrowserScene##id,
|
||||
typedef enum {
|
||||
#include "file_browser_scene_config.h"
|
||||
FileBrowserSceneNum,
|
||||
} FileBrowserScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers file_browser_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "file_browser_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||
#include "file_browser_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||
#include "file_browser_scene_config.h"
|
||||
#undef ADD_SCENE
|
@@ -0,0 +1,43 @@
|
||||
#include "../file_browser_app_i.h"
|
||||
#include "furi/check.h"
|
||||
#include "furi/log.h"
|
||||
#include "furi_hal.h"
|
||||
#include "m-string.h"
|
||||
|
||||
#define DEFAULT_PATH "/"
|
||||
#define EXTENSION "*"
|
||||
|
||||
bool file_browser_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
FileBrowserApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
scene_manager_next_scene(app->scene_manager, FileBrowserSceneResult);
|
||||
consumed = true;
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
static void file_browser_callback(void* context) {
|
||||
FileBrowserApp* app = context;
|
||||
furi_assert(app);
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, SceneManagerEventTypeCustom);
|
||||
}
|
||||
|
||||
void file_browser_scene_browser_on_enter(void* context) {
|
||||
FileBrowserApp* app = context;
|
||||
|
||||
file_browser_set_callback(app->file_browser, file_browser_callback, app);
|
||||
|
||||
file_browser_start(app->file_browser, app->file_path);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, FileBrowserAppViewBrowser);
|
||||
}
|
||||
|
||||
void file_browser_scene_browser_on_exit(void* context) {
|
||||
FileBrowserApp* app = context;
|
||||
|
||||
file_browser_stop(app->file_browser);
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
ADD_SCENE(file_browser, start, Start)
|
||||
ADD_SCENE(file_browser, browser, Browser)
|
||||
ADD_SCENE(file_browser, result, Result)
|
@@ -0,0 +1,36 @@
|
||||
#include "../file_browser_app_i.h"
|
||||
#include "furi_hal.h"
|
||||
#include "m-string.h"
|
||||
|
||||
void file_browser_scene_result_ok_callback(InputType type, void* context) {
|
||||
furi_assert(context);
|
||||
FileBrowserApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, type);
|
||||
}
|
||||
|
||||
bool file_browser_scene_result_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
//FileBrowserApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void file_browser_scene_result_on_enter(void* context) {
|
||||
FileBrowserApp* app = context;
|
||||
|
||||
widget_add_string_multiline_element(
|
||||
app->widget, 64, 10, AlignCenter, AlignTop, FontSecondary, string_get_cstr(app->file_path));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, FileBrowserAppViewResult);
|
||||
}
|
||||
|
||||
void file_browser_scene_result_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
FileBrowserApp* app = context;
|
||||
widget_reset(app->widget);
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
#include "../file_browser_app_i.h"
|
||||
#include "furi_hal.h"
|
||||
#include "gui/modules/widget_elements/widget_element_i.h"
|
||||
|
||||
static void
|
||||
file_browser_scene_start_ok_callback(GuiButtonType result, InputType type, void* context) {
|
||||
UNUSED(result);
|
||||
furi_assert(context);
|
||||
FileBrowserApp* app = context;
|
||||
if(type == InputTypeShort) {
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, type);
|
||||
}
|
||||
}
|
||||
|
||||
bool file_browser_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
FileBrowserApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
string_set_str(app->file_path, "/any/badusb/demo_windows.txt");
|
||||
scene_manager_next_scene(app->scene_manager, FileBrowserSceneBrowser);
|
||||
consumed = true;
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void file_browser_scene_start_on_enter(void* context) {
|
||||
FileBrowserApp* app = context;
|
||||
|
||||
widget_add_string_multiline_element(
|
||||
app->widget, 64, 20, AlignCenter, AlignTop, FontSecondary, "Press OK to start");
|
||||
|
||||
widget_add_button_element(
|
||||
app->widget, GuiButtonTypeCenter, "Ok", file_browser_scene_start_ok_callback, app);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, FileBrowserAppViewStart);
|
||||
}
|
||||
|
||||
void file_browser_scene_start_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
FileBrowserApp* app = context;
|
||||
widget_reset(app->widget);
|
||||
}
|
Reference in New Issue
Block a user