dialog_window = dialog_window or {}

__inherite(dialog_window, default_lua_widget_handler())--null_lua_widget_handler())

dialog_window.actions = dialog_window.actions or {}

dialog_window.actions.no = 
{
	pressed = function(_window) 
        _window.EndModal(0)
	end
}

dialog_window.actions.yes = 
{
	pressed = function(_window) 
        _window.EndModal(1)
	end
}

function dialog_window.OnChildAction(_this, _action, _child)
	if not _child then return end
	local handler = dialog_window.actions[_child.GetId().c_str()]
	if handler then handler = handler[_action.c_str()] end
	if handler then handler(_this, _child) end
end

function dialog_window.RunQuitDialog(_window)
        local dialog = sf.gui.CWindow()
        dialog.Load(g_App.GetSettings().GetChild("GUI", false).GetChildByAttribute("window", "id", "quit_dialog", true),
            g_App.GetSettings().GetChild("GUITemplates", false))
        dialog.UpdateLayout()
        dialog.SetOffset((_window.GetSize().X - dialog.GetSize().X)/2, (_window.GetSize().Y - dialog.GetSize().Y)/2)
        MoveWindowToCenter(_window, dialog)

        local dialog_ptr = sf.gui.CBaseWindowPtrT(dialog)
        return _window.DoModal(dialog_ptr)
end

function dialog_window.RunCustomDialog(_window, _dialog_id)
        local dialog = sf.gui.CWindow()
        dialog.Load(g_App.GetSettings().GetChild("GUI", false).GetChildByAttribute("window", "id", _dialog_id, true),
            g_App.GetSettings().GetChild("GUITemplates", false))
        dialog.UpdateLayout()
        dialog.SetOffset((_window.GetSize().X - dialog.GetSize().X)/2, (_window.GetSize().Y - dialog.GetSize().Y)/2)
        MoveWindowToCenter(_window, dialog)

        local dialog_ptr = sf.gui.CBaseWindowPtrT(dialog)
        return _window.DoModal(dialog_ptr)
end
