2021-09-10 03:57:43 +03:00
|
|
|
#include "../archive_i.h"
|
|
|
|
#include "../helpers/archive_favorites.h"
|
|
|
|
#include "../helpers/archive_files.h"
|
2021-09-21 13:56:33 +03:00
|
|
|
#include "../helpers/archive_browser.h"
|
2022-06-09 10:09:52 +03:00
|
|
|
#include "archive/views/archive_browser_view.h"
|
|
|
|
#include "toolbox/path.h"
|
2021-09-10 03:57:43 +03:00
|
|
|
|
|
|
|
#define SCENE_RENAME_CUSTOM_EVENT (0UL)
|
2021-09-28 19:18:06 +03:00
|
|
|
#define MAX_TEXT_INPUT_LEN 22
|
2021-09-10 03:57:43 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-09-21 12:34:16 +03:00
|
|
|
void archive_scene_rename_on_enter(void* context) {
|
2021-09-10 03:57:43 +03:00
|
|
|
ArchiveApp* archive = (ArchiveApp*)context;
|
|
|
|
|
|
|
|
TextInput* text_input = archive->text_input;
|
2021-09-21 13:56:33 +03:00
|
|
|
ArchiveFile_t* current = archive_get_current_file(archive->browser);
|
2021-09-10 03:57:43 +03:00
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
FuriString* filename;
|
|
|
|
filename = furi_string_alloc();
|
2022-06-09 10:09:52 +03:00
|
|
|
path_extract_filename(current->path, filename, true);
|
2022-10-05 18:15:23 +03:00
|
|
|
strlcpy(archive->text_store, furi_string_get_cstr(filename), MAX_NAME_LEN);
|
2022-06-09 10:09:52 +03:00
|
|
|
|
|
|
|
path_extract_extension(current->path, archive->file_extension, MAX_EXT_LEN);
|
2021-09-10 03:57:43 +03:00
|
|
|
|
|
|
|
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,
|
2021-09-28 19:18:06 +03:00
|
|
|
MAX_TEXT_INPUT_LEN,
|
2021-09-10 03:57:43 +03:00
|
|
|
false);
|
|
|
|
|
2022-04-07 18:00:45 +03:00
|
|
|
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_get_cstr(archive->browser->path), archive->file_extension, "");
|
2022-01-29 12:39:10 +03:00
|
|
|
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_free(filename);
|
2022-06-09 10:09:52 +03:00
|
|
|
|
2021-09-10 03:57:43 +03:00
|
|
|
view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewTextInput);
|
|
|
|
}
|
|
|
|
|
2021-09-21 12:34:16 +03:00
|
|
|
bool archive_scene_rename_on_event(void* context, SceneManagerEvent event) {
|
2021-09-10 03:57:43 +03:00
|
|
|
ArchiveApp* archive = (ArchiveApp*)context;
|
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
if(event.event == SCENE_RENAME_CUSTOM_EVENT) {
|
2022-07-26 15:21:51 +03:00
|
|
|
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
2021-09-10 03:57:43 +03:00
|
|
|
|
2022-06-09 10:09:52 +03:00
|
|
|
const char* path_src = archive_get_name(archive->browser);
|
2021-09-21 13:56:33 +03:00
|
|
|
ArchiveFile_t* file = archive_get_current_file(archive->browser);
|
2021-09-10 03:57:43 +03:00
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
FuriString* path_dst;
|
2022-11-12 14:55:42 +03:00
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
path_dst = furi_string_alloc();
|
2022-06-09 10:09:52 +03:00
|
|
|
path_extract_dirname(path_src, path_dst);
|
2022-11-12 14:55:42 +03:00
|
|
|
furi_string_cat_printf(
|
|
|
|
path_dst, "/%s%s", archive->text_store, archive->file_extension);
|
2022-06-09 10:09:52 +03:00
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
storage_common_rename(fs_api, path_src, furi_string_get_cstr(path_dst));
|
2022-07-26 15:21:51 +03:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2021-09-10 03:57:43 +03:00
|
|
|
|
|
|
|
if(file->fav) {
|
2022-10-05 18:15:23 +03:00
|
|
|
archive_favorites_rename(path_src, furi_string_get_cstr(path_dst));
|
2021-09-10 03:57:43 +03:00
|
|
|
}
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_free(path_dst);
|
2021-09-10 03:57:43 +03:00
|
|
|
|
|
|
|
scene_manager_next_scene(archive->scene_manager, ArchiveAppSceneBrowser);
|
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
2021-09-21 12:34:16 +03:00
|
|
|
void archive_scene_rename_on_exit(void* context) {
|
2021-09-10 03:57:43 +03:00
|
|
|
ArchiveApp* archive = (ArchiveApp*)context;
|
2022-01-29 12:39:10 +03:00
|
|
|
|
2021-09-10 03:57:43 +03:00
|
|
|
// Clear view
|
2022-01-29 12:39:10 +03:00
|
|
|
void* validator_context = text_input_get_validator_callback_context(archive->text_input);
|
|
|
|
text_input_set_validator(archive->text_input, NULL, NULL);
|
|
|
|
validator_is_file_free(validator_context);
|
|
|
|
|
2022-01-21 20:32:03 +03:00
|
|
|
text_input_reset(archive->text_input);
|
2021-09-10 03:57:43 +03:00
|
|
|
}
|