archive_scene_delete.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #define SCENE_DELETE_CUSTOM_EVENT (0UL)
  7. #define MAX_TEXT_INPUT_LEN 22
  8. void archive_scene_delete_widget_callback(GuiButtonType result, InputType type, void* context) {
  9. furi_assert(context);
  10. ArchiveApp* app = (ArchiveApp*)context;
  11. if(type == InputTypeShort) {
  12. view_dispatcher_send_custom_event(app->view_dispatcher, result);
  13. }
  14. }
  15. void archive_scene_delete_on_enter(void* context) {
  16. furi_assert(context);
  17. ArchiveApp* app = (ArchiveApp*)context;
  18. widget_add_button_element(
  19. app->widget, GuiButtonTypeLeft, "Cancel", archive_scene_delete_widget_callback, app);
  20. widget_add_button_element(
  21. app->widget, GuiButtonTypeRight, "Delete", archive_scene_delete_widget_callback, app);
  22. ArchiveFile_t* current = archive_get_current_file(app->browser);
  23. strlcpy(app->text_store, string_get_cstr(current->name), MAX_NAME_LEN);
  24. char* name = strrchr(app->text_store, '/');
  25. if(name != NULL) {
  26. name++;
  27. }
  28. char delete_str[64];
  29. snprintf(delete_str, sizeof(delete_str), "\e#Delete %s?\e#", name);
  30. widget_add_text_box_element(
  31. app->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, delete_str, false);
  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. }