Hide uninstall package button on unmodifiable paths (#8255)
authorrubenwardy <rw@rubenwardy.com>
Tue, 5 Mar 2019 07:12:58 +0000 (07:12 +0000)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Tue, 5 Mar 2019 07:12:58 +0000 (08:12 +0100)
builtin/mainmenu/tab_content.lua
src/script/lua_api/l_mainmenu.cpp
src/script/lua_api/l_mainmenu.h

index d8e2c97538cc0034b4bfdc911c7e4afd7d59a302..362fcd8d30f6d21c8c49db89534e21ad32d8fb9d 100644 (file)
@@ -134,9 +134,13 @@ local function get_formspec(tabview, name, tabdata)
                end
 
                retval = retval .. "textarea[5.85,2.2;6.35,2.9;;" ..
-                       fgettext("Information:") .. ";" .. desc .. "]" ..
-                       "button[5.5,4.65;3.25,1;btn_mod_mgr_delete_mod;" ..
-                       fgettext("Uninstall Package") .. "]"
+                       fgettext("Information:") .. ";" .. desc .. "]"
+
+               if core.may_modify_path(selected_pkg.path) then
+                       retval = retval ..
+                               "button[5.5,4.65;3.25,1;btn_mod_mgr_delete_mod;" ..
+                               fgettext("Uninstall Package") .. "]"
+               end
        end
        return retval
 end
index 2557f448abca46b2f20fc565db1d20dbb4b64c40..2094da241b095121932c9e1ed65fb43f3be66e6b 100644 (file)
@@ -867,6 +867,16 @@ bool ModApiMainMenu::mayModifyPath(const std::string &path)
        return false;
 }
 
+
+/******************************************************************************/
+int ModApiMainMenu::l_may_modify_path(lua_State *L)
+{
+       const char *target = luaL_checkstring(L, 1);
+       std::string absolute_destination = fs::RemoveRelativePathComponents(target);
+       lua_pushboolean(L, ModApiMainMenu::mayModifyPath(absolute_destination));
+       return 1;
+}
+
 /******************************************************************************/
 int ModApiMainMenu::l_show_path_select_dialog(lua_State *L)
 {
@@ -1057,6 +1067,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
        API_FCT(delete_dir);
        API_FCT(copy_dir);
        API_FCT(extract_zip);
+       API_FCT(may_modify_path);
        API_FCT(get_mainmenu_path);
        API_FCT(show_path_select_dialog);
        API_FCT(download_file);
@@ -1086,6 +1097,7 @@ void ModApiMainMenu::InitializeAsync(lua_State *L, int top)
        API_FCT(delete_dir);
        API_FCT(copy_dir);
        //API_FCT(extract_zip); //TODO remove dependency to GuiEngine
+       API_FCT(may_modify_path);
        API_FCT(download_file);
        //API_FCT(gettext); (gettext lib isn't threadsafe)
 }
index 4a664359a9d46a55ab67537fb7318380749f787e..9ff8229609956906da1a74b638ba2b0cc1b4b9e1 100644 (file)
@@ -130,6 +130,8 @@ private:
 
        static int l_extract_zip(lua_State *L);
 
+       static int l_may_modify_path(lua_State *L);
+
        static int l_download_file(lua_State *L);
 
        static int l_get_video_drivers(lua_State *L);