1
+ #include <lib/toolbox/random_name.h>
1
2
#include "../mag_i.h"
2
3
3
4
void mag_scene_save_name_on_enter (void * context ) {
4
5
Mag * mag = context ;
5
- UNUSED (mag );
6
+ TextInput * text_input = mag -> text_input ;
7
+ FuriString * folder_path ;
8
+ folder_path = furi_string_alloc ();
9
+
10
+ bool key_name_is_empty = furi_string_empty (mag -> file_name );
11
+
12
+ if (key_name_is_empty ) {
13
+ furi_string_set (mag -> file_path , MAG_APP_FOLDER );
14
+ set_random_name (mag -> text_store , MAG_TEXT_STORE_SIZE );
15
+ furi_string_set (folder_path , MAG_APP_FOLDER );
16
+ } else {
17
+ mag_text_store_set (mag , "%s" , furi_string_get_cstr (mag -> file_name ));
18
+ path_extract_dirname (furi_string_get_cstr (mag -> file_path ), folder_path );
19
+ }
20
+
21
+ text_input_set_header_text (text_input , "Name the card" );
22
+ text_input_set_result_callback (
23
+ text_input ,
24
+ mag_text_input_callback ,
25
+ mag ,
26
+ mag -> text_store ,
27
+ MAG_KEY_NAME_SIZE ,
28
+ key_name_is_empty );
29
+
30
+ FURI_LOG_I ("" , "%s %s" , furi_string_get_cstr (folder_path ), mag -> text_store );
31
+
32
+ ValidatorIsFile * validator_is_file = validator_is_file_alloc_init (
33
+ furi_string_get_cstr (folder_path ),
34
+ MAG_APP_EXTENSION ,
35
+ furi_string_get_cstr (mag -> file_name ));
36
+ text_input_set_validator (text_input , validator_is_file_callback , validator_is_file );
37
+
38
+ furi_string_free (folder_path );
39
+
40
+ view_dispatcher_switch_to_view (mag -> view_dispatcher , MagViewTextInput );
6
41
}
7
42
8
43
bool mag_scene_save_name_on_event (void * context , SceneManagerEvent event ) {
9
44
Mag * mag = context ;
10
- UNUSED (mag );
11
- UNUSED (event );
45
+ SceneManager * scene_manager = mag -> scene_manager ;
12
46
bool consumed = false;
13
47
48
+ if (event .type == SceneManagerEventTypeCustom ) {
49
+ if (event .event == MagEventNext ) {
50
+ consumed = true;
51
+ if (!furi_string_empty (mag -> file_name )) {
52
+ mag_delete_key (mag );
53
+ }
54
+
55
+ furi_string_set (mag -> file_name , mag -> text_store );
56
+
57
+ if (mag_save_key (mag )) {
58
+ scene_manager_next_scene (scene_manager , MagSceneSaveSuccess );
59
+ if (scene_manager_has_previous_scene (scene_manager , MagSceneSavedKeyMenu )) {
60
+ // Nothing, do not count editing as saving
61
+ //} else if(scene_manager_has_previous_scene(scene_manager, MagSceneSaveType)) {
62
+ //DOLPHIN_DEED(DolphinDeedRfidAdd);
63
+ // TODO: replace dolphin deed!
64
+ } else {
65
+ //DOLPHIN_DEED(DolphinDeedRfidSave);
66
+ // TODO: replace dolphin deed!
67
+ }
68
+ } else {
69
+ //scene_manager_search_and_switch_to_previous_scene(
70
+ // scene_manager, MagSceneReadKeyMenu);
71
+ // TODO: Replace with appropriate scene! No read scene prior if adding manually...
72
+ }
73
+ }
74
+ }
75
+
14
76
return consumed ;
15
77
}
16
78
17
79
void mag_scene_save_name_on_exit (void * context ) {
18
80
Mag * mag = context ;
19
- UNUSED (mag );
20
- }
81
+ TextInput * text_input = mag -> text_input ;
82
+
83
+ void * validator_context = text_input_get_validator_callback_context (text_input );
84
+ text_input_set_validator (text_input , NULL , NULL );
85
+ validator_is_file_free ((ValidatorIsFile * )validator_context );
86
+
87
+ text_input_reset (text_input );
88
+ }
0 commit comments