Browser: Context menu to show file content

This commit is contained in:
Aleksandr Skoriy 2022-10-28 05:43:25 +03:00
parent f9c08249a0
commit 8e362b087a
5 changed files with 104 additions and 4 deletions

View file

@ -150,6 +150,13 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(archive->scene_manager, ArchiveAppSceneInfo);
consumed = true;
break;
case ArchiveBrowserEventFileMenuShow:
archive_show_file_menu(browser, false);
scene_manager_set_scene_state(
archive->scene_manager, ArchiveAppSceneBrowser, SCENE_STATE_DEFAULT);
scene_manager_next_scene(archive->scene_manager, ArchiveAppSceneShow);
consumed = true;
break;
case ArchiveBrowserEventFileMenuDelete:
if(archive_get_tab(browser) != ArchiveTabFavorites) {
scene_manager_next_scene(archive->scene_manager, ArchiveAppSceneDelete);

View file

@ -2,3 +2,4 @@ ADD_SCENE(archive, browser, Browser)
ADD_SCENE(archive, rename, Rename)
ADD_SCENE(archive, delete, Delete)
ADD_SCENE(archive, info, Info)
ADD_SCENE(archive, show, Show)

View file

@ -0,0 +1,73 @@
#include "../archive_i.h"
#include "../helpers/archive_browser.h"
#include <storage/storage.h>
#define TAG "Archive"
void archive_scene_show_widget_callback(GuiButtonType result, InputType type, void* context) {
furi_assert(context);
ArchiveApp* app = (ArchiveApp*)context;
if(type == InputTypeShort) {
view_dispatcher_send_custom_event(app->view_dispatcher, result);
}
}
void archive_scene_show_on_enter(void* context) {
furi_assert(context);
ArchiveApp* instance = context;
FuriString* filename;
FuriString* str_size;
filename = furi_string_alloc();
str_size = furi_string_alloc();
ArchiveFile_t* current = archive_get_current_file(instance->browser);
Storage* fs_api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(fs_api);
uint32_t bytes_count;
FileInfo fileinfo;
storage_common_stat(fs_api, furi_string_get_cstr(current->path), &fileinfo);
storage_file_open(file, furi_string_get_cstr(current->path), FSAM_READ, FSOM_OPEN_EXISTING);
char* content = malloc(fileinfo.size + 1);
bytes_count = storage_file_read(file, content, fileinfo.size);
content[bytes_count + 1] = 0;
widget_add_text_scroll_element(
instance->widget, 0, 0, 128, 64, content);
path_extract_filename(current->path, filename, false);
// This one to return and cursor select this file
path_extract_filename_no_ext(furi_string_get_cstr(current->path), filename);
strlcpy(instance->text_store, furi_string_get_cstr(filename), MAX_NAME_LEN);
free(content);
storage_file_close(file);
storage_file_free(file);
furi_string_free(filename);
furi_string_free(str_size);
view_dispatcher_switch_to_view(instance->view_dispatcher, ArchiveViewWidget);
}
bool archive_scene_show_on_event(void* context, SceneManagerEvent event) {
furi_assert(context);
ArchiveApp* app = (ArchiveApp*)context;
if(event.type == SceneManagerEventTypeCustom) {
scene_manager_next_scene(app->scene_manager, ArchiveAppSceneBrowser);
return true;
}
return false;
}
void archive_scene_show_on_exit(void* context) {
furi_assert(context);
ArchiveApp* app = (ArchiveApp*)context;
widget_reset(app->widget);
}

View file

@ -51,6 +51,7 @@ static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
FuriString* item_run = furi_string_alloc_set("Run In App");
FuriString* item_pin = furi_string_alloc_set("Pin");
FuriString* item_info = furi_string_alloc_set("Info");
FuriString* item_show = furi_string_alloc_set("Show");
FuriString* item_rename = furi_string_alloc_set("Rename");
FuriString* item_delete = furi_string_alloc_set("Delete");
@ -79,6 +80,10 @@ static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
menu_array_push_raw(model->context_menu),
item_info,
ArchiveBrowserEventFileMenuInfo);
archive_menu_add_item(
menu_array_push_raw(model->context_menu),
item_show,
ArchiveBrowserEventFileMenuShow);
archive_menu_add_item(
menu_array_push_raw(model->context_menu),
item_rename,
@ -100,6 +105,10 @@ static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
menu_array_push_raw(model->context_menu),
item_pin,
ArchiveBrowserEventFileMenuPin);
archive_menu_add_item(
menu_array_push_raw(model->context_menu),
item_show,
ArchiveBrowserEventFileMenuShow);
archive_menu_add_item(
menu_array_push_raw(model->context_menu),
item_rename,
@ -114,6 +123,10 @@ static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
menu_array_push_raw(model->context_menu),
item_info,
ArchiveBrowserEventFileMenuInfo);
archive_menu_add_item(
menu_array_push_raw(model->context_menu),
item_show,
ArchiveBrowserEventFileMenuShow);
archive_menu_add_item(
menu_array_push_raw(model->context_menu),
item_pin,
@ -136,6 +149,10 @@ static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
menu_array_push_raw(model->context_menu),
item_info,
ArchiveBrowserEventFileMenuInfo);
archive_menu_add_item(
menu_array_push_raw(model->context_menu),
item_show,
ArchiveBrowserEventFileMenuShow);
archive_menu_add_item(
menu_array_push_raw(model->context_menu),
item_rename,
@ -149,6 +166,7 @@ static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
furi_string_free(item_run);
furi_string_free(item_pin);
furi_string_free(item_info);
furi_string_free(item_show);
furi_string_free(item_rename);
furi_string_free(item_delete);
} /*else {
@ -160,9 +178,9 @@ static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
canvas_set_color(canvas, ColorWhite);
uint8_t calc_height = menu_height - ((MENU_ITEMS - size_menu) * line_height);
canvas_draw_box(canvas, 71, 11, 57, calc_height + 4);
canvas_draw_box(canvas, 71, 1, 57, calc_height + 4);
canvas_set_color(canvas, ColorBlack);
elements_slightly_rounded_frame(canvas, 70, 12, 58, calc_height + 4);
elements_slightly_rounded_frame(canvas, 70, 2, 58, calc_height + 4);
/*FURI_LOG_D(
TAG,
@ -172,10 +190,10 @@ static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
model->menu_idx);*/
for(size_t i = 0; i < size_menu; i++) {
ArchiveContextMenuItem_t* current = menu_array_get(model->context_menu, i);
canvas_draw_str(canvas, 82, 21 + i * line_height, furi_string_get_cstr(current->text));
canvas_draw_str(canvas, 82, 11 + i * line_height, furi_string_get_cstr(current->text));
}
canvas_draw_icon(canvas, 74, 14 + model->menu_idx * line_height, &I_ButtonRight_4x7);
canvas_draw_icon(canvas, 74, 4 + model->menu_idx * line_height, &I_ButtonRight_4x7);
}
static void archive_draw_frame(Canvas* canvas, uint16_t idx, bool scrollbar, bool moving) {

View file

@ -40,6 +40,7 @@ typedef enum {
ArchiveBrowserEventFileMenuRename,
ArchiveBrowserEventFileMenuDelete,
ArchiveBrowserEventFileMenuInfo,
ArchiveBrowserEventFileMenuShow,
ArchiveBrowserEventFileMenuClose,
ArchiveBrowserEventEnterDir,