local c=LibStub local z=c("\065\099\101\071\085\073-\051\046\048")local Y=c("\065\099\101\067\111\110\102\105\103\082\101\103\105\115\116\114\121-\051\046\048")local k,O="\065\099\101\067\111\110\102\105\103\068\105\097\108\111\103-\051\046\048",86 local u,N=c:NewLibrary(k,O)if not u then return end u.OpenFrames=u.OpenFrames or{}u.Status=u.Status or{}u.frame=u.frame or CreateFrame("\070\114\097\109\101")u.tooltip=u.tooltip or CreateFrame("\071\097\109\101\084\111\111\108\116\105\112","\065\099\101\067\111\110\102\105\103\068\105\097\108\111\103\084\111\111\108\116\105\112",UIParent,"\071\097\109\101\084\111\111\108\116\105\112\084\101\109\112\108\097\116\101")u.frame.apps=u.frame.apps or{}u.frame.closing=u.frame.closing or{}u.frame.closeAllOverride=u.frame.closeAllOverride or{}local P,I,j,n=table.insert,table.sort,table.remove,table.wipe local M,S=string.match,string.format local X=error local F,m,y,x,w,L=pairs,next,select,type,unpack,ipairs local e,q=tostring,tonumber local a,v,p=math.min,math.max,math.floor local Q={}local f=xpcall local function t(c)return(geterrorhandler())(c)end local function K(c,...)if c then return f(c,t,...)end end local C=170 local W,E,s do local c=setmetatable({},{__mode="\107"})function W()local z=m(c)if z then c[z]=nil return z else return{}end end function s(c)local z=W()for c,Y in F(c)do z[c]=Y end return z end function E(z)n(z)c[z]=true end end local function V(...)for c=1,y("\035",...),1 do if y(c,...)~=nil then return y(c,...)end end end local function i(c,z)if c.plugins then for c,Y in F(c.plugins)do if Y[z]then return Y[z]end end end return c.args[z]end local B={set=true,get=true;func=true,confirm=true;validate=true,disabled=true;hidden=true}local D={name=true,desc=true;icon=true;usage=true,width=true;image=true;fontSize=true,tooltipHyperlink=true}local R={type=true;descStyle=true,imageWidth=true;imageHeight=true}local function d(c,z,Y,O,u,...)local N=B[c]local P if N then local z=Y if z[c]~=nil then P=z[c]end for Y=1,#O,1 do z=i(z,O[Y])if z[c]~=nil then P=z[c]end end else P=z[c]end if not R[c]and(x(P)=="\102\117\110\099\116\105\111\110"or not D[c]and x(P)=="\115\116\114\105\110\103")then local N=W()local I=Y local j=I.handler for c=1,#O,1 do I=i(I,O[c])N[c]=O[c]j=I.handler or j end N.options=Y N.appName=u N[0]=u N.arg=z.arg N.handler=j N.option=z N.type=z.type N.uiType="\100\105\097\108\111\103"N.uiName=k local n,M,F,m if x(P)=="\102\117\110\099\116\105\111\110"then n,M,F,m=P(N,...)else if j and j[P]then n,M,F,m=j[P](j,N,...)else X(S("\077\101\116\104\111\100 \037\115 \100\111\101\115\110\'\116 \101\120\105\115\116 \105\110 \104\097\110\100\108\101\114 \102\111\114 \116\121\112\101 \037\115",P,c))end end E(N)return n,M,F,m else return P end end local A local Z local function b(c,z)if not c then return true end if not z then return false end local Y,k=A[c]or 100,A[z]or 100 if Y==k then local Y=x(Z[c])=="\115\116\114\105\110\103"and Z[c]or""local k=x(Z[z])=="\115\116\114\105\110\103"and Z[z]or""return Y:upper()<k:upper()end if Y<0 then if k>=0 then return false end else if k<0 then return true end end return Y<k end local function l(c,z,Y,k,O,u)A=W()Z=W()if c.plugins then for c,N in F(c.plugins)do for c,N in F(N)do if not Y[c]then P(z,c)Y[c]=N O[#O+1]=c A[c]=d("\111\114\100\101\114",N,k,O,u)Z[c]=d("\110\097\109\101",N,k,O,u)O[#O]=nil end end end end for c,N in F(c.args)do if not Y[c]then P(z,c)Y[c]=N O[#O+1]=c A[c]=d("\111\114\100\101\114",N,k,O,u)Z[c]=d("\110\097\109\101",N,k,O,u)O[#O]=nil end end I(z,b)E(A)E(Z)end local function G(c)if c.children then local z=c.children for c=1,#z,1 do G(z[c])E(z[c])end E(z)end end local function g(c,z)local Y=c:GetUserDataTable()if Y.path then E(Y.path)end if c.type=="\084\114\101\101\071\114\111\117\112"then local z=Y.tree c:SetTree(nil)if z then for c=1,#z,1 do G(z[c])E(z[c])end E(z)end end if c.type=="\084\097\098\071\114\111\117\112"then c:SetTabs(nil)if Y.tablist then E(Y.tablist)end end if c.type=="\068\114\111\112\100\111\119\110\071\114\111\117\112"then c:SetGroupList(nil)if Y.grouplist then E(Y.grouplist)end if Y.orderlist then E(Y.orderlist)end end end function u.GetStatusTable(Y,c,z)local k=Y.Status if not k[c]then k[c]={}k[c].status={}k[c].children={}end k=k[c]if z then for c=1,#z,1 do local Y=z[c]if not k.children[Y]then k.children[Y]={}k.children[Y].status={}k.children[Y].children={}end k=k.children[Y]end end return k.status end function u.SelectGroup(z,c,...)local O=W()local u=Y:GetOptionsTable(c)if not u then X(("\037\115 \105\115\110\'\116 \114\101\103\105\115\116\101\100 \119\105\116\104 \065\099\101\067\111\110\102\105\103\082\101\103\105\115\116\114\121\044 \117\110\097\098\108\101 \116\111 \111\112\101\110 \099\111\110\102\105\103"):format(c),2)end local N=u("\100\105\097\108\111\103",k)local I=N local j=z:GetStatusTable(c,O)if not j.groups then j.groups={}end j=j.groups local n local M for Y=1,y("\035",...),1 do local k=y(Y,...)if I.childGroups=="\116\097\098"or I.childGroups=="\115\101\108\101\099\116"then j.selected=k n=nil else if n then n=n..("\001"..k)else n=k if not j.groups then j.groups={}end M=j end M.selected=n M.groups[n]=true end I=i(I,k)if not I then break end P(O,k)j=z:GetStatusTable(c,O)if not j.groups then j.groups={}end j=j.groups end E(O)Y:NotifyChange(c)end local function h(c,z)local Y=c:GetUserDataTable()local k=Y.option local O=Y.options local N=Y.path local P=Y.appName local I=u.tooltip I:SetOwner(c.frame,"\065\078\067\072\079\082\095\084\079\080\082\073\071\072\084")local j=d("\116\111\111\108\116\105\112\072\121\112\101\114\108\105\110\107",k,O,N,P)if j then I:SetHyperlink(j)I:Show()return end local n=d("\110\097\109\101",k,O,N,P)local M=d("\100\101\115\099",k,O,N,P)local S=d("\117\115\097\103\101",k,O,N,P)local X=k.descStyle if X and X~="\116\111\111\108\116\105\112"then return end I:SetText(n,1,.82,0,true)if k.type=="\109\117\108\116\105\115\101\108\101\099\116"then I:AddLine(Y.text,.5,.5,.8,true)end if x(M)=="\115\116\114\105\110\103"then I:AddLine(M,1,1,1,true)end if x(S)=="\115\116\114\105\110\103"then I:AddLine("\085\115\097\103\101\058 "..S,NORMAL_FONT_COLOR.r,NORMAL_FONT_COLOR.g,NORMAL_FONT_COLOR.b,true)end I:Show()end local function J(c,z)u.tooltip:Hide()end local function U(c)if c.type=="\101\120\101\099\117\116\101"then return"\102\117\110\099"else return"\115\101\116"end end do local c=u.popup if not c or N<81 then c=CreateFrame("\070\114\097\109\101",nil,UIParent)u.popup=c c:Hide()c:SetPoint("\067\069\078\084\069\082",UIParent,"\067\069\078\084\069\082")c:SetSize(320,72)c:EnableMouse(true)c:SetFrameStrata("\084\079\079\076\084\073\080")c:SetFrameLevel(100)c:SetScript("\079\110\075\101\121\068\111\119\110",function(c,z)if z=="\069\083\067\065\080\069"then c:SetPropagateKeyboardInput(false)if c.cancel:IsShown()then c.cancel:Click()else c:Hide()end else c:SetPropagateKeyboardInput(true)end end)local z=CreateFrame("\070\114\097\109\101",nil,c,"\068\105\097\108\111\103\066\111\114\100\101\114\079\112\097\113\117\101\084\101\109\112\108\097\116\101")z:SetAllPoints(c)c:SetFixedFrameStrata(true)c:SetFixedFrameLevel(true)local Y=c:CreateFontString(nil,"\065\082\084\087\079\082\075","\071\097\109\101\070\111\110\116\072\105\103\104\108\105\103\104\116")Y:SetSize(290,0)Y:SetPoint("\084\079\080",0,-16)c.text=Y local function k(z)local Y=CreateFrame("\066\117\116\116\111\110",nil,c)Y:SetSize(128,21)Y:SetNormalFontObject(GameFontNormal)Y:SetHighlightFontObject(GameFontHighlight)Y:SetNormalTexture(130763);(Y:GetNormalTexture()):SetTexCoord(.0,1.0,.0,.71875)Y:SetPushedTexture(130761);(Y:GetPushedTexture()):SetTexCoord(.0,1.0,.0,.71875)Y:SetHighlightTexture(130762);(Y:GetHighlightTexture()):SetTexCoord(.0,1.0,.0,.71875)Y:SetText(z)return Y end local O=k(ACCEPT)O:SetPoint("\066\079\084\084\079\077\082\073\071\072\084",c,"\066\079\084\084\079\077",-6,16)c.accept=O local N=k(CANCEL)N:SetPoint("\076\069\070\084",O,"\082\073\071\072\084",13,0)c.cancel=N end end local function H(c,z,Y,k,O,N,...)local P=u.popup P:Show()P.text:SetText(O)local I=61+P.text:GetHeight()P:SetHeight(I)P.accept:ClearAllPoints()P.accept:SetPoint("\066\079\084\084\079\077\082\073\071\072\084",P,"\066\079\084\084\079\077",-6,16)P.cancel:Show()local j={...}local n=y("\035",...)P.accept:SetScript("\079\110\067\108\105\099\107",function(O)K(N,w(j,1,n))u:Open(c,z,w(Y or Q))P:Hide()O:SetScript("\079\110\067\108\105\099\107",nil)P.cancel:SetScript("\079\110\067\108\105\099\107",nil)E(k)end)P.cancel:SetScript("\079\110\067\108\105\099\107",function(O)u:Open(c,z,w(Y or Q))P:Hide()O:SetScript("\079\110\067\108\105\099\107",nil)P.accept:SetScript("\079\110\067\108\105\099\107",nil)E(k)end)end local function o(c)local z=u.popup z:Show()z.text:SetText(c)local Y=61+z.text:GetHeight()z:SetHeight(Y)z.accept:ClearAllPoints()z.accept:SetPoint("\066\079\084\084\079\077",z,"\066\079\084\084\079\077",0,16)z.cancel:Hide()z.accept:SetScript("\079\110\067\108\105\099\107",function()z:Hide()end)end local function T(c,z,...)local Y=c:GetUserDataTable()local O=Y.option local N=Y.options local P=Y.path local I=W()local j local n=N local F=U(O)local m local y local L if n[F]~=nil then j=n[F]end m=n.handler y=n.confirm L=n.validate for c=1,#P,1 do local z=P[c]n=i(n,z)I[c]=z if n[F]~=nil then j=n[F]end m=n.handler or m if n.confirm~=nil then y=n.confirm end if n.validate~=nil then L=n.validate end end I.options=N I.appName=Y.appName I.arg=O.arg I.handler=m I.option=O I.type=O.type I.uiType="\100\105\097\108\111\103"I.uiName=k local e if x(O.name)=="\102\117\110\099\116\105\111\110"then e=O.name(I)elseif x(O.name)=="\115\116\114\105\110\103"then e=O.name else e=""end local q=O.usage local a=O.pattern local v=true if O.type=="\105\110\112\117\116"then if x(a)=="\115\116\114\105\110\103"then if not M(...,a)then v=false end end end local p if v and O.type~="\101\120\101\099\117\116\101"then if x(L)=="\115\116\114\105\110\103"then if m and m[L]then p,v=K(m[L],m,I,...)if not p then v=false end else X(S("\077\101\116\104\111\100 \037\115 \100\111\101\115\110\'\116 \101\120\105\115\116 \105\110 \104\097\110\100\108\101\114 \102\111\114 \116\121\112\101 \101\120\101\099\117\116\101",L))end elseif x(L)=="\102\117\110\099\116\105\111\110"then p,v=K(L,I,...)if not p then v=false end end end if not v or x(v)=="\115\116\114\105\110\103"then if not v then if q then v=e..("\058 "..q)else if a then v=e..("\058 \069\120\112\101\099\116\101\100 "..a)else v=e.."\058 \073\110\118\097\108\105\100 \086\097\108\117\101"end end end if Y.rootframe.SetStatusText then Y.rootframe:SetStatusText(v)else o(v)end PlaySound(882)E(I)return true else local c=O.confirmText if x(y)=="\115\116\114\105\110\103"then if m and m[y]then p,y=K(m[y],m,I,...)if p and x(y)=="\115\116\114\105\110\103"then c=y y=true elseif not p then y=false end else X(S("\077\101\116\104\111\100 \037\115 \100\111\101\115\110\'\116 \101\120\105\115\116 \105\110 \104\097\110\100\108\101\114 \102\111\114 \116\121\112\101 \099\111\110\102\105\114\109",y))end elseif x(y)=="\102\117\110\099\116\105\111\110"then p,y=K(y,I,...)if p and x(y)=="\115\116\114\105\110\103"then c=y y=true elseif not p then y=false end end if x(y)=="\098\111\111\108\101\097\110"then if y then if not c then local z,Y=O.name,O.desc if x(z)=="\102\117\110\099\116\105\111\110"then z=z(I)end if x(Y)=="\102\117\110\099\116\105\111\110"then Y=Y(I)end c=z if Y then c=c..(" - "..Y)end end local z=Y.rootframe:GetUserData("\105\115\099\117\115\116\111\109")local k if z then k=Y.rootframe end local u=Y.rootframe:GetUserData("\098\097\115\101\112\097\116\104")if x(j)=="\115\116\114\105\110\103"then if m and m[j]then H(Y.appName,k,u,I,c,m[j],m,I,...)else X(S("\077\101\116\104\111\100 \037\115 \100\111\101\115\110\'\116 \101\120\105\115\116 \105\110 \104\097\110\100\108\101\114 \102\111\114 \116\121\112\101 \102\117\110\099",j))end elseif x(j)=="\102\117\110\099\116\105\111\110"then H(Y.appName,k,u,I,c,j,I,...)end return end end if x(j)=="\115\116\114\105\110\103"then if m and m[j]then K(m[j],m,I,...)else X(S("\077\101\116\104\111\100 \037\115 \100\111\101\115\110\'\116 \101\120\105\115\116 \105\110 \104\097\110\100\108\101\114 \102\111\114 \116\121\112\101 \102\117\110\099",j))end elseif x(j)=="\102\117\110\099\116\105\111\110"then K(j,I,...)end local k=Y.rootframe:GetUserData("\105\115\099\117\115\116\111\109")local N=Y.rootframe:GetUserData("\098\097\115\101\112\097\116\104")or Q if O.type=="\099\111\108\111\114"then if z=="\079\110\086\097\108\117\101\067\111\110\102\105\114\109\101\100"then if k then u:Open(Y.appName,Y.rootframe,w(N))else u:Open(Y.appName,w(N))end end elseif O.type=="\114\097\110\103\101"then if z=="\079\110\077\111\117\115\101\085\112"then if k then u:Open(Y.appName,Y.rootframe,w(N))else u:Open(Y.appName,w(N))end end elseif O.type=="\109\117\108\116\105\115\101\108\101\099\116"then Y.valuechanged=true else if k then u:Open(Y.appName,Y.rootframe,w(N))else u:Open(Y.appName,w(N))end end end E(I)end local function r(c,z,Y)local k=c:GetUserData("\111\112\116\105\111\110")local O,u,N=k.min or not k.softMin and 0 or nil,k.max or not k.softMax and 100 or nil,k.step if O then if N then Y=p((Y-O)/N+.5)*N+O end Y=v(Y,O)end if u then Y=a(Y,u)end T(c,z,Y)end local function c9(c,z,...)T(c,z,c:GetUserData("\118\097\108\117\101"),...)local Y=c:GetUserDataTable()local k=Y.rootframe:GetUserData("\105\115\099\117\115\116\111\109")local O=Y.rootframe:GetUserData("\098\097\115\101\112\097\116\104")or Q if k then u:Open(Y.appName,Y.rootframe,w(O))else u:Open(Y.appName,w(O))end end local function z9(c,z,...)local Y=c:GetUserDataTable()if Y.valuechanged and not c:IsReleasing()then local c=Y.rootframe:GetUserData("\105\115\099\117\115\116\111\109")local z=Y.rootframe:GetUserData("\098\097\115\101\112\097\116\104")or Q if c then u:Open(Y.appName,Y.rootframe,w(z))else u:Open(Y.appName,w(z))end end end local function Y9(c,Y)local k=c:GetUserData("\097\112\112\078\097\109\101")u.OpenFrames[k]=nil z:Release(c)end local function k9(c,z,Y,k)local O=V(c.dialogHidden,c.guiHidden)if O~=nil then return O end return d("\104\105\100\100\101\110",c,z,Y,k)end local function O9(c,z,Y,k)local O=V(c.dialogDisabled,c.guiDisabled)if O~=nil then return O end return d("\100\105\115\097\098\108\101\100",c,z,Y,k)end local function u9(c,z,Y,k)local O=W()local u=W()local N=W()local I=W()l(c,N,I,z,Y,k)for c=1,#N,1 do local j=N[c]local n=I[j]if n.type=="\103\114\111\117\112"then Y[#Y+1]=j local c=V(n.dialogInline,n.guiInline,n.inline,false)local N=k9(n,z,Y,k)if not c and not N then O[j]=d("\110\097\109\101",n,z,Y,k)P(u,j)end Y[#Y]=nil end end E(I)E(N)return O,u end local function N9(c,z,Y,k,O)local u=W()local N=W()l(c,u,N,Y,k,O)for c=1,#u,1 do local I=u[c]local j=N[I]if j.type=="\103\114\111\117\112"then k[#k+1]=I local c=V(j.dialogInline,j.guiInline,j.inline,false)local u=k9(j,Y,k,O)if not c and not u then local c=W()c.value=I c.text=d("\110\097\109\101",j,Y,k,O)c.icon=d("\105\099\111\110",j,Y,k,O)c.iconCoords=d("\105\099\111\110\067\111\111\114\100\115",j,Y,k,O)c.disabled=O9(j,Y,k,O)if not z.children then z.children=W()end P(z.children,c)if(j.childGroups or"\116\114\101\101")=="\116\114\101\101"then N9(j,c,Y,k,O)end end k[#k]=nil end end E(u)E(N)end local function P9(c,z,Y,k,O)local u=W()local N=W()local I=W()l(c,N,I,z,Y,k)for c=1,#N,1 do local j=N[c]local n=I[j]if n.type=="\103\114\111\117\112"then Y[#Y+1]=j local c=V(n.dialogInline,n.guiInline,n.inline,false)local N=k9(n,z,Y,k)if not c and not N then local c=W()c.value=j c.text=d("\110\097\109\101",n,z,Y,k)c.icon=d("\105\099\111\110",n,z,Y,k)c.iconCoords=d("\105\099\111\110\067\111\111\114\100\115",n,z,Y,k)c.disabled=O9(n,z,Y,k)P(u,c)if O and(n.childGroups or"\116\114\101\101")=="\116\114\101\101"then N9(n,c,z,Y,k)end end Y[#Y]=nil end end E(N)E(I)return u end local function I9(c,z,Y,k,O,u)local N=c:GetUserDataTable()for c=1,#k,1 do N[c]=k[c]end N.rootframe=O N.option=Y N.options=z N.path=s(k)N.appName=u c:SetCallback("\079\110\082\101\108\101\097\115\101",g)c:SetCallback("\079\110\076\101\097\118\101",J)c:SetCallback("\079\110\069\110\116\101\114",h)end local function j9(c,Y)local k if c then k=z:Create(c)if not k then(geterrorhandler())(("\073\110\118\097\108\105\100 \067\117\115\116\111\109 \067\111\110\116\114\111\108 \084\121\112\101 - \037\115"):format(e(c)))end end if not k then k=z:Create(Y)end return k end local function n9(c,z)return e(c)<e(z)end local function M9(c,Y,k,O,u,N,n)local M=W()local S=W()l(N,M,S,Y,u,c)for N=1,#M,1 do local X=M[N]local m=S[X]P(u,X)local y=k9(m,Y,u,c)local a=d("\110\097\109\101",m,Y,u,c)if not y then if m.type=="\103\114\111\117\112"then if n or V(m.dialogInline,m.guiInline,m.inline,false)then local N if a and a~=""then N=z:Create("\073\110\108\105\110\101\071\114\111\117\112")N:SetTitle(a or"")else N=z:Create("\083\105\109\112\108\101\071\114\111\117\112")end N.width="\102\105\108\108"N:SetLayout("\102\108\111\119")k:AddChild(N)M9(c,Y,N,O,u,m,true)end else local N if m.type=="\101\120\101\099\117\116\101"then local z=d("\105\109\097\103\101\067\111\111\114\100\115",m,Y,u,c)local k,O,P=d("\105\109\097\103\101",m,Y,u,c)local I=x(k)=="\115\116\114\105\110\103"or x(k)=="\110\117\109\098\101\114"N=j9(m.dialogControl or m.control,I and"\073\099\111\110"or"\066\117\116\116\111\110")if I then if not O then O=d("\105\109\097\103\101\087\105\100\116\104",m,Y,u,c)end if not P then P=d("\105\109\097\103\101\072\101\105\103\104\116",m,Y,u,c)end if x(z)=="\116\097\098\108\101"then N:SetImage(k,w(z))else N:SetImage(k)end if x(O)~="\110\117\109\098\101\114"then O=32 end if x(P)~="\110\117\109\098\101\114"then P=32 end N:SetImageSize(O,P)N:SetLabel(a)else N:SetText(a)end N:SetCallback("\079\110\067\108\105\099\107",T)elseif m.type=="\105\110\112\117\116"then N=j9(m.dialogControl or m.control,m.multiline and"\077\117\108\116\105\076\105\110\101\069\100\105\116\066\111\120"or"\069\100\105\116\066\111\120")if m.multiline and N.SetNumLines then N:SetNumLines(q(m.multiline)or 4)end N:SetLabel(a)N:SetCallback("\079\110\069\110\116\101\114\080\114\101\115\115\101\100",T)local z=d("\103\101\116",m,Y,u,c)if x(z)~="\115\116\114\105\110\103"then z=""end N:SetText(z)elseif m.type=="\116\111\103\103\108\101"then N=j9(m.dialogControl or m.control,"\067\104\101\099\107\066\111\120")N:SetLabel(a)N:SetTriState(m.tristate)local z=d("\103\101\116",m,Y,u,c)N:SetValue(z)N:SetCallback("\079\110\086\097\108\117\101\067\104\097\110\103\101\100",T)if m.descStyle=="\105\110\108\105\110\101"then local z=d("\100\101\115\099",m,Y,u,c)N:SetDescription(z)end local k=d("\105\109\097\103\101",m,Y,u,c)local O=d("\105\109\097\103\101\067\111\111\114\100\115",m,Y,u,c)if x(k)=="\115\116\114\105\110\103"or x(k)=="\110\117\109\098\101\114"then if x(O)=="\116\097\098\108\101"then N:SetImage(k,w(O))else N:SetImage(k)end end elseif m.type=="\114\097\110\103\101"then N=j9(m.dialogControl or m.control,"\083\108\105\100\101\114")N:SetLabel(a)N:SetSliderValues(m.softMin or m.min or 0,m.softMax or m.max or 100,m.bigStep or m.step or 0)N:SetIsPercent(m.isPercent)local z=d("\103\101\116",m,Y,u,c)if x(z)~="\110\117\109\098\101\114"then z=0 end N:SetValue(z)N:SetCallback("\079\110\086\097\108\117\101\067\104\097\110\103\101\100",r)N:SetCallback("\079\110\077\111\117\115\101\085\112",r)elseif m.type=="\115\101\108\101\099\116"then local k=d("\118\097\108\117\101\115",m,Y,u,c)local P=d("\115\111\114\116\105\110\103",m,Y,u,c)if m.style=="\114\097\100\105\111"then local j=O9(m,Y,u,c)local n=d("\119\105\100\116\104",m,Y,u,c)N=z:Create("\073\110\108\105\110\101\071\114\111\117\112")N:SetLayout("\070\108\111\119")N:SetTitle(a)N.width="\102\105\108\108"N:PauseLayout()local M=d("\103\101\116",m,Y,u,c)if not P then P={}for c,z in F(k)do P[#P+1]=c end I(P,n9)end for P,I in L(P)do local S=k[I]local X=z:Create("\067\104\101\099\107\066\111\120")X:SetLabel(S)X:SetUserData("\118\097\108\117\101",I)X:SetUserData("\116\101\120\116",S)X:SetDisabled(j)X:SetType("\114\097\100\105\111")X:SetValue(M==I)X:SetCallback("\079\110\086\097\108\117\101\067\104\097\110\103\101\100",c9)I9(X,Y,m,u,O,c)N:AddChild(X)if n=="\100\111\117\098\108\101"then X:SetWidth(C*2)elseif n=="\104\097\108\102"then X:SetWidth(C/2)elseif x(n)=="\110\117\109\098\101\114"then X:SetWidth(C*n)elseif n=="\102\117\108\108"then X.width="\102\105\108\108"else X:SetWidth(C)end end N:ResumeLayout()N:DoLayout()else N=j9(m.dialogControl or m.control,"\068\114\111\112\100\111\119\110")local O=m.itemControl if O and not z:GetWidgetVersion(O)then(geterrorhandler())(("\073\110\118\097\108\105\100 \067\117\115\116\111\109 \073\116\101\109 \084\121\112\101 - \037\115"):format(e(O)))O=nil end N:SetLabel(a)N:SetList(k,P,O)local I=d("\103\101\116",m,Y,u,c)if not k[I]then I=nil end N:SetValue(I)N:SetCallback("\079\110\086\097\108\117\101\067\104\097\110\103\101\100",T)end elseif m.type=="\109\117\108\116\105\115\101\108\101\099\116"then local k=d("\118\097\108\117\101\115",m,Y,u,c)local j=O9(m,Y,u,c)local n=W()if k then for c,z in F(k)do P(n,c)end end I(n)local M=m.dialogControl or m.control if M then N=z:Create(M)if not N then(geterrorhandler())(("\073\110\118\097\108\105\100 \067\117\115\116\111\109 \067\111\110\116\114\111\108 \084\121\112\101 - \037\115"):format(e(M)))end end if N then N:SetMultiselect(true)N:SetLabel(a)N:SetList(k)N:SetDisabled(j)N:SetCallback("\079\110\086\097\108\117\101\067\104\097\110\103\101\100",T)N:SetCallback("\079\110\067\108\111\115\101\100",z9)local z=d("\119\105\100\116\104",m,Y,u,c)if z=="\100\111\117\098\108\101"then N:SetWidth(C*2)elseif z=="\104\097\108\102"then N:SetWidth(C/2)elseif x(z)=="\110\117\109\098\101\114"then N:SetWidth(C*z)elseif z=="\102\117\108\108"then N.width="\102\105\108\108"else N:SetWidth(C)end for z=1,#n,1 do local k=n[z]local O=d("\103\101\116",m,Y,u,c,k)N:SetItemValue(k,O)end else N=z:Create("\073\110\108\105\110\101\071\114\111\117\112")N:SetLayout("\070\108\111\119")N:SetTitle(a)N.width="\102\105\108\108"N:PauseLayout()local P=d("\119\105\100\116\104",m,Y,u,c)for I=1,#n,1 do local M=n[I]local S=k[M]local X=z:Create("\067\104\101\099\107\066\111\120")X:SetLabel(S)X:SetUserData("\118\097\108\117\101",M)X:SetUserData("\116\101\120\116",S)X:SetDisabled(j)X:SetTriState(m.tristate)X:SetValue(d("\103\101\116",m,Y,u,c,M))X:SetCallback("\079\110\086\097\108\117\101\067\104\097\110\103\101\100",c9)I9(X,Y,m,u,O,c)N:AddChild(X)if P=="\100\111\117\098\108\101"then X:SetWidth(C*2)elseif P=="\104\097\108\102"then X:SetWidth(C/2)elseif x(P)=="\110\117\109\098\101\114"then X:SetWidth(C*P)elseif P=="\102\117\108\108"then X.width="\102\105\108\108"else X:SetWidth(C)end end N:ResumeLayout()N:DoLayout()end E(n)elseif m.type=="\099\111\108\111\114"then N=j9(m.dialogControl or m.control,"\067\111\108\111\114\080\105\099\107\101\114")N:SetLabel(a)N:SetHasAlpha(d("\104\097\115\065\108\112\104\097",m,Y,u,c))N:SetColor(d("\103\101\116",m,Y,u,c))N:SetCallback("\079\110\086\097\108\117\101\067\104\097\110\103\101\100",T)N:SetCallback("\079\110\086\097\108\117\101\067\111\110\102\105\114\109\101\100",T)elseif m.type=="\107\101\121\098\105\110\100\105\110\103"then N=j9(m.dialogControl or m.control,"\075\101\121\098\105\110\100\105\110\103")N:SetLabel(a)N:SetKey(d("\103\101\116",m,Y,u,c))N:SetCallback("\079\110\075\101\121\067\104\097\110\103\101\100",T)elseif m.type=="\104\101\097\100\101\114"then N=j9(m.dialogControl or m.control,"\072\101\097\100\105\110\103")N:SetText(a)N.width="\102\105\108\108"elseif m.type=="\100\101\115\099\114\105\112\116\105\111\110"then N=j9(m.dialogControl or m.control,"\076\097\098\101\108")N:SetText(a)local z=d("\102\111\110\116\083\105\122\101",m,Y,u,c)if z=="\109\101\100\105\117\109"then N:SetFontObject(GameFontHighlight)elseif z=="\108\097\114\103\101"then N:SetFontObject(GameFontHighlightLarge)else N:SetFontObject(GameFontHighlightSmall)end local k=d("\105\109\097\103\101\067\111\111\114\100\115",m,Y,u,c)local O,P,I=d("\105\109\097\103\101",m,Y,u,c)if x(O)=="\115\116\114\105\110\103"or x(O)=="\110\117\109\098\101\114"then if not P then P=d("\105\109\097\103\101\087\105\100\116\104",m,Y,u,c)end if not I then I=d("\105\109\097\103\101\072\101\105\103\104\116",m,Y,u,c)end if x(k)=="\116\097\098\108\101"then N:SetImage(O,w(k))else N:SetImage(O)end if x(P)~="\110\117\109\098\101\114"then P=32 end if x(I)~="\110\117\109\098\101\114"then I=32 end N:SetImageSize(P,I)end local j=d("\119\105\100\116\104",m,Y,u,c)N.width=not j and"\102\105\108\108"end if N then if N.width~="\102\105\108\108"then local z=d("\119\105\100\116\104",m,Y,u,c)if z=="\100\111\117\098\108\101"then N:SetWidth(C*2)elseif z=="\104\097\108\102"then N:SetWidth(C/2)elseif x(z)=="\110\117\109\098\101\114"then N:SetWidth(C*z)elseif z=="\102\117\108\108"then N.width="\102\105\108\108"else N:SetWidth(C)end end if N.SetDisabled then local z=O9(m,Y,u,c)N:SetDisabled(z)end I9(N,Y,m,u,O,c)k:AddChild(N)end end end j(u)end k:ResumeLayout()k:DoLayout()E(M)E(S)end local function S9(c,...)for z=1,y("\035",...),1 do P(c,y(z,...))end end local function X9(c,z,Y,k)local O=c:GetUserDataTable()if not O then return end local N=O.options local P=O.option local I=O.path local j=O.appName local n=u.tooltip local M=W()for c=1,#I,1 do M[c]=I[c]end S9(M,("\001"):split(Y))local S=N for c=1,#M,1 do if not S then return end S=i(S,M[c])end local X=d("\110\097\109\101",S,N,M,j)local F=d("\100\101\115\099",S,N,M,j)n:SetOwner(k,"\065\078\067\072\079\082\095\078\079\078\069")n:ClearAllPoints()if c.type=="\084\097\098\071\114\111\117\112"then n:SetPoint("\066\079\084\084\079\077",k,"\084\079\080")else n:SetPoint("\076\069\070\084",k,"\082\073\071\072\084")end n:SetText(X,1,.82,0,true)if x(F)=="\115\116\114\105\110\103"then n:AddLine(F,1,1,1,true)end n:Show()end local function F9(c,z,Y,k)u.tooltip:Hide()end local function m9(c,z,Y,k)if not k then return false end local O=W()local u=W()for c=1,#Y,1 do O[c]=Y[c]end S9(O,("\001"):split(k))local N=z for Y=1,#O,1 do local k=O[Y]u[Y]=k N=i(N,k)if not N or N.type~="\103\114\111\117\112"or k9(N,z,u,c)then E(O)E(u)return false end end E(O)E(u)return true end local function y9(c,z,Y)local k=c:GetUserDataTable()local O=k.options local N=k.option local P=k.path local I=k.rootframe local j=W()for c=1,#P,1 do j[c]=P[c]end S9(j,("\001"):split(Y))c:ReleaseChildren()u:FeedGroup(k.appName,O,c,I,j)E(j)end function u.FeedGroup(I,c,Y,k,O,N,P)local j=Y local n local M,S=Y.childGroups,"\110\111\110\101"for c=1,#N,1 do local z=N[c]j=i(j,z)n=n or V(z.dialogInline,z.guiInline,z.inline,false)S=M M=j.childGroups end if not S then S="\116\114\101\101"end local X for z,k in F(j.args)do if k.type=="\103\114\111\117\112"and(not V(k.dialogInline,k.guiInline,k.inline,false)and not k9(k,Y,N,c))then X=true end end if j.plugins then for z,k in F(j.plugins)do for z,k in F(k)do if k.type=="\103\114\111\117\112"and(not V(k.dialogInline,k.guiInline,k.inline,false)and not k9(k,Y,N,c))then X=true end end end end k:SetLayout("\102\108\111\119")local m if not(X and not n)or M~="\116\097\098"and(M~="\115\101\108\101\099\116"and(S=="\116\114\101\101"and not P))then if k.type~="\073\110\108\105\110\101\071\114\111\117\112"and k.type~="\083\105\109\112\108\101\071\114\111\117\112"then m=z:Create("\083\099\114\111\108\108\070\114\097\109\101")m:SetLayout("\102\108\111\119")m.width="\102\105\108\108"m.height="\102\105\108\108"k:SetLayout("\102\105\108\108")k:AddChild(m)k=m end end M9(c,Y,k,O,N,j,nil)if m then k:PerformLayout()local z=I:GetStatusTable(c,N)if not z.scroll then z.scroll={}end m:SetStatusTable(z.scroll)end if X and not n then local I=d("\110\097\109\101",j,Y,N,c)if M=="\116\097\098"then local P=z:Create("\084\097\098\071\114\111\117\112")I9(P,Y,j,N,O,c)P:SetCallback("\079\110\071\114\111\117\112\083\101\108\101\099\116\101\100",y9)P:SetCallback("\079\110\084\097\098\069\110\116\101\114",X9)P:SetCallback("\079\110\084\097\098\076\101\097\118\101",F9)local I=u:GetStatusTable(c,N)if not I.groups then I.groups={}end P:SetStatusTable(I.groups)P.width="\102\105\108\108"P.height="\102\105\108\108"local n=P9(j,Y,N,c)P:SetTabs(n)P:SetUserData("\116\097\098\108\105\115\116",n)for z=1,#n,1 do local k=n[z]if not k.disabled then P:SelectTab(m9(c,Y,N,I.groups.selected)and I.groups.selected or k.value)break end end k:AddChild(P)elseif M=="\115\101\108\101\099\116"then local P=z:Create("\068\114\111\112\100\111\119\110\071\114\111\117\112")P:SetTitle(I)I9(P,Y,j,N,O,c)P:SetCallback("\079\110\071\114\111\117\112\083\101\108\101\099\116\101\100",y9)local n=u:GetStatusTable(c,N)if not n.groups then n.groups={}end P:SetStatusTable(n.groups)local M,S=u9(j,Y,N,c)P:SetGroupList(M,S)P:SetUserData("\103\114\111\117\112\108\105\115\116",M)P:SetUserData("\111\114\100\101\114\108\105\115\116",S)local X=S[1]if X then P:SetGroup(m9(c,Y,N,n.groups.selected)and n.groups.selected or X)end P.width="\102\105\108\108"P.height="\102\105\108\108"k:AddChild(P)elseif S~="\116\114\101\101"or P then local P=z:Create("\084\114\101\101\071\114\111\117\112")I9(P,Y,j,N,O,c)P:EnableButtonTooltips(false)P.width="\102\105\108\108"P.height="\102\105\108\108"P:SetCallback("\079\110\071\114\111\117\112\083\101\108\101\099\116\101\100",y9)P:SetCallback("\079\110\066\117\116\116\111\110\069\110\116\101\114",X9)P:SetCallback("\079\110\066\117\116\116\111\110\076\101\097\118\101",F9)local I=u:GetStatusTable(c,N)if not I.groups then I.groups={}end local n=P9(j,Y,N,c,true)P:SetStatusTable(I.groups)P:SetTree(n)P:SetUserData("\116\114\101\101",n)for z=1,#n,1 do local k=n[z]if not k.disabled then P:SelectByValue(m9(c,Y,N,I.groups.selected)and I.groups.selected or k.value)break end end k:AddChild(P)end end end local x9 local function w9(c)for z in F(c.closing)do if u.OpenFrames[z]then u.OpenFrames[z]:Hide()end if u.BlizOptions and u.BlizOptions[z]then for c,z in F(u.BlizOptions[z])do if not z:IsVisible()then z:ReleaseChildren()end end end c.closing[z]=nil end if c.closeAll then for z,Y in F(u.OpenFrames)do if not c.closeAllOverride[z]then Y:Hide()end end c.closeAll=nil n(c.closeAllOverride)end for z in F(c.apps)do if u.OpenFrames[z]then local c=u.OpenFrames[z]:GetUserDataTable()u:Open(z,w(c.basepath or Q))end if u.BlizOptions and u.BlizOptions[z]then for c,z in F(u.BlizOptions[z])do local Y=z:GetUserDataTable()if z:IsVisible()then u:Open(z:GetUserData("\097\112\112\078\097\109\101"),z,w(Y.basepath or Q))end end end c.apps[z]=nil end c:SetScript("\079\110\085\112\100\097\116\101",nil)end if u.frame:GetScript("\079\110\085\112\100\097\116\101")then u.frame:SetScript("\079\110\085\112\100\097\116\101",w9)end function u.CloseAll(c)u.frame.closeAll=true u.frame:SetScript("\079\110\085\112\100\097\116\101",w9)if m(c.OpenFrames)then return true end end function u.Close(z,c)if z.OpenFrames[c]then u.frame.closing[c]=true u.frame:SetScript("\079\110\085\112\100\097\116\101",w9)return true end end function u.ConfigTableChanged(Y,c,z)u.frame.apps[z]=true u.frame:SetScript("\079\110\085\112\100\097\116\101",w9)end Y.RegisterCallback(u,"\067\111\110\102\105\103\084\097\098\108\101\067\104\097\110\103\101","\067\111\110\102\105\103\084\097\098\108\101\067\104\097\110\103\101\100")function u.SetDefaultSize(k,c,z,Y)local O=u:GetStatusTable(c)if x(z)=="\110\117\109\098\101\114"and x(Y)=="\110\117\109\098\101\114"then O.width=z O.height=Y end end function u.Open(N,c,O,...)if not x9 then x9=CloseSpecialWindows CloseSpecialWindows=function()local c=x9()return N:CloseAll()or c end end local I=Y:GetOptionsTable(c)if not I then X(("\037\115 \105\115\110\'\116 \114\101\103\105\115\116\101\100 \119\105\116\104 \065\099\101\067\111\110\102\105\103\082\101\103\105\115\116\114\121\044 \117\110\097\098\108\101 \116\111 \111\112\101\110 \099\111\110\102\105\103"):format(c),2)end local j=I("\100\105\097\108\111\103",k)local n local M=W()local F=d("\110\097\109\101",j,j,M,c)if x(O)=="\115\116\114\105\110\103"then P(M,O)O=nil end for c=1,y("\035",...),1 do P(M,y(c,...))end local m=j if x(O)=="\116\097\098\108\101"and(O.type=="\066\108\105\122\079\112\116\105\111\110\115\071\114\111\117\112"and#M>0)then for c=1,#M,1 do m=j.args[M[c]]end F=S("\037\115 - \037\115",F,d("\110\097\109\101",m,j,M,c))end if O then n=O n:ReleaseChildren()n:SetUserData("\097\112\112\078\097\109\101",c)n:SetUserData("\105\115\099\117\115\116\111\109",true)if#M>0 then n:SetUserData("\098\097\115\101\112\097\116\104",s(M))end local z=u:GetStatusTable(c)if not z.width then z.width=700 end if not z.height then z.height=500 end if n.SetStatusTable then n:SetStatusTable(z)end if n.SetTitle then n:SetTitle(F or"")end else if not N.OpenFrames[c]then n=z:Create("\070\114\097\109\101")N.OpenFrames[c]=n else n=N.OpenFrames[c]end n:ReleaseChildren()n:SetCallback("\079\110\067\108\111\115\101",Y9)n:SetUserData("\097\112\112\078\097\109\101",c)if#M>0 then n:SetUserData("\098\097\115\101\112\097\116\104",s(M))end n:SetTitle(F or"")local Y=u:GetStatusTable(c)n:SetStatusTable(Y)end N:FeedGroup(c,j,n,n,M,true)if n.Show then n:Show()end E(M)if u.frame.closeAll then u.frame.closeAllOverride[c]=true end end if N and(N<39 and u.BlizOptions)then local c=u.BlizOptions local z={}for c,Y in F(c)do local k=Y:GetUserData("\097\112\112\078\097\109\101")if not z[k]then z[k]={}end z[k][c]=Y end u.BlizOptions=z else u.BlizOptions=u.BlizOptions or{}end local function L9(c,z)local Y=c:GetUserData("\112\097\116\104")u:Open(c:GetUserData("\097\112\112\078\097\109\101"),c,w(Y or Q))end local function e9(c,z)local Y=c:GetUserData("\097\112\112\078\097\109\101")u.frame.closing[Y]=true u.frame:SetScript("\079\110\085\112\100\097\116\101",w9)end function u.AddToBlizOptions(O,c,Y,k,...)local N=u.BlizOptions local I=c for c=1,y("\035",...),1 do I=I..("\001"..y(c,...))end if not N[c]then N[c]={}end if not N[c][I]then local O=z:Create("\066\108\105\122\079\112\116\105\111\110\115\071\114\111\117\112")N[c][I]=O O:SetTitle(Y or c)O:SetUserData("\097\112\112\078\097\109\101",c)if y("\035",...)>0 then local c={}for z=1,y("\035",...),1 do P(c,y(z,...))end O:SetUserData("\112\097\116\104",c)end O:SetCallback("\079\110\083\104\111\119",L9)O:SetCallback("\079\110\072\105\100\101",e9)if Settings and Settings.RegisterCanvasLayoutCategory then local z=Y or c if k then local c=Settings.GetCategory(k)if not c then X(("\084\104\101 \112\097\114\101\110\116 \099\097\116\101\103\111\114\121 \'\037\115\' \119\097\115 \110\111\116 \102\111\117\110\100"):format(k),2)end local Y=Settings.RegisterCanvasLayoutSubcategory(c,O.frame,z)O:SetName(Y.ID,k)else local c=Settings.RegisterCanvasLayoutCategory(O.frame,z)c.ID=z O:SetName(z,k)Settings.RegisterAddOnCategory(c)end else O:SetName(Y or c,k)InterfaceOptions_AddCategory(O.frame)end return O.frame,O.frame.name else X(("\037\115 \104\097\115 \097\108\114\101\097\100\121 \098\101\101\110 \097\100\100\101\100 \116\111 \116\104\101 \066\108\105\122\122\097\114\100 \079\112\116\105\111\110\115 \087\105\110\100\111\119 \119\105\116\104 \116\104\101 \103\105\118\101\110 \112\097\116\104"):format(c),2)end end
--- AceConfigDialog-3.0 generates AceGUI-3.0 based windows based on option tables.
-- @class file
-- @name AceConfigDialog-3.0
-- @release $Id: AceConfigDialog-3.0.lua 1296 2022-11-04 18:50:10Z nevcairiel $

