dlg_delete_content.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. local retval =
  20. "size[11.5,4.5,true]" ..
  21. "label[2,2;" ..
  22. fgettext("Are you sure you want to delete \"$1\"?", dialogdata.content.name) .. "]"..
  23. "style[dlg_delete_content_confirm;bgcolor=red]" ..
  24. "button[3.25,3.5;2.5,0.5;dlg_delete_content_confirm;" .. fgettext("Delete") .. "]" ..
  25. "button[5.75,3.5;2.5,0.5;dlg_delete_content_cancel;" .. fgettext("Cancel") .. "]"
  26. return retval
  27. end
  28. --------------------------------------------------------------------------------
  29. local function delete_content_buttonhandler(this, fields)
  30. if fields["dlg_delete_content_confirm"] ~= nil then
  31. if this.data.content.path ~= nil and
  32. this.data.content.path ~= "" and
  33. this.data.content.path ~= core.get_modpath() and
  34. this.data.content.path ~= core.get_gamepath() and
  35. this.data.content.path ~= core.get_texturepath() then
  36. if not core.delete_dir(this.data.content.path) then
  37. gamedata.errormessage = fgettext("pkgmgr: failed to delete \"$1\"", this.data.content.path)
  38. end
  39. if this.data.content.type == "game" then
  40. pkgmgr.update_gamelist()
  41. else
  42. pkgmgr.refresh_globals()
  43. end
  44. else
  45. gamedata.errormessage = fgettext("pkgmgr: invalid path \"$1\"", this.data.content.path)
  46. end
  47. this:delete()
  48. return true
  49. end
  50. if fields["dlg_delete_content_cancel"] then
  51. this:delete()
  52. return true
  53. end
  54. return false
  55. end
  56. --------------------------------------------------------------------------------
  57. function create_delete_content_dlg(content)
  58. assert(content.name)
  59. local retval = dialog_create("dlg_delete_content",
  60. delete_content_formspec,
  61. delete_content_buttonhandler,
  62. nil)
  63. retval.data.content = content
  64. return retval
  65. end