dlg_delete_mod.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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[12.4,5,true]" ..
  22. "field[1.75,1;10,3;;" .. fgettext("Are you sure you want to delete \"$1\"?", dialogdata.mod.name) .. ";]"..
  23. "button[4,4.2;1,0.5;dlg_delete_mod_confirm;" .. fgettext("Yes") .. "]" ..
  24. "button[6.5,4.2;3,0.5;dlg_delete_mod_cancel;" .. fgettext("No of course not!") .. "]"
  25. return retval
  26. end
  27. --------------------------------------------------------------------------------
  28. local function delete_mod_buttonhandler(this, fields)
  29. if fields["dlg_delete_mod_confirm"] ~= nil then
  30. if this.data.mod.path ~= nil and
  31. this.data.mod.path ~= "" and
  32. this.data.mod.path ~= core.get_modpath() then
  33. if not core.delete_dir(this.data.mod.path) then
  34. gamedata.errormessage = fgettext("Modmgr: failed to delete \"$1\"", this.data.mod.path)
  35. end
  36. modmgr.refresh_globals()
  37. else
  38. gamedata.errormessage = fgettext("Modmgr: invalid modpath \"$1\"", this.data.mod.path)
  39. end
  40. this:delete()
  41. return true
  42. end
  43. if fields["dlg_delete_mod_cancel"] then
  44. this:delete()
  45. return true
  46. end
  47. return false
  48. end
  49. --------------------------------------------------------------------------------
  50. function create_delete_mod_dlg(selected_index)
  51. local retval = dialog_create("dlg_delete_mod",
  52. delete_mod_formspec,
  53. delete_mod_buttonhandler,
  54. nil)
  55. retval.data.selected = selected_index
  56. return retval
  57. end