From c31646cd1f1d5fd45edf58f917eec2dcc0cfe90b Mon Sep 17 00:00:00 2001 From: shagu Date: Sat, 31 Dec 2016 14:53:22 +0100 Subject: [PATCH] api: always hide question dialog on button event --- env/api.lua | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/env/api.lua b/env/api.lua index f7bf04da..7d9cc1a9 100644 --- a/env/api.lua +++ b/env/api.lua @@ -227,24 +227,14 @@ function pfUI.api:CreateQuestionDialog(text, yes, no, editbox) return end - -- add default values - if not yes then - yes = function() message("You clicked OK") end - end - - if not no then - no = function() this:GetParent():Hide() end - end - - if not text then - text = "Are you sure?" - end + if not text then text = "Are you sure?" end local border = tonumber(pfUI_config.appearance.border.default) local padding = 15 -- frame local question = CreateFrame("Frame", "pfQuestionDialog", UIParent) + question:ClearAllPoints() question:SetPoint("CENTER", 0, 0) question:SetFrameStrata("TOOLTIP") question:SetMovable(true) @@ -286,7 +276,10 @@ function pfUI.api:CreateQuestionDialog(text, yes, no, editbox) question.yes:SetWidth(100) question.yes:SetHeight(20) question.yes:SetText("Okay") - question.yes:SetScript("OnClick", yes) + question.yes:SetScript("OnClick", function() + if yes then yes() end + this:GetParent():Hide() + end) if question.input then question.yes:SetPoint("TOPLEFT", question.input, "BOTTOMLEFT", -border, -padding) @@ -299,7 +292,10 @@ function pfUI.api:CreateQuestionDialog(text, yes, no, editbox) question.no:SetWidth(85) question.no:SetHeight(20) question.no:SetText("Cancel") - question.no:SetScript("OnClick", no) + question.no:SetScript("OnClick", function() + if no then no() end + this:GetParent():Hide() + end) if question.input then question.no:SetPoint("TOPRIGHT", question.input, "BOTTOMRIGHT", border, -padding) @@ -339,7 +335,6 @@ function pfUI.api:CreateQuestionDialog(text, yes, no, editbox) local width = 200 if question.text:GetStringWidth() > 200 then width = question.text:GetStringWidth() end question:SetWidth( width + 2*padding) - end -- [ Bar Layout Options ] --