diff --git a/WeakAurasOptions/OptionsFrames/DebugLogFrame.lua b/WeakAurasOptions/OptionsFrames/DebugLogFrame.lua index 7ea2bdd..fbc6345 100644 --- a/WeakAurasOptions/OptionsFrames/DebugLogFrame.lua +++ b/WeakAurasOptions/OptionsFrames/DebugLogFrame.lua @@ -65,7 +65,7 @@ local function ConstructDebugLog(frame) return group end -function OptionsPrivate.DebugLog(frame) - debugLog = debugLog or ConstructDebugLog(frame) +function OptionsPrivate.DebugLog(frame, noConstruct) + debugLog = debugLog or (not noConstruct and ConstructDebugLog(frame)) return debugLog end diff --git a/WeakAurasOptions/OptionsFrames/IconPicker.lua b/WeakAurasOptions/OptionsFrames/IconPicker.lua index 982de59..7046d27 100644 --- a/WeakAurasOptions/OptionsFrames/IconPicker.lua +++ b/WeakAurasOptions/OptionsFrames/IconPicker.lua @@ -208,7 +208,7 @@ local function ConstructIconPicker(frame) return group end -function OptionsPrivate.IconPicker(frame) - iconPicker = iconPicker or ConstructIconPicker(frame) +function OptionsPrivate.IconPicker(frame, noConstruct) + iconPicker = iconPicker or (not noConstruct and ConstructIconPicker(frame)) return iconPicker end diff --git a/WeakAurasOptions/OptionsFrames/ImportExport.lua b/WeakAurasOptions/OptionsFrames/ImportExport.lua index 5d19960..5ba1329 100644 --- a/WeakAurasOptions/OptionsFrames/ImportExport.lua +++ b/WeakAurasOptions/OptionsFrames/ImportExport.lua @@ -35,11 +35,20 @@ local function ConstructImportExport(frame) function group.Open(self, mode, id) if(frame.window == "texture") then - frame.texturePicker:CancelClose(); + local texturepicker = OptionsPrivate.TexturePicker(frame, true) + if texturepicker then + texturepicker:CancelClose(); + end elseif(frame.window == "icon") then - frame.iconPicker:CancelClose(); + local iconpicker = OptionsPrivate.IconPicker(frame, true) + if iconpicker then + iconpicker:CancelClose(); + end elseif(frame.window == "model") then - frame.modelPicker:CancelClose(); + local modelpicker = OptionsPrivate.ModelPicker(frame, true) + if modelpicker then + modelpicker:CancelClose(); + end end frame.window = "importexport"; frame:UpdateFrameVisible() @@ -89,7 +98,7 @@ local function ConstructImportExport(frame) return group end -function OptionsPrivate.ImportExport(frame) - importexport = importexport or ConstructImportExport(frame) +function OptionsPrivate.ImportExport(frame, noConstruct) + importexport = importexport or (not noConstruct and ConstructImportExport(frame)) return importexport end diff --git a/WeakAurasOptions/OptionsFrames/ModelPicker.lua b/WeakAurasOptions/OptionsFrames/ModelPicker.lua index 43eeaec..e3ba6d1 100644 --- a/WeakAurasOptions/OptionsFrames/ModelPicker.lua +++ b/WeakAurasOptions/OptionsFrames/ModelPicker.lua @@ -368,7 +368,7 @@ local function ConstructModelPicker(frame) return group end -function OptionsPrivate.ModelPicker(frame) - modelPicker = modelPicker or ConstructModelPicker(frame) +function OptionsPrivate.ModelPicker(frame, noConstruct) + modelPicker = modelPicker or (not noConstruct and ConstructModelPicker(frame)) return modelPicker end diff --git a/WeakAurasOptions/OptionsFrames/OptionsFrame.lua b/WeakAurasOptions/OptionsFrames/OptionsFrame.lua index f9258aa..fc79cc9 100644 --- a/WeakAurasOptions/OptionsFrames/OptionsFrame.lua +++ b/WeakAurasOptions/OptionsFrames/OptionsFrame.lua @@ -241,48 +241,31 @@ function OptionsPrivate.CreateFrame() self.dynamicTextCodesFrame:Hide() self:HideTip() end + local widgets = { + { window = "texture", title = L["Texture Picker"], fn = "TexturePicker" }, + { window = "icon", title = L["Icon Picker"], fn = "IconPicker" }, + { window = "model", title = L["Model Picker"], fn = "ModelPicker" }, + { window = "importexport", title = L["Import / Export"], fn = "ImportExport" }, + { window = "texteditor", title = L["Code Editor"], fn = "TextEditor" }, + { window = "codereview", title = L["Custom Code Viewer"], fn = "CodeReview" }, + { window = "debuglog", title = L["Debug Log"], fn = "DebugLog" }, + { window = "update", title = L["Update"], fn = "UpdateFrame" }, + } - if self.window == "texture" then - OptionsPrivate.SetTitle(L["Texture Picker"]) - self.texturePicker.frame:Show() - else - self.texturePicker.frame:Hide() + for _, widget in ipairs(widgets) do + local obj = OptionsPrivate[widget.fn](self, true) + if self.window == widget.window then + OptionsPrivate.SetTitle(widget.title) + if obj then + obj.frame:Show() + end + else + if obj then + obj.frame:Hide() + end + end end - if self.window == "icon" then - OptionsPrivate.SetTitle(L["Icon Picker"]) - self.iconPicker.frame:Show() - else - self.iconPicker.frame:Hide() - end - - if self.window == "model" then - OptionsPrivate.SetTitle(L["Model Picker"]) - self.modelPicker.frame:Show() - else - self.modelPicker.frame:Hide() - end - - if self.window == "importexport" then - OptionsPrivate.SetTitle(L["Import / Export"]) - self.importexport.frame:Show() - else - self.importexport.frame:Hide() - end - - if self.window == "texteditor" then - OptionsPrivate.SetTitle(L["Code Editor"]) - self.texteditor.frame:Show() - else - self.texteditor.frame:Hide() - end - - if self.window == "codereview" then - OptionsPrivate.SetTitle(L["Custom Code Viewer"]) - self.codereview.frame:Show() - else - self.codereview.frame:Hide() - end if self.window == "newView" then OptionsPrivate.SetTitle(L["New Template"]) self.newView.frame:Show() @@ -291,18 +274,6 @@ function OptionsPrivate.CreateFrame() self.newView.frame:Hide() end end - if self.window == "update" then - OptionsPrivate.SetTitle(L["Update"]) - self.update.frame:Show() - else - self.update.frame:Hide() - end - if self.window == "debuglog" then - OptionsPrivate.SetTitle(L["Debug Log"]) - self.debugLog.frame:Show() - else - self.debugLog.frame:Hide() - end if self.window == "default" then if self.loadProgessVisible then self.loadProgress:Show() @@ -490,15 +461,6 @@ function OptionsPrivate.CreateFrame() container.content:SetPoint("BOTTOMRIGHT", 0, 0) frame.container = container - frame.texturePicker = OptionsPrivate.TexturePicker(frame) - frame.iconPicker = OptionsPrivate.IconPicker(frame) - frame.modelPicker = OptionsPrivate.ModelPicker(frame) - frame.importexport = OptionsPrivate.ImportExport(frame) - frame.texteditor = OptionsPrivate.TextEditor(frame) - frame.codereview = OptionsPrivate.CodeReview(frame) - frame.update = OptionsPrivate.UpdateFrame(frame) - frame.debugLog = OptionsPrivate.DebugLog(frame) - frame.moversizer, frame.mover = OptionsPrivate.MoverSizer(frame) -- filter line diff --git a/WeakAurasOptions/OptionsFrames/TextEditor.lua b/WeakAurasOptions/OptionsFrames/TextEditor.lua index 82e7bd7..09247bc 100644 --- a/WeakAurasOptions/OptionsFrames/TextEditor.lua +++ b/WeakAurasOptions/OptionsFrames/TextEditor.lua @@ -605,9 +605,15 @@ local function ConstructTextEditor(frame) helpButton:Hide() end if (frame.window == "texture") then - frame.texturePicker:CancelClose() + local texturepicker = OptionsPrivate.TexturePicker(frame, true) + if texturepicker then + texturepicker:CancelClose() + end elseif (frame.window == "icon") then - frame.iconPicker:CancelClose() + local iconpicker = OptionsPrivate.IconPicker(frame, true) + if iconpicker then + iconpicker:CancelClose() + end end frame.window = "texteditor" frame:UpdateFrameVisible() @@ -774,7 +780,7 @@ local function ConstructTextEditor(frame) return group end -function OptionsPrivate.TextEditor(frame) - textEditor = textEditor or ConstructTextEditor(frame) +function OptionsPrivate.TextEditor(frame, noConstruct) + textEditor = textEditor or (not noConstruct and ConstructTextEditor(frame)) return textEditor end diff --git a/WeakAurasOptions/OptionsFrames/TexturePicker.lua b/WeakAurasOptions/OptionsFrames/TexturePicker.lua index 7cd44b7..7e219d4 100644 --- a/WeakAurasOptions/OptionsFrames/TexturePicker.lua +++ b/WeakAurasOptions/OptionsFrames/TexturePicker.lua @@ -261,7 +261,7 @@ local function ConstructTexturePicker(frame) return group end -function OptionsPrivate.TexturePicker(frame) - texturePicker = texturePicker or ConstructTexturePicker(frame) +function OptionsPrivate.TexturePicker(frame, noConstruct) + texturePicker = texturePicker or (not noConstruct and ConstructTexturePicker(frame)) return texturePicker end