local LibStub = LibStub
local gui = LibStub("AceGUI-3.0")
local reg = LibStub("AceConfigRegistry-3.0")

local MAJOR, MINOR = "AceConfigDialog-3.0", 86
local AceConfigDialog, oldminor = LibStub:NewLibrary(MAJOR, MINOR)

if not AceConfigDialog then return end

AceConfigDialog.OpenFrames = AceConfigDialog.OpenFrames or {}
AceConfigDialog.Status = AceConfigDialog.Status or {}
AceConfigDialog.frame = AceConfigDialog.frame or CreateFrame("Frame")
AceConfigDialog.tooltip = AceConfigDialog.tooltip or CreateFrame("GameTooltip", "AceConfigDialogTooltip", UIParent, "GameTooltipTemplate")

AceConfigDialog.frame.apps = AceConfigDialog.frame.apps or {}
AceConfigDialog.frame.closing = AceConfigDialog.frame.closing or {}
AceConfigDialog.frame.closeAllOverride = AceConfigDialog.frame.closeAllOverride or {}

-- Lua APIs
local tinsert, tsort, tremove, wipe = table.insert, table.sort, table.remove, table.wipe
local strmatch, format = string.match, string.format
local error = error
local pairs, next, select, type, unpack, ipairs = pairs, next, select, type, unpack, ipairs
local tostring, tonumber = tostring, tonumber
local math_min, math_max, math_floor = math.min, math.max, math.floor

