dlg_overwrite.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --Luanti
  2. --Copyright (C) 2018-24 rubenwardy
  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. function get_formspec(data)
  18. local package = data.package
  19. return confirmation_formspec(
  20. fgettext("\"$1\" already exists. Would you like to overwrite it?", package.name),
  21. 'install', fgettext("Overwrite"),
  22. 'cancel', fgettext("Cancel"))
  23. end
  24. local function handle_submit(this, fields)
  25. local data = this.data
  26. if fields.cancel then
  27. this:delete()
  28. return true
  29. end
  30. if fields.install then
  31. this:delete()
  32. data.callback()
  33. return true
  34. end
  35. return false
  36. end
  37. function create_confirm_overwrite(package, callback)
  38. assert(type(package) == "table")
  39. assert(type(callback) == "function")
  40. local dlg = dialog_create("data", get_formspec, handle_submit, nil)
  41. dlg.data.package = package
  42. dlg.data.callback = callback
  43. return dlg
  44. end