2
0

dlg_rename_modpack.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. local retval =
  20. "size[11.5,4.5,true]" ..
  21. "button[3.25,3.5;2.5,0.5;dlg_rename_modpack_confirm;"..
  22. fgettext("Accept") .. "]" ..
  23. "button[5.75,3.5;2.5,0.5;dlg_rename_modpack_cancel;"..
  24. fgettext("Cancel") .. "]"
  25. local input_y = 2
  26. if dialogdata.mod.is_name_explicit then
  27. retval = retval .. "textarea[1,0.2;10,2;;;" ..
  28. fgettext("This modpack has an explicit name given in its modpack.conf " ..
  29. "which will override any renaming here.") .. "]"
  30. input_y = 2.5
  31. end
  32. retval = retval ..
  33. "field[2.5," .. input_y .. ";7,0.5;te_modpack_name;" ..
  34. fgettext("Rename Modpack:") .. ";" .. dialogdata.mod.dir_name .. "]"
  35. return retval
  36. end
  37. --------------------------------------------------------------------------------
  38. local function rename_modpack_buttonhandler(this, fields)
  39. if fields["dlg_rename_modpack_confirm"] ~= nil then
  40. local oldpath = this.data.mod.path
  41. local targetpath = this.data.mod.parent_dir .. DIR_DELIM .. fields["te_modpack_name"]
  42. os.rename(oldpath, targetpath)
  43. pkgmgr.refresh_globals()
  44. pkgmgr.selected_mod = pkgmgr.global_mods:get_current_index(
  45. pkgmgr.global_mods:raw_index_by_uid(fields["te_modpack_name"]))
  46. this:delete()
  47. return true
  48. end
  49. if fields["dlg_rename_modpack_cancel"] then
  50. this:delete()
  51. return true
  52. end
  53. return false
  54. end
  55. --------------------------------------------------------------------------------
  56. function create_rename_modpack_dlg(modpack)
  57. local retval = dialog_create("dlg_delete_mod",
  58. rename_modpack_formspec,
  59. rename_modpack_buttonhandler,
  60. nil)
  61. retval.data.mod = modpack
  62. return retval
  63. end