]> git.lizzy.rs Git - minetest.git/blob - builtin/mainmenu/dlg_rename_modpack.lua
Mainmenu: Refactor tab UI code
[minetest.git] / builtin / mainmenu / dlg_rename_modpack.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 rename_modpack_formspec(dialogdata)
21         
22         dialogdata.mod = modmgr.global_mods:get_list()[dialogdata.selected]
23
24         local retval =
25                 "size[12.4,5,true]" ..
26                 "label[1.75,1;".. fgettext("Rename Modpack:") .. "]"..
27                 "field[4.5,1.4;6,0.5;te_modpack_name;;" ..
28                 dialogdata.mod.name ..
29                 "]" ..
30                 "button[5,4.2;2.6,0.5;dlg_rename_modpack_confirm;"..
31                                 fgettext("Accept") .. "]" ..
32                 "button[7.5,4.2;2.8,0.5;dlg_rename_modpack_cancel;"..
33                                 fgettext("Cancel") .. "]"
34         
35         return retval
36 end
37
38 --------------------------------------------------------------------------------
39 local function rename_modpack_buttonhandler(this, fields)
40         if fields["dlg_rename_modpack_confirm"] ~= nil then
41                 local oldpath = core.get_modpath() .. DIR_DELIM .. this.data.mod.name
42                 local targetpath = core.get_modpath() .. DIR_DELIM .. fields["te_modpack_name"]
43                 core.copy_dir(oldpath,targetpath,false)
44                 modmgr.refresh_globals()
45                 modmgr.selected_mod = modmgr.global_mods:get_current_index(
46                         modmgr.global_mods:raw_index_by_uid(fields["te_modpack_name"]))
47                         
48                 this:delete()
49                 return true
50         end
51         
52         if fields["dlg_rename_modpack_cancel"] then
53                 this:delete()
54                 return true
55         end
56
57         return false
58 end
59
60 --------------------------------------------------------------------------------
61 function create_rename_modpack_dlg(selected_index)
62
63         local retval = dialog_create("dlg_delete_mod",
64                                         rename_modpack_formspec,
65                                         rename_modpack_buttonhandler,
66                                         nil)
67         retval.data.selected = selected_index
68         return retval
69 end