dlg_overwrite.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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