dlg_delete_content.lua 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. --Minetest
  2. --Copyright (C) 2014 sapier
  3. --
  4. --This program is free software; you can redistribute it and/or modify
  5. --it under the terms of the GNU Lesser General Public License as published by
  6. --the Free Software Foundation; either version 2.1 of the License, or
  7. --(at your option) any later version.
  8. --
  9. --This program is distributed in the hope that it will be useful,
  10. --but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. --MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. --GNU Lesser General Public License for more details.
  13. --
  14. --You should have received a copy of the GNU Lesser General Public License along
  15. --with this program; if not, write to the Free Software Foundation, Inc.,
  16. --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. --------------------------------------------------------------------------------
  18. local function delete_content_formspec(dialogdata)
  19. return confirmation_formspec(
  20. fgettext("Are you sure you want to delete \"$1\"?", dialogdata.content.name),
  21. 'dlg_delete_content_confirm', fgettext("Delete"),
  22. 'dlg_delete_content_cancel', fgettext("Cancel"))
  23. end
  24. --------------------------------------------------------------------------------
  25. local function delete_content_buttonhandler(this, fields)
  26. if fields["dlg_delete_content_confirm"] ~= nil then
  27. if this.data.content.path ~= nil and
  28. this.data.content.path ~= "" and
  29. this.data.content.path ~= core.get_modpath() and
  30. this.data.content.path ~= core.get_gamepath() and
  31. this.data.content.path ~= core.get_texturepath() then
  32. if not core.delete_dir(this.data.content.path) then
  33. gamedata.errormessage = fgettext("pkgmgr: failed to delete \"$1\"", this.data.content.path)
  34. end
  35. if this.data.content.type == "game" then
  36. pkgmgr.update_gamelist()
  37. else
  38. pkgmgr.refresh_globals()
  39. end
  40. else
  41. gamedata.errormessage = fgettext("pkgmgr: invalid path \"$1\"", this.data.content.path)
  42. end
  43. this:delete()
  44. return true
  45. end
  46. if fields["dlg_delete_content_cancel"] then
  47. this:delete()
  48. return true
  49. end
  50. return false
  51. end
  52. --------------------------------------------------------------------------------
  53. function create_delete_content_dlg(content)
  54. assert(content.name)
  55. local retval = dialog_create("dlg_delete_content",
  56. delete_content_formspec,
  57. delete_content_buttonhandler,
  58. nil)
  59. retval.data.content = content
  60. return retval
  61. end