dlg_delete_mod.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_mod_formspec(dialogdata)
  19. dialogdata.mod = modmgr.global_mods:get_list()[dialogdata.selected]
  20. local retval =
  21. "size[11.5,4.5,true]" ..
  22. "label[2,2;" ..
  23. fgettext("Are you sure you want to delete \"$1\"?", dialogdata.mod.name) .. "]"..
  24. "button[3.25,3.5;2.5,0.5;dlg_delete_mod_confirm;" .. fgettext("Delete") .. "]" ..
  25. "button[5.75,3.5;2.5,0.5;dlg_delete_mod_cancel;" .. fgettext("Cancel") .. "]"
  26. return retval
  27. end
  28. --------------------------------------------------------------------------------
  29. local function delete_mod_buttonhandler(this, fields)
  30. if fields["dlg_delete_mod_confirm"] ~= nil then
  31. if this.data.mod.path ~= nil and
  32. this.data.mod.path ~= "" and
  33. this.data.mod.path ~= core.get_modpath() then
  34. if not core.delete_dir(this.data.mod.path) then
  35. gamedata.errormessage = fgettext("Modmgr: failed to delete \"$1\"", this.data.mod.path)
  36. end
  37. modmgr.refresh_globals()
  38. else
  39. gamedata.errormessage = fgettext("Modmgr: invalid modpath \"$1\"", this.data.mod.path)
  40. end
  41. this:delete()
  42. return true
  43. end
  44. if fields["dlg_delete_mod_cancel"] then
  45. this:delete()
  46. return true
  47. end
  48. return false
  49. end
  50. --------------------------------------------------------------------------------
  51. function create_delete_mod_dlg(selected_index)
  52. local retval = dialog_create("dlg_delete_mod",
  53. delete_mod_formspec,
  54. delete_mod_buttonhandler,
  55. nil)
  56. retval.data.selected = selected_index
  57. return retval
  58. end