dlg_delete_content.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. -- Luanti
  2. -- Copyright (C) 2014 sapier
  3. -- SPDX-License-Identifier: LGPL-2.1-or-later
  4. --------------------------------------------------------------------------------
  5. local function delete_content_formspec(dialogdata)
  6. return confirmation_formspec(
  7. fgettext("Are you sure you want to delete \"$1\"?", dialogdata.content.name),
  8. 'dlg_delete_content_confirm', fgettext("Delete"),
  9. 'dlg_delete_content_cancel', fgettext("Cancel"))
  10. end
  11. --------------------------------------------------------------------------------
  12. local function delete_content_buttonhandler(this, fields)
  13. if fields["dlg_delete_content_confirm"] ~= nil then
  14. if this.data.content.path ~= nil and
  15. this.data.content.path ~= "" and
  16. this.data.content.path ~= core.get_modpath() and
  17. this.data.content.path ~= core.get_gamepath() and
  18. this.data.content.path ~= core.get_texturepath() then
  19. if not core.delete_dir(this.data.content.path) then
  20. gamedata.errormessage = fgettext_ne("pkgmgr: failed to delete \"$1\"", this.data.content.path)
  21. end
  22. pkgmgr.reload_by_type(this.data.content.type)
  23. else
  24. gamedata.errormessage = fgettext_ne("pkgmgr: invalid path \"$1\"", this.data.content.path)
  25. end
  26. this:delete()
  27. return true
  28. end
  29. if fields["dlg_delete_content_cancel"] then
  30. this:delete()
  31. return true
  32. end
  33. return false
  34. end
  35. --------------------------------------------------------------------------------
  36. function create_delete_content_dlg(content)
  37. assert(content.name)
  38. local retval = dialog_create("dlg_delete_content",
  39. delete_content_formspec,
  40. delete_content_buttonhandler,
  41. nil)
  42. retval.data.content = content
  43. return retval
  44. end