Archive refactoring WIP (#688)
* view_dispatcher queue * refactoring, all works * scenes Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
30
applications/archive/scenes/archive_scene.c
Normal file
30
applications/archive/scenes/archive_scene.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "archive_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const archive_on_enter_handlers[])(void*) = {
|
||||
#include "archive_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 archive_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "archive_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 archive_on_exit_handlers[])(void* context) = {
|
||||
#include "archive_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers archive_scene_handlers = {
|
||||
.on_enter_handlers = archive_on_enter_handlers,
|
||||
.on_event_handlers = archive_on_event_handlers,
|
||||
.on_exit_handlers = archive_on_exit_handlers,
|
||||
.scene_num = ArchiveAppSceneNum,
|
||||
};
|
29
applications/archive/scenes/archive_scene.h
Normal file
29
applications/archive/scenes/archive_scene.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) ArchiveAppScene##id,
|
||||
typedef enum {
|
||||
#include "archive_scene_config.h"
|
||||
ArchiveAppSceneNum,
|
||||
} ArchiveAppScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers archive_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "archive_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 "archive_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 "archive_scene_config.h"
|
||||
#undef ADD_SCENE
|
42
applications/archive/scenes/archive_scene_browser.c
Normal file
42
applications/archive/scenes/archive_scene_browser.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "../archive_i.h"
|
||||
#include "../views/archive_main_view.h"
|
||||
|
||||
void archive_scene_browser_callback(ArchiveBrowserEvent event, void* context) {
|
||||
ArchiveApp* archive = (ArchiveApp*)context;
|
||||
view_dispatcher_send_custom_event(archive->view_dispatcher, event);
|
||||
}
|
||||
|
||||
const void archive_scene_browser_on_enter(void* context) {
|
||||
ArchiveApp* archive = (ArchiveApp*)context;
|
||||
ArchiveMainView* main_view = archive->main_view;
|
||||
|
||||
archive_browser_set_callback(main_view, archive_scene_browser_callback, archive);
|
||||
archive_browser_update(main_view);
|
||||
view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewBrowser);
|
||||
}
|
||||
|
||||
const bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
ArchiveApp* archive = (ArchiveApp*)context;
|
||||
bool consumed;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case ArchiveBrowserEventRename:
|
||||
scene_manager_next_scene(archive->scene_manager, ArchiveAppSceneRename);
|
||||
consumed = true;
|
||||
break;
|
||||
case ArchiveBrowserEventExit:
|
||||
view_dispatcher_stop(archive->view_dispatcher);
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
const void archive_scene_browser_on_exit(void* context) {
|
||||
// ArchiveApp* archive = (ArchiveApp*)context;
|
||||
}
|
2
applications/archive/scenes/archive_scene_config.h
Normal file
2
applications/archive/scenes/archive_scene_config.h
Normal file
@@ -0,0 +1,2 @@
|
||||
ADD_SCENE(archive, browser, Browser)
|
||||
ADD_SCENE(archive, rename, Rename)
|
80
applications/archive/scenes/archive_scene_rename.c
Normal file
80
applications/archive/scenes/archive_scene_rename.c
Normal file
@@ -0,0 +1,80 @@
|
||||
#include "../archive_i.h"
|
||||
#include "../helpers/archive_favorites.h"
|
||||
#include "../helpers/archive_files.h"
|
||||
|
||||
#define SCENE_RENAME_CUSTOM_EVENT (0UL)
|
||||
|
||||
void archive_scene_rename_text_input_callback(void* context) {
|
||||
ArchiveApp* archive = (ArchiveApp*)context;
|
||||
view_dispatcher_send_custom_event(archive->view_dispatcher, SCENE_RENAME_CUSTOM_EVENT);
|
||||
}
|
||||
|
||||
const void archive_scene_rename_on_enter(void* context) {
|
||||
ArchiveApp* archive = (ArchiveApp*)context;
|
||||
|
||||
TextInput* text_input = archive->text_input;
|
||||
ArchiveFile_t* current = archive_get_current_file(archive->main_view);
|
||||
strlcpy(archive->text_store, string_get_cstr(current->name), MAX_NAME_LEN);
|
||||
|
||||
archive_trim_file_ext(archive->text_store);
|
||||
|
||||
text_input_set_header_text(text_input, "Rename:");
|
||||
|
||||
text_input_set_result_callback(
|
||||
text_input,
|
||||
archive_scene_rename_text_input_callback,
|
||||
archive,
|
||||
archive->text_store,
|
||||
MAX_NAME_LEN,
|
||||
false);
|
||||
|
||||
view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewTextInput);
|
||||
}
|
||||
|
||||
const bool archive_scene_rename_on_event(void* context, SceneManagerEvent event) {
|
||||
ArchiveApp* archive = (ArchiveApp*)context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SCENE_RENAME_CUSTOM_EVENT) {
|
||||
Storage* fs_api = furi_record_open("storage");
|
||||
|
||||
string_t buffer_src;
|
||||
string_t buffer_dst;
|
||||
|
||||
const char* path = archive_get_path(archive->main_view);
|
||||
const char* name = archive_get_name(archive->main_view);
|
||||
|
||||
string_init_printf(buffer_src, "%s/%s", path, name);
|
||||
string_init_printf(buffer_dst, "%s/%s", path, archive->text_store);
|
||||
|
||||
archive_set_name(archive->main_view, archive->text_store);
|
||||
|
||||
// append extension
|
||||
ArchiveFile_t* file = archive_get_current_file(archive->main_view);
|
||||
|
||||
string_cat(buffer_dst, known_ext[file->type]);
|
||||
storage_common_rename(
|
||||
fs_api, string_get_cstr(buffer_src), string_get_cstr(buffer_dst));
|
||||
furi_record_close("storage");
|
||||
|
||||
if(file->fav) {
|
||||
archive_favorites_rename(path, name, string_get_cstr(buffer_dst));
|
||||
}
|
||||
|
||||
string_clear(buffer_src);
|
||||
string_clear(buffer_dst);
|
||||
|
||||
scene_manager_next_scene(archive->scene_manager, ArchiveAppSceneBrowser);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
const void archive_scene_rename_on_exit(void* context) {
|
||||
ArchiveApp* archive = (ArchiveApp*)context;
|
||||
// Clear view
|
||||
text_input_set_header_text(archive->text_input, NULL);
|
||||
text_input_set_result_callback(archive->text_input, NULL, NULL, NULL, 0, false);
|
||||
}
|
Reference in New Issue
Block a user