local emptyTbl = {}

--[[
	 xpcall safecall implementation
]]
local xpcall = xpcall

local function errorhandler(err)
	return geterrorhandler()(err)
end

local function safecall(func, ...)
	if func then
		return xpcall(func, errorhandler, ...)
	end
end

local width_multiplier = 170

--[[
Group Types
  Tree 	- All Descendant Groups will all become nodes on the tree, direct child options will appear above the tree
        - Descendant Groups with inline=true and thier children will not become nodes

  Tab	- Direct Child Groups will become tabs, direct child options will appear above the tab control
        - Grandchild groups will default to inline unless specified otherwise

  Select- Same as Tab but with entries in a dropdown rather than tabs


  Inline Groups
    - Will not become nodes of a select group, they will be effectivly part of thier parent group seperated by a border
    - If declared on a direct child of a root node of a select group, they will appear above the group container control
    - When a group is displayed inline, all descendants will also be inline members of the group

]]

-- Recycling functions
local new, del, copy
--newcount, delcount,createdcount,cached = 0,0,0
do
	local pool = setmetatable({},{__mode="k"})
	function new()
		--newcount = newcount + 1
		local t = next(pool)
		if t then
			pool[t] = nil
			return t
		else
			--createdcount = createdcount + 1
			return {}
		end
	end
	function copy(t)
		local c = new()
		for k, v in pairs(t) do
			c[k] = v
		end
		return c
	end
	function del(t)
		--delcount = delcount + 1
		wipe(t)
		pool[t] = true
	end
