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