-- lib/dfui.lua
-- $Id: dfui.lua,v 1.26 2005/01/23 10:17:25 cpressey Exp $
-- Wrapper/helper/extra abstractions for DFUI in dfuibe_lua.

-- BEGIN lib/dfui.lua --

--[[---------]]--
--[[ Dialogs ]]--
--[[---------]]--

Dialog = {}

Dialog.inform = function(c, msg)
	c:present({
	    id = "inform",
	    name = "Information",
	    short_desc = msg,
	    role = "informative",
	    actions = {
		{
		    id = "ok",
		    name = "OK"
		}
	    }
	})
end

Dialog.confirm = function(c, msg)
	return c:present({
	    id = "confirm",
	    name = "Are you SURE?",
	    short_desc = msg,
	    role = "alert",
	    actions = {
		{
		    id = "ok",
		    name = "OK"
		},
		{
		    id = "cancel",
		    name = "Cancel"
		}
	    }
	}).action_id == "ok"
end

Dialog.select = function(c, msg, map)
	local action = {}
	local consequence = {}
	local id_num = 0
	local k, v

	for k, v in map do
		table.insert(action, {
		    id = tostring(id_num),
		    name = k
		})
		consequence[tostring(id_num)] = v
		id_num = id_num + 1
	end

	return consequence[c:present({
	    id = "select",
	    name = "Please Select",
	    short_desc = msg,
	    role = "informative",
	    actions = action
	}).action_id]
end

-- END of lib/dfui.lua --
