archive_scene_delete.c 2.5 KB

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