archive_scene_delete.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "../archive_i.h"
  2. #include "../helpers/archive_favorites.h"
  3. #include "../helpers/archive_files.h"
  4. #include "../helpers/archive_apps.h"
  5. #include "../helpers/archive_browser.h"
  6. #include "toolbox/path.h"
  7. #define SCENE_DELETE_CUSTOM_EVENT (0UL)
  8. #define MAX_TEXT_INPUT_LEN 22
  9. void archive_scene_delete_widget_callback(GuiButtonType result, InputType type, void* context) {
  10. furi_assert(context);
  11. ArchiveApp* app = (ArchiveApp*)context;
  12. if(type == InputTypeShort) {
  13. view_dispatcher_send_custom_event(app->view_dispatcher, result);
  14. }
  15. }
  16. void archive_scene_delete_on_enter(void* context) {
  17. furi_assert(context);
  18. ArchiveApp* app = (ArchiveApp*)context;
  19. widget_add_button_element(
  20. app->widget, GuiButtonTypeLeft, "Cancel", archive_scene_delete_widget_callback, app);
  21. widget_add_button_element(
  22. app->widget, GuiButtonTypeRight, "Delete", archive_scene_delete_widget_callback, app);
  23. FuriString* filename;
  24. filename = furi_string_alloc();
  25. ArchiveFile_t* current = archive_get_current_file(app->browser);
  26. path_extract_filename(current->path, filename, false);
  27. char delete_str[64];
  28. snprintf(delete_str, sizeof(delete_str), "\e#Delete %s?\e#", furi_string_get_cstr(filename));
  29. widget_add_text_box_element(
  30. app->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, delete_str, false);
  31. furi_string_free(filename);
  32. view_dispatcher_switch_to_view(app->view_dispatcher, ArchiveViewWidget);
  33. }
  34. bool archive_scene_delete_on_event(void* context, SceneManagerEvent event) {
  35. furi_assert(context);
  36. ArchiveApp* app = (ArchiveApp*)context;
  37. ArchiveBrowserView* browser = app->browser;
  38. ArchiveFile_t* selected = archive_get_current_file(browser);
  39. const char* name = archive_get_name(browser);
  40. if(event.type == SceneManagerEventTypeCustom) {
  41. if(event.event == GuiButtonTypeRight) {
  42. if(selected->is_app) {
  43. archive_app_delete_file(browser, name);
  44. } else {
  45. archive_delete_file(browser, "%s", name);
  46. }
  47. archive_show_file_menu(browser, false);
  48. return scene_manager_previous_scene(app->scene_manager);
  49. } else if(event.event == GuiButtonTypeLeft) {
  50. return scene_manager_previous_scene(app->scene_manager);
  51. }
  52. }
  53. return false;
  54. }
  55. void archive_scene_delete_on_exit(void* context) {
  56. furi_assert(context);
  57. ArchiveApp* app = (ArchiveApp*)context;
  58. widget_reset(app->widget);
  59. }