spi_mem_scene_delete_confirm.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "../spi_mem_app_i.h"
  2. #include "../spi_mem_files.h"
  3. static void spi_mem_scene_delete_confirm_widget_callback(
  4. GuiButtonType result,
  5. InputType type,
  6. void* context) {
  7. SPIMemApp* app = context;
  8. if(type == InputTypeShort) {
  9. view_dispatcher_send_custom_event(app->view_dispatcher, result);
  10. }
  11. }
  12. void spi_mem_scene_delete_confirm_on_enter(void* context) {
  13. SPIMemApp* app = context;
  14. FuriString* file_name = furi_string_alloc();
  15. FuriString* message = furi_string_alloc();
  16. path_extract_filename(app->file_path, file_name, true);
  17. furi_string_printf(message, "\e#Delete %s?\e#", furi_string_get_cstr(file_name));
  18. widget_add_text_box_element(
  19. app->widget, 0, 0, 128, 27, AlignCenter, AlignCenter, furi_string_get_cstr(message), true);
  20. widget_add_button_element(
  21. app->widget,
  22. GuiButtonTypeLeft,
  23. "Cancel",
  24. spi_mem_scene_delete_confirm_widget_callback,
  25. app);
  26. widget_add_button_element(
  27. app->widget,
  28. GuiButtonTypeRight,
  29. "Delete",
  30. spi_mem_scene_delete_confirm_widget_callback,
  31. app);
  32. view_dispatcher_switch_to_view(app->view_dispatcher, SPIMemViewWidget);
  33. furi_string_free(file_name);
  34. furi_string_free(message);
  35. }
  36. bool spi_mem_scene_delete_confirm_on_event(void* context, SceneManagerEvent event) {
  37. SPIMemApp* app = context;
  38. bool success = false;
  39. if(event.type == SceneManagerEventTypeCustom) {
  40. success = true;
  41. if(event.event == GuiButtonTypeRight) {
  42. app->mode = SPIMemModeDelete;
  43. if(spi_mem_file_delete(app)) {
  44. scene_manager_next_scene(app->scene_manager, SPIMemSceneSuccess);
  45. } else {
  46. scene_manager_next_scene(app->scene_manager, SPIMemSceneStorageError);
  47. }
  48. } else if(event.event == GuiButtonTypeLeft) {
  49. scene_manager_search_and_switch_to_previous_scene(
  50. app->scene_manager, SPIMemSceneSavedFileMenu);
  51. }
  52. }
  53. return success;
  54. }
  55. void spi_mem_scene_delete_confirm_on_exit(void* context) {
  56. SPIMemApp* app = context;
  57. widget_reset(app->widget);
  58. }