]> git.lizzy.rs Git - minetest.git/blob - builtin/mainmenu/dlg_delete_mod.lua
Fix world config menu ignoring `name` in `mod.conf`.
[minetest.git] / builtin / mainmenu / dlg_delete_mod.lua
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 --------------------------------------------------------------------------------
19
20 local function delete_mod_formspec(dialogdata)
21         
22         dialogdata.mod = modmgr.global_mods:get_list()[dialogdata.selected]
23
24         local retval =
25                 "size[12.4,5,true]" ..
26                 "field[1.75,1;10,3;;" .. fgettext("Are you sure you want to delete \"$1\"?", dialogdata.mod.name) ..  ";]"..
27                 "button[4,4.2;1,0.5;dlg_delete_mod_confirm;" .. fgettext("Yes") .. "]" ..
28                 "button[6.5,4.2;3,0.5;dlg_delete_mod_cancel;" .. fgettext("No of course not!") .. "]"
29         
30         return retval
31 end
32
33 --------------------------------------------------------------------------------
34 local function delete_mod_buttonhandler(this, fields)
35         if fields["dlg_delete_mod_confirm"] ~= nil then
36
37                 if this.data.mod.path ~= nil and
38                         this.data.mod.path ~= "" and
39                         this.data.mod.path ~= core.get_modpath() then
40                         if not core.delete_dir(this.data.mod.path) then
41                                 gamedata.errormessage = fgettext("Modmgr: failed to delete \"$1\"", this.data.mod.path)
42                         end
43                         modmgr.refresh_globals()
44                 else
45                         gamedata.errormessage = fgettext("Modmgr: invalid modpath \"$1\"", this.data.mod.path)
46                 end
47                 this:delete()
48                 return true
49         end
50         
51         if fields["dlg_delete_mod_cancel"] then
52                 this:delete()
53                 return true
54         end
55
56         return false
57 end
58
59 --------------------------------------------------------------------------------
60 function create_delete_mod_dlg(selected_index)
61
62         local retval = dialog_create("dlg_delete_mod",
63                                         delete_mod_formspec,
64                                         delete_mod_buttonhandler,
65                                         nil)
66         retval.data.selected = selected_index
67         return retval
68 end