Prompt user before removing server list entry

This commit is contained in:
BeniS 2013-02-24 01:26:49 +13:00
parent 67ed9e21ad
commit 92228e9553
2 changed files with 24 additions and 6 deletions

View File

@ -3,6 +3,7 @@ ServerList = {}
-- private variables
local serverListWindow = nil
local serverTextList = nil
local removeWindow = nil
local servers = {}
-- public functions
@ -69,8 +70,28 @@ function ServerList.add(host, port, protocol, load)
return true
end
function ServerList.remove(host)
servers[host] = nil
function ServerList.remove(widget)
local host = widget:getId()
if removeWindow then
return
end
local yesCallback = function()
widget:destroy()
servers[host] = nil
removeWindow:destroy()
removeWindow=nil
end
local noCallback = function()
removeWindow:destroy()
removeWindow=nil
end
removeWindow = displayGeneralBox(tr('Remove'), tr('Remove '..host..'?'), {
{ text=tr('Yes'), callback=yesCallback },
{ text=tr('No'), callback=noCallback },
anchor=AnchorHorizontalCenter}, yesCallback, noCallback)
end
function ServerList.destroy()

View File

@ -51,10 +51,7 @@ ServerWidget < UIWidget
anchors.right: parent.right
margin-right: 4
margin-top: 1
@onClick: |
local parent = self:getParent()
ServerList.remove(parent:getId())
parent:destroy()
@onClick: ServerList.remove(self:getParent())
MainWindow
id: serverListWindow