--	function cached()
--		local n = 0
--		for k in pairs(pool) do
--			n = n + 1
--		end
--		return n
--	end
end

-- picks the first non-nil value and returns it
local function pickfirstset(...)
  for i=1,select("#",...) do
    if select(i,...)~=nil then
      return select(i,...)
    end
  end
end

--gets an option from a given group, checking plugins
local function GetSubOption(group, key)
	if group.plugins then
		for plugin, t in pairs(group.plugins) do
			if t[key] then
				return t[key]
			end
		end
	end

	return group.args[key]
end

--Option member type definitions, used to decide how to access it

--Is the member Inherited from parent options
local isInherited = {
	set = true,
	get = true,
	func = true,
	confirm = true,
	validate = true,
	disabled = true,
	hidden = true
}

--Does a string type mean a literal value, instead of the default of a method of the handler
local stringIsLiteral = {
	name = true,
	desc = true,
	icon = true,
	usage = true,
	width = true,
	image = true,
	fontSize = true,
	tooltipHyperlink = true
}

--Is Never a function or method
local allIsLiteral = {
	type = true,
	descStyle = true,
	imageWidth = true,
	imageHeight = true,
}

--gets the value for a member that could be a function
--function refs are called with an info arg
--every other type is returned
local function GetOptionsMemberValue(membername, option, options, path, appName, ...)
	--get definition for the member
	local inherits = isInherited[membername]


	--get the member of the option, traversing the tree if it can be inherited
	local member

	if inherits then
		local group = options
		if group[membername] ~= nil then
			member = group[membername]
		end
		for i = 1, #path do
			group = GetSubOption(group, path[i])
			if group[membername] ~= nil then
				member = group[membername]
			end
		end
	else
		member = option[membername]
	end

	--check if we need to call a functon, or if we have a literal value
	if ( not allIsLiteral[membername] ) and ( type(member) == "function" or ((not stringIsLiteral[membername]) and type(member) == "string") ) then
		--We have a function to call
		local info = new()
		--traverse the options table, picking up the handler and filling the info with the path
		local group = options
		local handler = group.handler

		for i = 1, #path do
			group = GetSubOption(group, path[i])
			info[i] = path[i]
			handler = group.handler or handler
		end

		info.options = options
		info.appName = appName
		info[0] = appName
		info.arg = option.arg
		info.handler = handler
		info.option = option
		info.type = option.type
		info.uiType = "dialog"
		info.uiName = MAJOR

		local a, b, c ,d
		--using 4 returns for the get of a color type, increase if a type needs more
		if type(member) == "function" then
			--Call the function
			a,b,c,d = member(info, ...)
		else
			--Call the method
			if handler and handler[member] then
				a,b,c,d = handler[member](handler, info, ...)
			else
				error(format("Method %s doesn't exist in handler for type %s", member, membername))
			end
		end
		del(info)
		return a,b,c,d
	else
		--The value isnt a function to call, return it
		return member
	end
end

--[[calls an options function that could be inherited, method name or function ref
local function CallOptionsFunction(funcname ,option, options, path, appName, ...)
	local info = new()

	local func
	local group = options
	local handler

	--build the info table containing the path
	-- pick up functions while traversing the tree
	if group[funcname] ~= nil then
		func = group[funcname]
	end
	handler = group.handler or handler

	for i, v in ipairs(path) do
		group = GetSubOption(group, v)
		info[i] = v
		if group[funcname] ~= nil then
			func =  group[funcname]
		end
		handler = group.handler or handler
	end

	info.options = options
	info[0] = appName
	info.arg = option.arg

	local a, b, c ,d
	if type(func) == "string" then
		if handler and handler[func] then
			a,b,c,d = handler[func](handler, info, ...)
		else
			error(string.format("Method %s doesn't exist in handler for type func", func))
		end
	elseif type(func) == "function" then
		a,b,c,d = func(info, ...)
	end
	del(info)
	return a,b,c,d
end
--]]

--tables to hold orders and names for options being sorted, will be created with new()
--prevents needing to call functions repeatedly while sorting
local tempOrders
local tempNames

