Skip to content

Instantly share code, notes, and snippets.

@Rainrider
Created July 23, 2017 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rainrider/62d56e0d1c40a4311c130fbc3aa89650 to your computer and use it in GitHub Desktop.
Save Rainrider/62d56e0d1c40a4311c130fbc3aa89650 to your computer and use it in GitHub Desktop.
Add validation error popup to AceConfigDialog-3.0
Index: AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.lua
===================================================================
--- AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.lua (revision 1159)
+++ AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.lua (working copy)
@@ -611,6 +611,36 @@
end
end
+local function validationErrorPopup(appName, rootframe, basepath, info, message, ...)
+ if not StaticPopupDialogs["ACECONFIGDIALOG30_VALIDATION_ERROR_DIALOG"] then
+ StaticPopupDialogs["ACECONFIGDIALOG30_VALIDATION_ERROR_DIALOG"] = {}
+ end
+ local t = StaticPopupDialogs["ACECONFIGDIALOG30_VALIDATION_ERROR_DIALOG"]
+ wipe(t)
+ t.text = message
+ t.button1 = OKAY
+ t.preferredIndex = STATICPOPUP_NUMDIALOGS
+ local dialog, oldstrata
+ t.OnAccept = function()
+ if dialog and oldstrata then
+ dialog:SetFrameStrata(oldstrata)
+ end
+ AceConfigDialog:Open(appName, rootframe, unpack(basepath or emptyTbl))
+ end
+ for i = 1, select('#', ...) do
+ t[i] = select(i, ...) or false
+ end
+ t.timeout = 0
+ t.whileDead = 1
+ t.hideOnEscape = 1
+
+ dialog = StaticPopup_Show("ACECONFIGDIALOG30_VALIDATION_ERROR_DIALOG")
+ if dialog then
+ oldstrata = dialog:GetFrameStrata()
+ dialog:SetFrameStrata("TOOLTIP")
+ end
+end
+
local function ActivateControl(widget, event, ...)
--This function will call the set / execute handler for the widget
--widget:GetUserDataTable() contains the needed info
@@ -696,30 +726,23 @@
end
local rootframe = user.rootframe
- if type(validated) == "string" then
- --validate function returned a message to display
- if rootframe.SetStatusText then
- rootframe:SetStatusText(validated)
- else
- -- TODO: do something else.
- end
- PlaySound(PlaySoundKitID and "igPlayerInviteDecline" or 882) -- SOUNDKIT.IG_PLAYER_INVITE_DECLINE || XXX _DECLINE is actually missing from the table
- del(info)
- return true
- elseif not validated then
- --validate returned false
- if rootframe.SetStatusText then
+ if not validated or type(validated) == "string" then
+ --validate function returned a message to display or false
+ if not validated then
if usage then
- rootframe:SetStatusText(name..": "..usage)
+ validated = name .. ": " .. usage
else
if pattern then
- rootframe:SetStatusText(name..": Expected "..pattern)
+ validated = name .. ": Expected " .. pattern
else
- rootframe:SetStatusText(name..": Invalid Value")
+ validated = name .. ": Invalid value"
end
end
+ end
+ if rootframe.SetStatusText then
+ rootframe:SetStatusText(validated)
else
- -- TODO: do something else
+ validationErrorPopup(user.appName, rootframe, basepath, info, validated, ...)
end
PlaySound(PlaySoundKitID and "igPlayerInviteDecline" or 882) -- SOUNDKIT.IG_PLAYER_INVITE_DECLINE || XXX _DECLINE is actually missing from the table
del(info)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment