2
0

dlg_rename_modpack.lua 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 rename_modpack_formspec(dialogdata)
  19. dialogdata.mod = modmgr.global_mods:get_list()[dialogdata.selected]
  20. local retval =
  21. "size[11.5,4.5,true]" ..
  22. "field[2.5,2;7,0.5;te_modpack_name;".. fgettext("Rename Modpack:") .. ";" ..
  23. dialogdata.mod.name .. "]" ..
  24. "button[3.25,3.5;2.5,0.5;dlg_rename_modpack_confirm;"..
  25. fgettext("Accept") .. "]" ..
  26. "button[5.75,3.5;2.5,0.5;dlg_rename_modpack_cancel;"..
  27. fgettext("Cancel") .. "]"
  28. return retval
  29. end
  30. --------------------------------------------------------------------------------
  31. local function rename_modpack_buttonhandler(this, fields)
  32. if fields["dlg_rename_modpack_confirm"] ~= nil then
  33. local oldpath = core.get_modpath() .. DIR_DELIM .. this.data.mod.name
  34. local targetpath = core.get_modpath() .. DIR_DELIM .. fields["te_modpack_name"]
  35. core.copy_dir(oldpath,targetpath,false)
  36. modmgr.refresh_globals()
  37. modmgr.selected_mod = modmgr.global_mods:get_current_index(
  38. modmgr.global_mods:raw_index_by_uid(fields["te_modpack_name"]))
  39. this:delete()
  40. return true
  41. end
  42. if fields["dlg_rename_modpack_cancel"] then
  43. this:delete()
  44. return true
  45. end
  46. return false
  47. end
  48. --------------------------------------------------------------------------------
  49. function create_rename_modpack_dlg(selected_index)
  50. local retval = dialog_create("dlg_delete_mod",
  51. rename_modpack_formspec,
  52. rename_modpack_buttonhandler,
  53. nil)
  54. retval.data.selected = selected_index
  55. return retval
  56. end