local function compareOptions(a,b)
	if not a then
		return true
	end
	if not b then
		return false
	end
	local OrderA, OrderB = tempOrders[a] or 100, tempOrders[b] or 100
	if OrderA == OrderB then
		local NameA = (type(tempNames[a]) == "string") and tempNames[a] or ""
		local NameB = (type(tempNames[b]) == "string") and tempNames[b] or ""
		return NameA:upper() < NameB:upper()
	end
	if OrderA < 0 then
		if OrderB >= 0 then
			return false
		end
	else
		if OrderB < 0 then
			return true
		end
	end
	return OrderA < OrderB
end



--builds 2 tables out of an options group
-- keySort, sorted keys
-- opts, combined options from .plugins and args
local function BuildSortedOptionsTable(group, keySort, opts, options, path, appName)
	tempOrders = new()
	tempNames = new()

	if group.plugins then
		for plugin, t in pairs(group.plugins) do
			for k, v in pairs(t) do
				if not opts[k] then
					tinsert(keySort, k)
					opts[k] = v

					path[#path+1] = k
					tempOrders[k] = GetOptionsMemberValue("order", v, options, path, appName)
					tempNames[k] = GetOptionsMemberValue("name", v, options, path, appName)
					path[#path] = nil
				end
			end
		end
	end

	for k, v in pairs(group.args) do
		if not opts[k] then
			tinsert(keySort, k)
			opts[k] = v

			path[#path+1] = k
			tempOrders[k] = GetOptionsMemberValue("order", v, options, path, appName)
			tempNames[k] = GetOptionsMemberValue("name", v, options, path, appName)
			path[#path] = nil
		end
	end

	tsort(keySort, compareOptions)

	del(tempOrders)
	del(tempNames)
end

local function DelTree(tree)
	if tree.children then
		local childs = tree.children
		for i = 1, #childs do
			DelTree(childs[i])
			del(childs[i])
		end
		del(childs)
	end
end

local function CleanUserData(widget, event)

	local user = widget:GetUserDataTable()

	if user.path then
		del(user.path)
	end

	if widget.type == "TreeGroup" then
		local tree = user.tree
		widget:SetTree(nil)
		if tree then
			for i = 1, #tree do
				DelTree(tree[i])
				del(tree[i])
			end
			del(tree)
		end
	end

	if widget.type == "TabGroup" then
		widget:SetTabs(nil)
		if user.tablist then
			del(user.tablist)
		end
	end

	if widget.type == "DropdownGroup" then
		widget:SetGroupList(nil)
		if user.grouplist then
			del(user.grouplist)
		end
		if user.orderlist then
			del(user.orderlist)
		end
	end
end

-- - Gets a status table for the given appname and options path.
-- @param appName The application name as given to `:RegisterOptionsTable()`
-- @param path The path to the options (a table with all group keys)
-- @return
function AceConfigDialog:GetStatusTable(appName, path)
	local status = self.Status

	if not status[appName] then
		status[appName] = {}
		status[appName].status = {}
		status[appName].children = {}
	end

	status = status[appName]

	if path then
		for i = 1, #path do
			local v = path[i]
			if not status.children[v] then
				status.children[v] = {}
				status.children[v].status = {}
				status.children[v].children = {}
			end
			status = status.children[v]
		end
	end

	return status.status
end

--- Selects the specified path in the options window.
-- The path specified has to match the keys of the groups in the table.
-- @param appName The application name as given to `:RegisterOptionsTable()`
-- @param ... The path to the key that should be selected
function AceConfigDialog:SelectGroup(appName, ...)
	local path = new()


	local app = reg:GetOptionsTable(appName)
	if not app then
		error(("%s isn't registed with AceConfigRegistry, unable to open config"):format(appName), 2)
	end
	local options = app("dialog", MAJOR)
	local group = options
	local status = self:GetStatusTable(appName, path)
	if not status.groups then
		status.groups = {}
	end
	status = status.groups
	local treevalue
	local treestatus

	for n = 1, select("#",...) do
		local key = select(n, ...)

		if group.childGroups == "tab" or group.childGroups == "select" then
			--if this is a tab or select group, select the group
			status.selected = key
			--children of this group are no longer extra levels of a tree
			treevalue = nil
		else
			--tree group by default
			if treevalue then
				--this is an extra level of a tree group, build a uniquevalue for it
				treevalue = treevalue.."\001"..key
			else
				--this is the top level of a tree group, the uniquevalue is the same as the key
				treevalue = key
				if not status.groups then
					status.groups = {}
				end
				--save this trees status table for any extra levels or groups
				treestatus = status
			end
			--make sure that the tree entry is open, and select it.
			--the selected group will be overwritten if a child is the final target but still needs to be open
			treestatus.selected = treevalue
			treestatus.groups[treevalue] = true

		end

		--move to the next group in the path
		group = GetSubOption(group, key)
		if not group then
			break
		end
		tinsert(path, key)
		status = self:GetStatusTable(appName, path)
		if not status.groups then
			status.groups = {}
		end
		status = status.groups
	end

	del(path)
	reg:NotifyChange(appName)
end

local function OptionOnMouseOver(widget, event)
	--show a tooltip/set the status bar to the desc text
	local user = widget:GetUserDataTable()
	local opt = user.option
	local options = user.options
	local path = user.path
	local appName = user.appName
	local tooltip = AceConfigDialog.tooltip

	tooltip:SetOwner(widget.frame, "ANCHOR_TOPRIGHT")

	local tooltipHyperlink = GetOptionsMemberValue("tooltipHyperlink", opt, options, path, appName)
	if tooltipHyperlink then
		tooltip:SetHyperlink(tooltipHyperlink)
		tooltip:Show()
		return
	end

	local name = GetOptionsMemberValue("name", opt, options, path, appName)
	local desc = GetOptionsMemberValue("desc", opt, options, path, appName)
	local usage = GetOptionsMemberValue("usage", opt, options, path, appName)
	local descStyle = opt.descStyle

	if descStyle and descStyle ~= "tooltip" then return end

	tooltip:SetText(name, 1, .82, 0, true)

	if opt.type == "multiselect" then
		tooltip:AddLine(user.text, 0.5, 0.5, 0.8, true)
	end
	if type(desc) == "string" then
		tooltip:AddLine(desc, 1, 1, 1, true)
	end
	if type(usage) == "string" then
		tooltip:AddLine("Usage: "..usage, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, true)
	end

	tooltip:Show()
end

local function OptionOnMouseLeave(widget, event)
	AceConfigDialog.tooltip:Hide()
end

local function GetFuncName(option)
	if option.type == "execute" then
		return "func"
	else
		return "set"
	end
end
do
	local frame = AceConfigDialog.popup
	if not frame or oldminor < 81 then
		frame = CreateFrame("Frame", nil, UIParent)
		AceConfigDialog.popup = frame
		frame:Hide()
		frame:SetPoint("CENTER", UIParent, "CENTER")
		frame:SetSize(320, 72)
		frame:EnableMouse(true) -- Do not allow click-through on the frame
		frame:SetFrameStrata("TOOLTIP")
		frame:SetFrameLevel(100) -- Lots of room to draw under it
		frame:SetScript("OnKeyDown", function(self, key)
			if key == "ESCAPE" then
				self:SetPropagateKeyboardInput(false)
				if self.cancel:IsShown() then
					self.cancel:Click()
				else -- Showing a validation error
					self:Hide()
				end
			else
				self:SetPropagateKeyboardInput(true)
			end
		end)

		local border = CreateFrame("Frame", nil, frame, "DialogBorderOpaqueTemplate")
		border:SetAllPoints(frame)
		frame:SetFixedFrameStrata(true)
		frame:SetFixedFrameLevel(true)

		local text = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
		text:SetSize(290, 0)
		text:SetPoint("TOP", 0, -16)
		frame.text = text

		local function newButton(newText)
			local button = CreateFrame("Button", nil, frame)
			button:SetSize(128, 21)
			button:SetNormalFontObject(GameFontNormal)
			button:SetHighlightFontObject(GameFontHighlight)
			button:SetNormalTexture(130763) -- "Interface\\Buttons\\UI-DialogBox-Button-Up"
			button:GetNormalTexture():SetTexCoord(0.0, 1.0, 0.0, 0.71875)
			button:SetPushedTexture(130761) -- "Interface\\Buttons\\UI-DialogBox-Button-Down"
			button:GetPushedTexture():SetTexCoord(0.0, 1.0, 0.0, 0.71875)
			button:SetHighlightTexture(130762) -- "Interface\\Buttons\\UI-DialogBox-Button-Highlight"
			button:GetHighlightTexture():SetTexCoord(0.0, 1.0, 0.0, 0.71875)
			button:SetText(newText)
			return button
		end

		local accept = newButton(ACCEPT)
		accept:SetPoint("BOTTOMRIGHT", frame, "BOTTOM", -6, 16)
		frame.accept = accept

		local cancel = newButton(CANCEL)
		cancel:SetPoint("LEFT", accept, "RIGHT", 13, 0)
		frame.cancel = cancel
	end
end
local function confirmPopup(appName, rootframe, basepath, info, message, func, ...)
	local frame = AceConfigDialog.popup
	frame:Show()
	frame.text:SetText(message)
	-- From StaticPopup.lua
	-- local height = 32 + text:GetHeight() + 2;
	-- height = height + 6 + accept:GetHeight()
	-- We add 32 + 2 + 6 + 21 (button height) == 61
	local height = 61 + frame.text:GetHeight()
	frame:SetHeight(height)

	frame.accept:ClearAllPoints()
	frame.accept:SetPoint("BOTTOMRIGHT", frame, "BOTTOM", -6, 16)
	frame.cancel:Show()

	local t = {...}
	local tCount = select("#", ...)
	frame.accept:SetScript("OnClick", function(self)
		safecall(func, unpack(t, 1, tCount)) -- Manually set count as unpack() stops on nil (bug with #table)
		AceConfigDialog:Open(appName, rootframe, unpack(basepath or emptyTbl))
		frame:Hide()
		self:SetScript("OnClick", nil)
		frame.cancel:SetScript("OnClick", nil)
		del(info)
	end)
	frame.cancel:SetScript("OnClick", function(self)
		AceConfigDialog:Open(appName, rootframe, unpack(basepath or emptyTbl))
		frame:Hide()
		self:SetScript("OnClick", nil)
		frame.accept:SetScript("OnClick", nil)
		del(info)
	end)
end

local function validationErrorPopup(message)
	local frame = AceConfigDialog.popup
	frame:Show()
	frame.text:SetText(message)
	-- From StaticPopup.lua
	-- local height = 32 + text:GetHeight() + 2;
	-- height = height + 6 + accept:GetHeight()
	-- We add 32 + 2 + 6 + 21 (button height) == 61
	local height = 61 + frame.text:GetHeight()
	frame:SetHeight(height)

	frame.accept:ClearAllPoints()
	frame.accept:SetPoint("BOTTOM", frame, "BOTTOM", 0, 16)
	frame.cancel:Hide()

	frame.accept:SetScript("OnClick", function()
		frame:Hide()
	end)
end

local function ActivateControl(widget, event, ...)
	--This function will call the set / execute handler for the widget
	--widget:GetUserDataTable() contains the needed info
	local user = widget:GetUserDataTable()
	local option = user.option
	local options = user.options
	local path = user.path
	local info = new()

	local func
	local group = options
	local funcname = GetFuncName(option)
	local handler
	local confirm
	local validate
	--build the info table containing the path
	-- pick up functions while traversing the tree
	if group[funcname] ~= nil then
		func =  group[funcname]
	end
	handler = group.handler
	confirm = group.confirm
	validate = group.validate
	for i = 1, #path do
		local v = path[i]
		group = GetSubOption(group, v)
		info[i] = v
		if group[funcname] ~= nil then
			func =  group[funcname]
		end
		handler = group.handler or handler
		if group.confirm ~= nil then
			confirm = group.confirm
		end
		if group.validate ~= nil then
			validate = group.validate
		end
	end

	info.options = options
	info.appName = user.appName
	info.arg = option.arg
	info.handler = handler
	info.option = option
	info.type = option.type
	info.uiType = "dialog"
	info.uiName = MAJOR

	local name
	if type(option.name) == "function" then
		name = option.name(info)
	elseif type(option.name) == "string" then
		name = option.name
	else
		name = ""
	end
	local usage = option.usage
	local pattern = option.pattern

	local validated = true

	if option.type == "input" then
		if type(pattern)=="string" then
			if not strmatch(..., pattern) then
				validated = false
			end
		end
	end

	local success
	if validated and option.type ~= "execute" then
		if type(validate) == "string" then
			if handler and handler[validate] then
				success, validated = safecall(handler[validate], handler, info, ...)
				if not success then validated = false end
			else
				error(format("Method %s doesn't exist in handler for type execute", validate))
			end
		elseif type(validate) == "function" then
			success, validated = safecall(validate, info, ...)
			if not success then validated = false end
		end
	end

	if not validated or type(validated) == "string" then
		if not validated then
			if usage then
				validated = name..": "..usage
			else
				if pattern then
					validated = name..": Expected "..pattern
				else
					validated = name..": Invalid Value"
				end
			end
		end

		-- show validate message
		if user.rootframe.SetStatusText then
			user.rootframe:SetStatusText(validated)
		else
			validationErrorPopup(validated)
		end
		PlaySound(882) -- SOUNDKIT.IG_PLAYER_INVITE_DECLINE || _DECLINE is actually missing from the table
		del(info)
		return true
	else

		local confirmText = option.confirmText
		--call confirm func/method
		if type(confirm) == "string" then
			if handler and handler[confirm] then
				success, confirm = safecall(handler[confirm], handler, info, ...)
				if success and type(confirm) == "string" then
					confirmText = confirm
					confirm = true
				elseif not success then
					confirm = false
				end
			else
				error(format("Method %s doesn't exist in handler for type confirm", confirm))
			end
		elseif type(confirm) == "function" then
			success, confirm = safecall(confirm, info, ...)
			if success and type(confirm) == "string" then
				confirmText = confirm
				confirm = true
			elseif not success then
				confirm = false
			end
		end

		--confirm if needed
		if type(confirm) == "boolean" then
			if confirm then
				if not confirmText then
					local option_name, desc = option.name, option.desc
					if type(option_name) == "function" then
						option_name = option_name(info)
					end
					if type(desc) == "function" then
						desc = desc(info)
					end
					confirmText = option_name
					if desc then
						confirmText = confirmText.." - "..desc
					end
				end

				local iscustom = user.rootframe:GetUserData("iscustom")
				local rootframe

				if iscustom then
					rootframe = user.rootframe
				end
				local basepath = user.rootframe:GetUserData("basepath")
				if type(func) == "string" then
					if handler and handler[func] then
						confirmPopup(user.appName, rootframe, basepath, info, confirmText, handler[func], handler, info, ...)
					else
						error(format("Method %s doesn't exist in handler for type func", func))
					end
				elseif type(func) == "function" then
					confirmPopup(user.appName, rootframe, basepath, info, confirmText, func, info, ...)
				end
				--func will be called and info deleted when the confirm dialog is responded to
				return
			end
		end

		--call the function
		if type(func) == "string" then
			if handler and handler[func] then
				safecall(handler[func],handler, info, ...)
			else
				error(format("Method %s doesn't exist in handler for type func", func))
			end
		elseif type(func) == "function" then
			safecall(func,info, ...)
		end



		local iscustom = user.rootframe:GetUserData("iscustom")
		local basepath = user.rootframe:GetUserData("basepath") or emptyTbl
		--full refresh of the frame, some controls dont cause this on all events
		if option.type == "color" then
			if event == "OnValueConfirmed" then

				if iscustom then
					AceConfigDialog:Open(user.appName, user.rootframe, unpack(basepath))
				else
					AceConfigDialog:Open(user.appName, unpack(basepath))
				end
			end
		elseif option.type == "range" then
			if event == "OnMouseUp" then
				if iscustom then
					AceConfigDialog:Open(user.appName, user.rootframe, unpack(basepath))
				else
					AceConfigDialog:Open(user.appName, unpack(basepath))
				end
			end
		--multiselects don't cause a refresh on 'OnValueChanged' only 'OnClosed'
		elseif option.type == "multiselect" then
			user.valuechanged = true
		else
			if iscustom then
				AceConfigDialog:Open(user.appName, user.rootframe, unpack(basepath))
			else
				AceConfigDialog:Open(user.appName, unpack(basepath))
			end
		end

	end
	del(info)
end

local function ActivateSlider(widget, event, value)
	local option = widget:GetUserData("option")
	local min, max, step = option.min or (not option.softMin and 0 or nil), option.max or (not option.softMax and 100 or nil), option.step
	if min then
		if step then
			value = math_floor((value - min) / step + 0.5) * step + min
		end
		value = math_max(value, min)
	end
	if max then
		value = math_min(value, max)
	end
	ActivateControl(widget,event,value)
end

--called from a checkbox that is part of an internally created multiselect group
--this type is safe to refresh on activation of one control
local function ActivateMultiControl(widget, event, ...)
	ActivateControl(widget, event, widget:GetUserData("value"), ...)
	local user = widget:GetUserDataTable()
	local iscustom = user.rootframe:GetUserData("iscustom")
	local basepath = user.rootframe:GetUserData("basepath") or emptyTbl
	if iscustom then
		AceConfigDialog:Open(user.appName, user.rootframe, unpack(basepath))
	else
		AceConfigDialog:Open(user.appName, unpack(basepath))
	end
end

local function MultiControlOnClosed(widget, event, ...)
	local user = widget:GetUserDataTable()
	if user.valuechanged and not widget:IsReleasing() then
		local iscustom = user.rootframe:GetUserData("iscustom")
		local basepath = user.rootframe:GetUserData("basepath") or emptyTbl
		if iscustom then
			AceConfigDialog:Open(user.appName, user.rootframe, unpack(basepath))
		else
			AceConfigDialog:Open(user.appName, unpack(basepath))
		end
	end
end

local function FrameOnClose(widget, event)
	local appName = widget:GetUserData("appName")
	AceConfigDialog.OpenFrames[appName] = nil
	gui:Release(widget)
end

local function CheckOptionHidden(option, options, path, appName)
	--check for a specific boolean option
	local hidden = pickfirstset(option.dialogHidden,option.guiHidden)
	if hidden ~= nil then
		return hidden
	end

	return GetOptionsMemberValue("hidden", option, options, path, appName)
end

local function CheckOptionDisabled(option, options, path, appName)
	--check for a specific boolean option
	local disabled = pickfirstset(option.dialogDisabled,option.guiDisabled)
	if disabled ~= nil then
		return disabled
	end

	return GetOptionsMemberValue("disabled", option, options, path, appName)
end
--[[
local function BuildTabs(group, options, path, appName)
	local tabs = new()
	local text = new()
	local keySort = new()
	local opts = new()

	BuildSortedOptionsTable(group, keySort, opts, options, path, appName)

	for i = 1, #keySort do
		local k = keySort[i]
		local v = opts[k]
		if v.type == "group" then
			path[#path+1] = k
			local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false)
			local hidden = CheckOptionHidden(v, options, path, appName)
			if not inline and not hidden then
				tinsert(tabs, k)
				text[k] = GetOptionsMemberValue("name", v, options, path, appName)
			end
			path[#path] = nil
		end
	end

	del(keySort)
	del(opts)

	return tabs, text
end
]]
local function BuildSelect(group, options, path, appName)
	local groups = new()
	local order = new()
	local keySort = new()
	local opts = new()

	BuildSortedOptionsTable(group, keySort, opts, options, path, appName)

	for i = 1, #keySort do
		local k = keySort[i]
		local v = opts[k]
		if v.type == "group" then
			path[#path+1] = k
			local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false)
			local hidden = CheckOptionHidden(v, options, path, appName)
			if not inline and not hidden then
				groups[k] = GetOptionsMemberValue("name", v, options, path, appName)
				tinsert(order, k)
			end
			path[#path] = nil
		end
	end

	del(opts)
	del(keySort)

	return groups, order
end

local function BuildSubGroups(group, tree, options, path, appName)
	local keySort = new()
	local opts = new()

	BuildSortedOptionsTable(group, keySort, opts, options, path, appName)

	for i = 1, #keySort do
		local k = keySort[i]
		local v = opts[k]
		if v.type == "group" then
			path[#path+1] = k
			local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false)
			local hidden = CheckOptionHidden(v, options, path, appName)
			if not inline and not hidden then
				local entry = new()
				entry.value = k
				entry.text = GetOptionsMemberValue("name", v, options, path, appName)
				entry.icon = GetOptionsMemberValue("icon", v, options, path, appName)
				entry.iconCoords = GetOptionsMemberValue("iconCoords", v, options, path, appName)
				entry.disabled = CheckOptionDisabled(v, options, path, appName)
				if not tree.children then tree.children = new() end
				tinsert(tree.children,entry)
				if (v.childGroups or "tree") == "tree" then
					BuildSubGroups(v,entry, options, path, appName)
				end
			end
			path[#path] = nil
		end
	end

	del(keySort)
	del(opts)
end

local function BuildGroups(group, options, path, appName, recurse)
	local tree = new()
	local keySort = new()
	local opts = new()

	BuildSortedOptionsTable(group, keySort, opts, options, path, appName)

	for i = 1, #keySort do
		local k = keySort[i]
		local v = opts[k]
		if v.type == "group" then
			path[#path+1] = k
			local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false)
			local hidden = CheckOptionHidden(v, options, path, appName)
			if not inline and not hidden then
				local entry = new()
				entry.value = k
				entry.text = GetOptionsMemberValue("name", v, options, path, appName)
				entry.icon = GetOptionsMemberValue("icon", v, options, path, appName)
				entry.iconCoords = GetOptionsMemberValue("iconCoords", v, options, path, appName)
				entry.disabled = CheckOptionDisabled(v, options, path, appName)
				tinsert(tree,entry)
				if recurse and (v.childGroups or "tree") == "tree" then
					BuildSubGroups(v,entry, options, path, appName)
				end
			end
			path[#path] = nil
		end
	end
	del(keySort)
	del(opts)
	return tree
end

local function InjectInfo(control, options, option, path, rootframe, appName)
	local user = control:GetUserDataTable()
	for i = 1, #path do
		user[i] = path[i]
	end
	user.rootframe = rootframe
	user.option = option
	user.options = options
	user.path = copy(path)
	user.appName = appName
	control:SetCallback("OnRelease", CleanUserData)
	control:SetCallback("OnLeave", OptionOnMouseLeave)
	control:SetCallback("OnEnter", OptionOnMouseOver)
end

local function CreateControl(userControlType, fallbackControlType)
	local control
	if userControlType then
		control = gui:Create(userControlType)
		if not control then
			geterrorhandler()(("Invalid Custom Control Type - %s"):format(tostring(userControlType)))
		end
	end
	if not control then
		control = gui:Create(fallbackControlType)
	end
	return control
end

local function sortTblAsStrings(x,y)
	return tostring(x) < tostring(y) -- Support numbers as keys
end

--[[
	options - root of the options table being fed
	container - widget that controls will be placed in
	rootframe - Frame object the options are in
	path - table with the keys to get to the group being fed
--]]

local function FeedOptions(appName, options,container,rootframe,path,group,inline)
	local keySort = new()
	local opts = new()

	BuildSortedOptionsTable(group, keySort, opts, options, path, appName)

	for i = 1, #keySort do
		local k = keySort[i]
		local v = opts[k]
		tinsert(path, k)
		local hidden = CheckOptionHidden(v, options, path, appName)
		local name = GetOptionsMemberValue("name", v, options, path, appName)
		if not hidden then
			if v.type == "group" then
				if inline or pickfirstset(v.dialogInline,v.guiInline,v.inline, false) then
					--Inline group
					local GroupContainer
					if name and name ~= "" then
						GroupContainer = gui:Create("InlineGroup")
						GroupContainer:SetTitle(name or "")
					else
						GroupContainer = gui:Create("SimpleGroup")
					end

					GroupContainer.width = "fill"
					GroupContainer:SetLayout("flow")
					container:AddChild(GroupContainer)
					FeedOptions(appName,options,GroupContainer,rootframe,path,v,true)
				end
			else
				--Control to feed
				local control

				if v.type == "execute" then

					local imageCoords = GetOptionsMemberValue("imageCoords",v, options, path, appName)
					local image, width, height = GetOptionsMemberValue("image",v, options, path, appName)

					local iconControl = type(image) == "string" or type(image) == "number"
					control = CreateControl(v.dialogControl or v.control, iconControl and "Icon" or "Button")
					if iconControl then
						if not width then
							width = GetOptionsMemberValue("imageWidth",v, options, path, appName)
						end
						if not height then
							height = GetOptionsMemberValue("imageHeight",v, options, path, appName)
						end
						if type(imageCoords) == "table" then
							control:SetImage(image, unpack(imageCoords))
						else
							control:SetImage(image)
						end
						if type(width) ~= "number" then
							width = 32
						end
						if type(height) ~= "number" then
							height = 32
						end
						control:SetImageSize(width, height)
						control:SetLabel(name)
					else
						control:SetText(name)
					end
					control:SetCallback("OnClick",ActivateControl)

				elseif v.type == "input" then
					control = CreateControl(v.dialogControl or v.control, v.multiline and "MultiLineEditBox" or "EditBox")

					if v.multiline and control.SetNumLines then
						control:SetNumLines(tonumber(v.multiline) or 4)
					end
					control:SetLabel(name)
					control:SetCallback("OnEnterPressed",ActivateControl)
					local text = GetOptionsMemberValue("get",v, options, path, appName)
					if type(text) ~= "string" then
						text = ""
					end
					control:SetText(text)

				elseif v.type == "toggle" then
					control = CreateControl(v.dialogControl or v.control, "CheckBox")
					control:SetLabel(name)
					control:SetTriState(v.tristate)
					local value = GetOptionsMemberValue("get",v, options, path, appName)
					control:SetValue(value)
					control:SetCallback("OnValueChanged",ActivateControl)

					if v.descStyle == "inline" then
						local desc = GetOptionsMemberValue("desc", v, options, path, appName)
						control:SetDescription(desc)
					end

					local image = GetOptionsMemberValue("image", v, options, path, appName)
					local imageCoords = GetOptionsMemberValue("imageCoords", v, options, path, appName)

					if type(image) == "string" or type(image) == "number" then
						if type(imageCoords) == "table" then
							control:SetImage(image, unpack(imageCoords))
						else
							control:SetImage(image)
						end
					end
				elseif v.type == "range" then
					control = CreateControl(v.dialogControl or v.control, "Slider")
					control:SetLabel(name)
					control:SetSliderValues(v.softMin or v.min or 0, v.softMax or v.max or 100, v.bigStep or v.step or 0)
					control:SetIsPercent(v.isPercent)
					local value = GetOptionsMemberValue("get",v, options, path, appName)
					if type(value) ~= "number" then
						value = 0
					end
					control:SetValue(value)
					control:SetCallback("OnValueChanged",ActivateSlider)
					control:SetCallback("OnMouseUp",ActivateSlider)

				elseif v.type == "select" then
					local values = GetOptionsMemberValue("values", v, options, path, appName)
					local sorting = GetOptionsMemberValue("sorting", v, options, path, appName)
					if v.style == "radio" then
						local disabled = CheckOptionDisabled(v, options, path, appName)
						local width = GetOptionsMemberValue("width",v,options,path,appName)
						control = gui:Create("InlineGroup")
						control:SetLayout("Flow")
						control:SetTitle(name)
						control.width = "fill"

						control:PauseLayout()
						local optionValue = GetOptionsMemberValue("get",v, options, path, appName)
						if not sorting then
							sorting = {}
							for value, text in pairs(values) do
								sorting[#sorting+1]=value
							end
							tsort(sorting, sortTblAsStrings)
						end
						for _, value in ipairs(sorting) do
							local text = values[value]
							local radio = gui:Create("CheckBox")
							radio:SetLabel(text)
							radio:SetUserData("value", value)
							radio:SetUserData("text", text)
							radio:SetDisabled(disabled)
							radio:SetType("radio")
							radio:SetValue(optionValue == value)
							radio:SetCallback("OnValueChanged", ActivateMultiControl)
							InjectInfo(radio, options, v, path, rootframe, appName)
							control:AddChild(radio)
							if width == "double" then
								radio:SetWidth(width_multiplier * 2)
							elseif width == "half" then
								radio:SetWidth(width_multiplier / 2)
							elseif (type(width) == "number") then
								radio:SetWidth(width_multiplier * width)
							elseif width == "full" then
								radio.width = "fill"
							else
								radio:SetWidth(width_multiplier)
							end
						end
						control:ResumeLayout()
						control:DoLayout()
					else
						control = CreateControl(v.dialogControl or v.control, "Dropdown")
						local itemType = v.itemControl
						if itemType and not gui:GetWidgetVersion(itemType) then
							geterrorhandler()(("Invalid Custom Item Type - %s"):format(tostring(itemType)))
							itemType = nil
						end
						control:SetLabel(name)
						control:SetList(values, sorting, itemType)
						local value = GetOptionsMemberValue("get",v, options, path, appName)
						if not values[value] then
							value = nil
						end
						control:SetValue(value)
						control:SetCallback("OnValueChanged", ActivateControl)
					end

				elseif v.type == "multiselect" then
					local values = GetOptionsMemberValue("values", v, options, path, appName)
					local disabled = CheckOptionDisabled(v, options, path, appName)

					local valuesort = new()
					if values then
						for value, text in pairs(values) do
							tinsert(valuesort, value)
						end
					end
					tsort(valuesort)

					local controlType = v.dialogControl or v.control
					if controlType then
						control = gui:Create(controlType)
						if not control then
							geterrorhandler()(("Invalid Custom Control Type - %s"):format(tostring(controlType)))
						end
					end
					if control then
						control:SetMultiselect(true)
						control:SetLabel(name)
						control:SetList(values)
						control:SetDisabled(disabled)
						control:SetCallback("OnValueChanged",ActivateControl)
						control:SetCallback("OnClosed", MultiControlOnClosed)
						local width = GetOptionsMemberValue("width",v,options,path,appName)
						if width == "double" then
							control:SetWidth(width_multiplier * 2)
						elseif width == "half" then
							control:SetWidth(width_multiplier / 2)
						elseif (type(width) == "number") then
							control:SetWidth(width_multiplier * width)
						elseif width == "full" then
							control.width = "fill"
						else
							control:SetWidth(width_multiplier)
						end
						--check:SetTriState(v.tristate)
						for s = 1, #valuesort do
							local key = valuesort[s]
							local value = GetOptionsMemberValue("get",v, options, path, appName, key)
							control:SetItemValue(key,value)
						end
					else
						control = gui:Create("InlineGroup")
						control:SetLayout("Flow")
						control:SetTitle(name)
						control.width = "fill"

						control:PauseLayout()
						local width = GetOptionsMemberValue("width",v,options,path,appName)
						for s = 1, #valuesort do
							local value = valuesort[s]
							local text = values[value]
							local check = gui:Create("CheckBox")
							check:SetLabel(text)
							check:SetUserData("value", value)
							check:SetUserData("text", text)
							check:SetDisabled(disabled)
							check:SetTriState(v.tristate)
							check:SetValue(GetOptionsMemberValue("get",v, options, path, appName, value))
							check:SetCallback("OnValueChanged",ActivateMultiControl)
							InjectInfo(check, options, v, path, rootframe, appName)
							control:AddChild(check)
							if width == "double" then
								check:SetWidth(width_multiplier * 2)
							elseif width == "half" then
								check:SetWidth(width_multiplier / 2)
							elseif (type(width) == "number") then
								check:SetWidth(width_multiplier * width)
							elseif width == "full" then
								check.width = "fill"
							else
								check:SetWidth(width_multiplier)
							end
						end
						control:ResumeLayout()
						control:DoLayout()


					end

					del(valuesort)

				elseif v.type == "color" then
					control = CreateControl(v.dialogControl or v.control, "ColorPicker")
					control:SetLabel(name)
					control:SetHasAlpha(GetOptionsMemberValue("hasAlpha",v, options, path, appName))
					control:SetColor(GetOptionsMemberValue("get",v, options, path, appName))
					control:SetCallback("OnValueChanged",ActivateControl)
					control:SetCallback("OnValueConfirmed",ActivateControl)

				elseif v.type == "keybinding" then
					control = CreateControl(v.dialogControl or v.control, "Keybinding")
					control:SetLabel(name)
					control:SetKey(GetOptionsMemberValue("get",v, options, path, appName))
					control:SetCallback("OnKeyChanged",ActivateControl)

				elseif v.type == "header" then
					control = CreateControl(v.dialogControl or v.control, "Heading")
					control:SetText(name)
					control.width = "fill"

				elseif v.type == "description" then
					control = CreateControl(v.dialogControl or v.control, "Label")
					control:SetText(name)

					local fontSize = GetOptionsMemberValue("fontSize",v, options, path, appName)
					if fontSize == "medium" then
						control:SetFontObject(GameFontHighlight)
					elseif fontSize == "large" then
						control:SetFontObject(GameFontHighlightLarge)
					else -- small or invalid
						control:SetFontObject(GameFontHighlightSmall)
					end

					local imageCoords = GetOptionsMemberValue("imageCoords",v, options, path, appName)
					local image, width, height = GetOptionsMemberValue("image",v, options, path, appName)

					if type(image) == "string" or type(image) == "number" then
						if not width then
							width = GetOptionsMemberValue("imageWidth",v, options, path, appName)
						end
						if not height then
							height = GetOptionsMemberValue("imageHeight",v, options, path, appName)
						end
						if type(imageCoords) == "table" then
							control:SetImage(image, unpack(imageCoords))
						else
							control:SetImage(image)
						end
						if type(width) ~= "number" then
							width = 32
						end
						if type(height) ~= "number" then
							height = 32
						end
						control:SetImageSize(width, height)
					end
					local controlWidth = GetOptionsMemberValue("width",v,options,path,appName)
					control.width = not controlWidth and "fill"
				end

				--Common Init
				if control then
					if control.width ~= "fill" then
						local width = GetOptionsMemberValue("width",v,options,path,appName)
						if width == "double" then
							control:SetWidth(width_multiplier * 2)
						elseif width == "half" then
							control:SetWidth(width_multiplier / 2)
						elseif (type(width) == "number") then
							control:SetWidth(width_multiplier * width)
						elseif width == "full" then
							control.width = "fill"
						else
							control:SetWidth(width_multiplier)
						end
					end
					if control.SetDisabled then
						local disabled = CheckOptionDisabled(v, options, path, appName)
						control:SetDisabled(disabled)
					end

					InjectInfo(control, options, v, path, rootframe, appName)
					container:AddChild(control)
				end

			end
		end
		tremove(path)
	end
	container:ResumeLayout()
	container:DoLayout()
	del(keySort)
	del(opts)
end

local function BuildPath(path, ...)
	for i = 1, select("#",...)  do
		tinsert(path, (select(i,...)))
	end
end


local function TreeOnButtonEnter(widget, event, uniquevalue, button)
	local user = widget:GetUserDataTable()
	if not user then return end
	local options = user.options
	local option = user.option
	local path = user.path
	local appName = user.appName
	local tooltip = AceConfigDialog.tooltip

	local feedpath = new()
	for i = 1, #path do
		feedpath[i] = path[i]
	end

	BuildPath(feedpath, ("\001"):split(uniquevalue))
	local group = options
	for i = 1, #feedpath do
		if not group then return end
		group = GetSubOption(group, feedpath[i])
	end

	local name = GetOptionsMemberValue("name", group, options, feedpath, appName)
	local desc = GetOptionsMemberValue("desc", group, options, feedpath, appName)

	tooltip:SetOwner(button, "ANCHOR_NONE")
	tooltip:ClearAllPoints()
	if widget.type == "TabGroup" then
		tooltip:SetPoint("BOTTOM",button,"TOP")
	else
		tooltip:SetPoint("LEFT",button,"RIGHT")
	end

	tooltip:SetText(name, 1, .82, 0, true)

	if type(desc) == "string" then
		tooltip:AddLine(desc, 1, 1, 1, true)
	end

	tooltip:Show()
end

local function TreeOnButtonLeave(widget, event, value, button)
	AceConfigDialog.tooltip:Hide()
end


local function GroupExists(appName, options, path, uniquevalue)
	if not uniquevalue then return false end

	local feedpath = new()
	local temppath = new()
	for i = 1, #path do
		feedpath[i] = path[i]
	end

	BuildPath(feedpath, ("\001"):split(uniquevalue))

	local group = options
	for i = 1, #feedpath do
		local v = feedpath[i]
		temppath[i] = v
		group = GetSubOption(group, v)

		if not group or group.type ~= "group" or CheckOptionHidden(group, options, temppath, appName) then
			del(feedpath)
			del(temppath)
			return false
		end
	end
	del(feedpath)
	del(temppath)
	return true
end

local function GroupSelected(widget, event, uniquevalue)

	local user = widget:GetUserDataTable()

	local options = user.options
	local option = user.option
	local path = user.path
	local rootframe = user.rootframe

	local feedpath = new()
	for i = 1, #path do
		feedpath[i] = path[i]
	end

	BuildPath(feedpath, ("\001"):split(uniquevalue))
	widget:ReleaseChildren()
	AceConfigDialog:FeedGroup(user.appName,options,widget,rootframe,feedpath)

	del(feedpath)
end



--[[
-- INTERNAL --
This function will feed one group, and any inline child groups into the given container
Select Groups will only have the selection control (tree, tabs, dropdown) fed in
and have a group selected, this event will trigger the feeding of child groups

Rules:
	If the group is Inline, FeedOptions
	If the group has no child groups, FeedOptions

	If the group is a tab or select group, FeedOptions then add the Group Control
	If the group is a tree group FeedOptions then
		its parent isnt a tree group:  then add the tree control containing this and all child tree groups
		if its parent is a tree group, its already a node on a tree
--]]

function AceConfigDialog:FeedGroup(appName,options,container,rootframe,path, isRoot)
	local group = options
	--follow the path to get to the curent group
	local inline
	local grouptype, parenttype = options.childGroups, "none"


	for i = 1, #path do
		local v = path[i]
		group = GetSubOption(group, v)
		inline = inline or pickfirstset(v.dialogInline,v.guiInline,v.inline, false)
		parenttype = grouptype
		grouptype = group.childGroups
	end

	if not parenttype then
		parenttype = "tree"
	end

	--check if the group has child groups
	local hasChildGroups
	for k, v in pairs(group.args) do
		if v.type == "group" and not pickfirstset(v.dialogInline,v.guiInline,v.inline, false) and not CheckOptionHidden(v, options, path, appName) then
			hasChildGroups = true
		end
	end
	if group.plugins then
		for plugin, t in pairs(group.plugins) do
			for k, v in pairs(t) do
				if v.type == "group" and not pickfirstset(v.dialogInline,v.guiInline,v.inline, false) and not CheckOptionHidden(v, options, path, appName) then
					hasChildGroups = true
				end
			end
		end
	end

	container:SetLayout("flow")
	local scroll

	--Add a scrollframe if we are not going to add a group control, this is the inverse of the conditions for that later on
	if (not (hasChildGroups and not inline)) or (grouptype ~= "tab" and grouptype ~= "select" and (parenttype == "tree" and not isRoot)) then
		if container.type ~= "InlineGroup" and container.type ~= "SimpleGroup" then
			scroll = gui:Create("ScrollFrame")
			scroll:SetLayout("flow")
			scroll.width = "fill"
			scroll.height = "fill"
			container:SetLayout("fill")
			container:AddChild(scroll)
			container = scroll
		end
	end

	FeedOptions(appName,options,container,rootframe,path,group,nil)

	if scroll then
		container:PerformLayout()
		local status = self:GetStatusTable(appName, path)
		if not status.scroll then
			status.scroll = {}
		end
		scroll:SetStatusTable(status.scroll)
	end

	if hasChildGroups and not inline then
		local name = GetOptionsMemberValue("name", group, options, path, appName)
		if grouptype == "tab" then

			local tab = gui:Create("TabGroup")
			InjectInfo(tab, options, group, path, rootframe, appName)
			tab:SetCallback("OnGroupSelected", GroupSelected)
			tab:SetCallback("OnTabEnter", TreeOnButtonEnter)
			tab:SetCallback("OnTabLeave", TreeOnButtonLeave)

			local status = AceConfigDialog:GetStatusTable(appName, path)
			if not status.groups then
				status.groups = {}
			end
			tab:SetStatusTable(status.groups)
			tab.width = "fill"
			tab.height = "fill"

			local tabs = BuildGroups(group, options, path, appName)
			tab:SetTabs(tabs)
			tab:SetUserData("tablist", tabs)

			for i = 1, #tabs do
				local entry = tabs[i]
				if not entry.disabled then
					tab:SelectTab((GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or entry.value)
					break
				end
			end

			container:AddChild(tab)

		elseif grouptype == "select" then

			local selectGroup = gui:Create("DropdownGroup")
			selectGroup:SetTitle(name)
			InjectInfo(selectGroup, options, group, path, rootframe, appName)
			selectGroup:SetCallback("OnGroupSelected", GroupSelected)
			local status = AceConfigDialog:GetStatusTable(appName, path)
			if not status.groups then
				status.groups = {}
			end
			selectGroup:SetStatusTable(status.groups)
			local grouplist, orderlist = BuildSelect(group, options, path, appName)
			selectGroup:SetGroupList(grouplist, orderlist)
			selectGroup:SetUserData("grouplist", grouplist)
			selectGroup:SetUserData("orderlist", orderlist)

			local firstgroup = orderlist[1]
			if firstgroup then
				selectGroup:SetGroup((GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or firstgroup)
			end

			selectGroup.width = "fill"
			selectGroup.height = "fill"

			container:AddChild(selectGroup)

		--assume tree group by default
		--if parenttype is tree then this group is already a node on that tree
		elseif (parenttype ~= "tree") or isRoot then
			local tree = gui:Create("TreeGroup")
			InjectInfo(tree, options, group, path, rootframe, appName)
			tree:EnableButtonTooltips(false)

			tree.width = "fill"
			tree.height = "fill"

			tree:SetCallback("OnGroupSelected", GroupSelected)
			tree:SetCallback("OnButtonEnter", TreeOnButtonEnter)
			tree:SetCallback("OnButtonLeave", TreeOnButtonLeave)

			local status = AceConfigDialog:GetStatusTable(appName, path)
			if not status.groups then
				status.groups = {}
			end
			local treedefinition = BuildGroups(group, options, path, appName, true)
			tree:SetStatusTable(status.groups)

			tree:SetTree(treedefinition)
			tree:SetUserData("tree",treedefinition)

			for i = 1, #treedefinition do
				local entry = treedefinition[i]
				if not entry.disabled then
					tree:SelectByValue((GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or entry.value)
					break
				end
			end

			container:AddChild(tree)
		end
	end
end

local old_CloseSpecialWindows


local function RefreshOnUpdate(this)
	for appName in pairs(this.closing) do
		if AceConfigDialog.OpenFrames[appName] then
			AceConfigDialog.OpenFrames[appName]:Hide()
		end
		if AceConfigDialog.BlizOptions and AceConfigDialog.BlizOptions[appName] then
			for key, widget in pairs(AceConfigDialog.BlizOptions[appName]) do
				if not widget:IsVisible() then
					widget:ReleaseChildren()
				end
			end
		end
		this.closing[appName] = nil
	end

	if this.closeAll then
		for k, v in pairs(AceConfigDialog.OpenFrames) do
			if not this.closeAllOverride[k] then
				v:Hide()
			end
		end
		this.closeAll = nil
		wipe(this.closeAllOverride)
	end

	for appName in pairs(this.apps) do
		if AceConfigDialog.OpenFrames[appName] then
			local user = AceConfigDialog.OpenFrames[appName]:GetUserDataTable()
			AceConfigDialog:Open(appName, unpack(user.basepath or emptyTbl))
		end
		if AceConfigDialog.BlizOptions and AceConfigDialog.BlizOptions[appName] then
			for key, widget in pairs(AceConfigDialog.BlizOptions[appName]) do
				local user = widget:GetUserDataTable()
				if widget:IsVisible() then
					AceConfigDialog:Open(widget:GetUserData("appName"), widget, unpack(user.basepath or emptyTbl))
				end
			end
		end
		this.apps[appName] = nil
	end
	this:SetScript("OnUpdate", nil)
end

-- Upgrade the OnUpdate script as well, if needed.
if AceConfigDialog.frame:GetScript("OnUpdate") then
	AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate)
end

--- Close all open options windows
function AceConfigDialog:CloseAll()
	AceConfigDialog.frame.closeAll = true
	AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate)
	if next(self.OpenFrames) then
		return true
	end
end

--- Close a specific options window.
-- @param appName The application name as given to `:RegisterOptionsTable()`
function AceConfigDialog:Close(appName)
	if self.OpenFrames[appName] then
		AceConfigDialog.frame.closing[appName] = true
		AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate)
		return true
	end
end

-- Internal -- Called by AceConfigRegistry
function AceConfigDialog:ConfigTableChanged(event, appName)
	AceConfigDialog.frame.apps[appName] = true
	AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate)
end

reg.RegisterCallback(AceConfigDialog, "ConfigTableChange", "ConfigTableChanged")

--- Sets the default size of the options window for a specific application.
-- @param appName The application name as given to `:RegisterOptionsTable()`
-- @param width The default width
-- @param height The default height
function AceConfigDialog:SetDefaultSize(appName, width, height)
	local status = AceConfigDialog:GetStatusTable(appName)
	if type(width) == "number" and type(height) == "number" then
		status.width = width
		status.height = height
	end
end

--- Open an option window at the specified path (if any).
-- This function can optionally feed the group into a pre-created container
-- instead of creating a new container frame.
-- @paramsig appName [, container][, ...]
-- @param appName The application name as given to `:RegisterOptionsTable()`
-- @param container An optional container frame to feed the options into
-- @param ... The path to open after creating the options window (see `:SelectGroup` for details)
function AceConfigDialog:Open(appName, container, ...)
	if not old_CloseSpecialWindows then
		old_CloseSpecialWindows = CloseSpecialWindows
		CloseSpecialWindows = function()
			local found = old_CloseSpecialWindows()
			return self:CloseAll() or found
		end
	end
	local app = reg:GetOptionsTable(appName)
	if not app then
		error(("%s isn't registed with AceConfigRegistry, unable to open config"):format(appName), 2)
	end
	local options = app("dialog", MAJOR)

	local f

	local path = new()
	local name = GetOptionsMemberValue("name", options, options, path, appName)

	--If an optional path is specified add it to the path table before feeding the options
	--as container is optional as well it may contain the first element of the path
	if type(container) == "string" then
		tinsert(path, container)
		container = nil
	end
	for n = 1, select("#",...) do
		tinsert(path, (select(n, ...)))
	end

	local option = options
	if type(container) == "table" and container.type == "BlizOptionsGroup" and #path > 0 then
		for i = 1, #path do
			option = options.args[path[i]]
		end
		name = format("%s - %s", name, GetOptionsMemberValue("name", option, options, path, appName))
	end

	--if a container is given feed into that
	if container then
		f = container
		f:ReleaseChildren()
		f:SetUserData("appName", appName)
		f:SetUserData("iscustom", true)
		if #path > 0 then
			f:SetUserData("basepath", copy(path))
		end
		local status = AceConfigDialog:GetStatusTable(appName)
		if not status.width then
			status.width =  700
		end
		if not status.height then
			status.height = 500
		end
		if f.SetStatusTable then
			f:SetStatusTable(status)
		end
		if f.SetTitle then
			f:SetTitle(name or "")
		end
	else
		if not self.OpenFrames[appName] then
			f = gui:Create("Frame")
			self.OpenFrames[appName] = f
		else
			f = self.OpenFrames[appName]
		end
		f:ReleaseChildren()
		f:SetCallback("OnClose", FrameOnClose)
		f:SetUserData("appName", appName)
		if #path > 0 then
			f:SetUserData("basepath", copy(path))
		end
		f:SetTitle(name or "")
		local status = AceConfigDialog:GetStatusTable(appName)
		f:SetStatusTable(status)
	end

	self:FeedGroup(appName,options,f,f,path,true)
	if f.Show then
		f:Show()
	end
	del(path)

	if AceConfigDialog.frame.closeAll then
		-- close all is set, but thats not good, since we're just opening here, so force it
		AceConfigDialog.frame.closeAllOverride[appName] = true
	end
end

-- convert pre-39 BlizOptions structure to the new format
if oldminor and oldminor < 39 and AceConfigDialog.BlizOptions then
	local old = AceConfigDialog.BlizOptions
	local newOpt = {}
	for key, widget in pairs(old) do
		local appName = widget:GetUserData("appName")
		if not newOpt[appName] then newOpt[appName] = {} end
		newOpt[appName][key] = widget
	end
	AceConfigDialog.BlizOptions = newOpt
else
	AceConfigDialog.BlizOptions = AceConfigDialog.BlizOptions or {}
end

local function FeedToBlizPanel(widget, event)
	local path = widget:GetUserData("path")
	AceConfigDialog:Open(widget:GetUserData("appName"), widget, unpack(path or emptyTbl))
end

local function ClearBlizPanel(widget, event)
	local appName = widget:GetUserData("appName")
	AceConfigDialog.frame.closing[appName] = true
	AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate)
end

--- Add an option table into the Blizzard Interface Options panel.
-- You can optionally supply a descriptive name to use and a parent frame to use,
-- as well as a path in the options table.\\
-- If no name is specified, the appName will be used instead.
--
-- If you specify a proper `parent` (by name), the interface options will generate a
-- tree layout. Note that only one level of children is supported, so the parent always
-- has to be a head-level note.
--
-- This function returns a reference to the container frame registered with the Interface
-- Options. You can use this reference to open the options with the API function
-- `InterfaceOptionsFrame_OpenToCategory`.
-- @param appName The application name as given to `:RegisterOptionsTable()`
-- @param name A descriptive name to display in the options tree (defaults to appName)
-- @param parent The parent to use in the interface options tree.
-- @param ... The path in the options table to feed into the interface options panel.
-- @return The reference to the frame registered into the Interface Options.
-- @return The category ID to pass to Settings.OpenToCategory (or InterfaceOptionsFrame_OpenToCategory)
function AceConfigDialog:AddToBlizOptions(appName, name, parent, ...)
	local BlizOptions = AceConfigDialog.BlizOptions

	local key = appName
	for n = 1, select("#", ...) do
		key = key.."\001"..select(n, ...)
	end

	if not BlizOptions[appName] then
		BlizOptions[appName] = {}
	end

	if not BlizOptions[appName][key] then
		local group = gui:Create("BlizOptionsGroup")
		BlizOptions[appName][key] = group

		group:SetTitle(name or appName)
		group:SetUserData("appName", appName)
		if select("#", ...) > 0 then
			local path = {}
			for n = 1, select("#",...) do
				tinsert(path, (select(n, ...)))
			end
			group:SetUserData("path", path)
		end
		group:SetCallback("OnShow", FeedToBlizPanel)
		group:SetCallback("OnHide", ClearBlizPanel)
		if Settings and Settings.RegisterCanvasLayoutCategory then
			local categoryName = name or appName
			if parent then
				local category = Settings.GetCategory(parent)
				if not category then
					error(("The parent category '%s' was not found"):format(parent), 2)
				end
				local subcategory = Settings.RegisterCanvasLayoutSubcategory(category, group.frame, categoryName)

				-- force the generated ID to be used for subcategories, as these can have very simple names like "Profiles"
				group:SetName(subcategory.ID, parent)
			else
				local category = Settings.RegisterCanvasLayoutCategory(group.frame, categoryName)
				-- using appName here would be cleaner, but would not be 100% compatible
				-- but for top-level categories it should be fine, as these are typically addon names
				category.ID = categoryName
				group:SetName(categoryName, parent)
				Settings.RegisterAddOnCategory(category)
			end
		else
			group:SetName(name or appName, parent)
			InterfaceOptions_AddCategory(group.frame)
		end
		return group.frame, group.frame.name
	else
		error(("%s has already been added to the Blizzard Options Window with the given path"):format(appName), 2)
	end
end
