dlg_rename_modpack.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. -- Luanti
  2. -- Copyright (C) 2014 sapier
  3. -- SPDX-License-Identifier: LGPL-2.1-or-later
  4. --------------------------------------------------------------------------------
  5. local function rename_modpack_formspec(dialogdata)
  6. local retval =
  7. "size[11.5,4.5,true]" ..
  8. "button[3.25,3.5;2.5,0.5;dlg_rename_modpack_confirm;"..
  9. fgettext("Accept") .. "]" ..
  10. "button[5.75,3.5;2.5,0.5;dlg_rename_modpack_cancel;"..
  11. fgettext("Cancel") .. "]"
  12. local input_y = 2
  13. if dialogdata.mod.is_name_explicit then
  14. retval = retval .. "textarea[1,0.2;10,2;;;" ..
  15. fgettext("This modpack has an explicit name given in its modpack.conf " ..
  16. "which will override any renaming here.") .. "]"
  17. input_y = 2.5
  18. end
  19. retval = retval ..
  20. "field[2.5," .. input_y .. ";7,0.5;te_modpack_name;" ..
  21. fgettext("Rename Modpack:") .. ";" .. dialogdata.mod.dir_name .. "]"
  22. return retval
  23. end
  24. --------------------------------------------------------------------------------
  25. local function rename_modpack_buttonhandler(this, fields)
  26. if fields["dlg_rename_modpack_confirm"] ~= nil then
  27. local oldpath = this.data.mod.path
  28. local targetpath = this.data.mod.parent_dir .. DIR_DELIM .. fields["te_modpack_name"]
  29. os.rename(oldpath, targetpath)
  30. pkgmgr.reload_global_mods()
  31. pkgmgr.selected_mod = pkgmgr.global_mods:get_current_index(
  32. pkgmgr.global_mods:raw_index_by_uid(fields["te_modpack_name"]))
  33. this:delete()
  34. return true
  35. end
  36. if fields["dlg_rename_modpack_cancel"] then
  37. this:delete()
  38. return true
  39. end
  40. return false
  41. end
  42. --------------------------------------------------------------------------------
  43. function create_rename_modpack_dlg(modpack)
  44. local retval = dialog_create("dlg_delete_mod",
  45. rename_modpack_formspec,
  46. rename_modpack_buttonhandler,
  47. nil)
  48. retval.data.mod = modpack
  49. return retval
  50. end