فهرست منبع

Fix scene flow

TollyH 2 سال پیش
والد
کامیت
0a2f0bb2fd
4فایلهای تغییر یافته به همراه47 افزوده شده و 17 حذف شده
  1. 24 12
      mfc_editor_app.c
  2. 11 1
      mfc_editor_app_i.h
  3. 11 2
      scenes/mfc_editor_scene_file_select.c
  4. 1 2
      scenes/mfc_editor_scene_invalid_file.c

+ 24 - 12
mfc_editor_app.c

@@ -137,7 +137,7 @@ static bool mfc_editor_file_has_shadow_file(MfcEditorApp* instance, FuriString*
     return has_shadow_file;
 }
 
-bool mfc_editor_prompt_load_file(MfcEditorApp* instance) {
+MfcEditorPromptResponse mfc_editor_prompt_load_file(MfcEditorApp* instance) {
     furi_assert(instance);
 
     DialogsFileBrowserOptions browser_options;
@@ -145,19 +145,31 @@ bool mfc_editor_prompt_load_file(MfcEditorApp* instance) {
     browser_options.base_path = NFC_APP_FOLDER;
     browser_options.hide_dot_files = true;
 
-    bool result = dialog_file_browser_show(
-        instance->dialogs, instance->file_path, instance->file_path, &browser_options);
-
-    if(result) {
-        if(mfc_editor_file_has_shadow_file(instance, instance->file_path) &&
-           mfc_editor_prompt_should_load_shadow(instance) == DialogMessageButtonRight) {
-            FuriString* shadow_file_path = furi_string_alloc();
-            mfc_editor_get_shadow_file_path(instance->file_path, shadow_file_path);
-            furi_string_set(instance->file_path, shadow_file_path);
-            furi_string_free(shadow_file_path);
+    MfcEditorPromptResponse result = MfcEditorPromptResponseSuccess;
+    if(!dialog_file_browser_show(
+           instance->dialogs, instance->file_path, instance->file_path, &browser_options)) {
+        result = MfcEditorPromptResponseExitedFile;
+    } else {
+        if(mfc_editor_file_has_shadow_file(instance, instance->file_path)) {
+            DialogMessageButton message_button = mfc_editor_prompt_should_load_shadow(instance);
+
+            if(message_button == DialogMessageButtonRight) {
+                // User selected to use shadow file, so replace selected path with that path
+                FuriString* shadow_file_path = furi_string_alloc();
+                mfc_editor_get_shadow_file_path(instance->file_path, shadow_file_path);
+                furi_string_set(instance->file_path, shadow_file_path);
+                furi_string_free(shadow_file_path);
+            } else if(message_button == DialogMessageButtonBack) {
+                result = MfcEditorPromptResponseExitedShadow;
+            }
         }
 
-        result = mfc_editor_load_file(instance, instance->file_path, true);
+        // Don't load the file if user was prompted for shadow file use but went back
+        if(result == MfcEditorPromptResponseSuccess) {
+            if(!mfc_editor_load_file(instance, instance->file_path, true)) {
+                result = MfcEditorPromptResponseFailure;
+            }
+        }
     }
 
     return result;

+ 11 - 1
mfc_editor_app_i.h

@@ -55,6 +55,16 @@ typedef enum {
     MfcEditorAppViewPopup,
 } MfcEditorAppView;
 
-bool mfc_editor_prompt_load_file(MfcEditorApp* instance);
+typedef enum {
+    // Generic
+    MfcEditorPromptResponseSuccess,
+    MfcEditorPromptResponseFailure,
+
+    // Backed out of a prompt
+    MfcEditorPromptResponseExitedFile,
+    MfcEditorPromptResponseExitedShadow,
+} MfcEditorPromptResponse;
+
+MfcEditorPromptResponse mfc_editor_prompt_load_file(MfcEditorApp* instance);
 
 bool mfc_editor_load_file(MfcEditorApp* instance, FuriString* file_path, bool show_dialog);

+ 11 - 2
scenes/mfc_editor_scene_file_select.c

@@ -3,7 +3,15 @@
 void mfc_editor_scene_file_select_on_enter(void* context) {
     MfcEditorApp* instance = context;
 
-    if(mfc_editor_prompt_load_file(instance)) {
+    // File select scene should repeat itself if the file load failed
+    // or if the user quit the shadow file prompt, not the file selector
+    MfcEditorPromptResponse prompt_response = MfcEditorPromptResponseFailure;
+    while(prompt_response == MfcEditorPromptResponseFailure ||
+          prompt_response == MfcEditorPromptResponseExitedShadow) {
+        prompt_response = mfc_editor_prompt_load_file(instance);
+    }
+
+    if(prompt_response == MfcEditorPromptResponseSuccess) {
         if(nfc_device_get_protocol(instance->nfc_device) == NfcProtocolMfClassic) {
             scene_manager_set_scene_state(instance->scene_manager, MfcEditorSceneSectorSelect, 0);
             scene_manager_next_scene(instance->scene_manager, MfcEditorSceneSectorSelect);
@@ -11,7 +19,8 @@ void mfc_editor_scene_file_select_on_enter(void* context) {
             scene_manager_next_scene(instance->scene_manager, MfcEditorSceneInvalidFile);
         }
     } else {
-        scene_manager_previous_scene(instance->scene_manager);
+        scene_manager_search_and_switch_to_previous_scene(
+            instance->scene_manager, MfcEditorSceneStart);
     }
 }
 

+ 1 - 2
scenes/mfc_editor_scene_invalid_file.c

@@ -24,8 +24,7 @@ bool mfc_editor_scene_invalid_file_on_event(void* context, SceneManagerEvent eve
 
     if(event.type == SceneManagerEventTypeCustom) {
         if(event.event == MfcEditorCustomEventViewExit) {
-            consumed = scene_manager_search_and_switch_to_previous_scene(
-                instance->scene_manager, MfcEditorSceneStart);
+            consumed = scene_manager_previous_scene(instance->scene_manager);
         }
     }