Reset LastAddedControl to be table-lookup based.

Scott Yeskie [05-23-14 - 23:07]
Reset LastAddedControl to be table-lookup based.

Needed because pChat accesses the table directly.
Filename
lib/LibAddonMenu-1.0.lua
diff --git a/lib/LibAddonMenu-1.0.lua b/lib/LibAddonMenu-1.0.lua
index 57bf50b..d520d79 100644
--- a/lib/LibAddonMenu-1.0.lua
+++ b/lib/LibAddonMenu-1.0.lua
@@ -11,6 +11,7 @@ local optionsWindow = ZO_OptionsWindowSettingsScrollChild
 local openSubMenu
 lam.panels = {}
 lam.forceControlName = nil
+lam.lastAddedControl = {}


 lam.Panel = {}
@@ -41,7 +42,6 @@ function lam.Panel.new(panelID, panelName)
     local self = setmetatable({}, lam.Panel)
     self.panelName = panelName
     self.uniqCounter = 0
-    self.lastAddedControl = nil
     self.panelID = panelID
     lam.panels[panelID] = self
     return lam.panels[panelID]
@@ -63,10 +63,10 @@ end
 function lam.Panel:AddHeader(text)
     local isSubMenu = type(self.panelID) == "userdata"
     local controlName = self:getUniqueName()
-    --local header = wm:CreateControlFromVirtual(controlName, optionsWindow, self.lastAddedControl and "ZO_Options_SectionTitle_WithDivider" or "ZO_Options_SectionTitle")
-    local header = wm:CreateControlFromVirtual(controlName, isSubMenu and self.panelID or optionsWindow, self.lastAddedControl and "ZO_Options_SectionTitle_WithDivider" or "ZO_Options_SectionTitle")
-    if self.lastAddedControl then
-        header:SetAnchor(TOPLEFT, self.lastAddedControl, BOTTOMLEFT, 0, 15)
+    --local header = wm:CreateControlFromVirtual(controlName, optionsWindow, lam.lastAddedControl[self.panelID] and "ZO_Options_SectionTitle_WithDivider" or "ZO_Options_SectionTitle")
+    local header = wm:CreateControlFromVirtual(controlName, isSubMenu and self.panelID or optionsWindow, lam.lastAddedControl[self.panelID] and "ZO_Options_SectionTitle_WithDivider" or "ZO_Options_SectionTitle")
+    if lam.lastAddedControl[self.panelID] then
+        header:SetAnchor(TOPLEFT, lam.lastAddedControl[self.panelID], BOTTOMLEFT, 0, 15)
     else
         header:SetAnchor(TOPLEFT)
         if not isSubMenu then
@@ -91,7 +91,7 @@ function lam.Panel:AddHeader(text)
     ZO_OptionsWindow_InitializeControl(header)
     if isSubMenu then header:SetParent(self.panelID) end

-    self.lastAddedControl = header
+    lam.lastAddedControl[self.panelID] = header

     return header
 end
@@ -106,7 +106,7 @@ function lam.Panel:AddSlider(text, tooltip, minValue, maxValue, step, getFunc, s
     local controlName = self:getUniqueName()
     local isSubMenu = type(panelID) == "userdata"
     local slider = wm:CreateControlFromVirtual(controlName, isSubMenu and panelID or optionsWindow, "ZO_Options_Slider")
-    slider:SetAnchor(TOPLEFT, self.lastAddedControl, BOTTOMLEFT, 0, 6)
+    slider:SetAnchor(TOPLEFT, lam.lastAddedControl[self.panelID], BOTTOMLEFT, 0, 6)
     slider.controlType = OPTIONS_SLIDER
     slider.system = SETTING_TYPE_UI
     slider.panel = isSubMenu and panelID.panel or panelID
@@ -143,7 +143,7 @@ function lam.Panel:AddSlider(text, tooltip, minValue, maxValue, step, getFunc, s
     ZO_OptionsWindow_InitializeControl(slider)
     if isSubMenu then slider:SetParent(panelID) end

-    self.lastAddedControl = slider
+    lam.lastAddedControl[self.panelID] = slider

     return slider
 end
@@ -153,7 +153,7 @@ function lam.Panel:AddDropdown(text, tooltip, validChoices, getFunc, setFunc, wa
     local controlName = self:getUniqueName()
     local isSubMenu = type(panelID) == "userdata"
     local dropdown = wm:CreateControlFromVirtual(controlName, isSubMenu and panelID or optionsWindow, "ZO_Options_Dropdown")
-    dropdown:SetAnchor(TOPLEFT, self.lastAddedControl, BOTTOMLEFT, 0, 6)
+    dropdown:SetAnchor(TOPLEFT, lam.lastAddedControl[self.panelID], BOTTOMLEFT, 0, 6)
     dropdown.controlType = OPTIONS_DROPDOWN
     dropdown.system = SETTING_TYPE_UI
     dropdown.panel = isSubMenu and panelID.panel or panelID
@@ -183,7 +183,7 @@ function lam.Panel:AddDropdown(text, tooltip, validChoices, getFunc, setFunc, wa
     ZO_OptionsWindow_InitializeControl(dropdown)
     if isSubMenu then dropdown:SetParent(panelID) end

-    self.lastAddedControl = dropdown
+    lam.lastAddedControl[self.panelID] = dropdown

     return dropdown
 end
@@ -193,7 +193,7 @@ function lam.Panel:AddCheckbox(text, tooltip, getFunc, setFunc, warning, warning
     local controlName = self:getUniqueName()
     local isSubMenu = type(panelID) == "userdata"
     local checkbox = wm:CreateControlFromVirtual(controlName, isSubMenu and panelID or optionsWindow, "ZO_Options_Checkbox")
-    checkbox:SetAnchor(TOPLEFT, self.lastAddedControl, BOTTOMLEFT, 0, 6)
+    checkbox:SetAnchor(TOPLEFT, lam.lastAddedControl[self.panelID], BOTTOMLEFT, 0, 6)
     checkbox.controlType = OPTIONS_CHECKBOX
     checkbox.system = SETTING_TYPE_UI
     checkbox.settingId = _G[strformat("SETTING_%s", controlName)]
@@ -218,7 +218,7 @@ function lam.Panel:AddCheckbox(text, tooltip, getFunc, setFunc, warning, warning
     ZO_OptionsWindow_InitializeControl(checkbox)
     if isSubMenu then checkbox:SetParent(panelID) end

-    self.lastAddedControl = checkbox
+    lam.lastAddedControl[self.panelID] = checkbox

     return checkbox
 end
@@ -228,7 +228,7 @@ function lam.Panel:AddColorPicker(text, tooltip, getFunc, setFunc, warning, warn
     local controlName = self:getUniqueName()
     local isSubMenu = type(panelID) == "userdata"
     local colorpicker = wm:CreateTopLevelWindow(controlName)
-    colorpicker:SetAnchor(TOPLEFT, self.lastAddedControl, BOTTOMLEFT, 0, 10)
+    colorpicker:SetAnchor(TOPLEFT, lam.lastAddedControl[self.panelID], BOTTOMLEFT, 0, 10)
     colorpicker:SetParent(isSubMenu and panelID or optionsWindow)
     colorpicker:SetResizeToFitDescendents(true)
     colorpicker:SetWidth(510)
@@ -292,7 +292,7 @@ function lam.Panel:AddColorPicker(text, tooltip, getFunc, setFunc, warning, warn
     ZO_OptionsWindow_InitializeControl(colorpicker)
     if isSubMenu then colorpicker:SetParent(panelID) end

-    self.lastAddedControl = colorpicker
+    lam.lastAddedControl[self.panelID] = colorpicker

     return colorpicker
 end
@@ -302,7 +302,7 @@ function lam.Panel:AddEditBox(text, tooltip, isMultiLine, getFunc, setFunc, warn
     local controlName = self:getUniqueName()
     local isSubMenu = type(panelID) == "userdata"
     local editbox = wm:CreateTopLevelWindow(controlName)
-    editbox:SetAnchor(TOPLEFT, self.lastAddedControl, BOTTOMLEFT, 0, 10)
+    editbox:SetAnchor(TOPLEFT, lam.lastAddedControl[self.panelID], BOTTOMLEFT, 0, 10)
     editbox:SetResizeToFitDescendents(true)
     editbox:SetWidth(510)
     editbox:SetMouseEnabled(true)
@@ -339,7 +339,7 @@ function lam.Panel:AddEditBox(text, tooltip, isMultiLine, getFunc, setFunc, warn
     ZO_OptionsWindow_InitializeControl(editbox)
     editbox:SetParent(isSubMenu and panelID or optionsWindow)

-    self.lastAddedControl = editbox
+    lam.lastAddedControl[self.panelID] = editbox

     return editbox
 end
@@ -350,7 +350,7 @@ function lam.Panel:AddButton(text, tooltip, onClick, warning, warningText)
     local controlName = self:getUniqueName()
     local isSubMenu = type(panelID) == "userdata"
     local button = wm:CreateTopLevelWindow(controlName)
-    button:SetAnchor(TOPLEFT, self.lastAddedControl, BOTTOMLEFT, 0, 6)
+    button:SetAnchor(TOPLEFT, lam.lastAddedControl[self.panelID], BOTTOMLEFT, 0, 6)
     button:SetDimensions(510, 28)
     button:SetMouseEnabled(true)

@@ -377,7 +377,7 @@ function lam.Panel:AddButton(text, tooltip, onClick, warning, warningText)
     ZO_OptionsWindow_InitializeControl(button)
     button:SetParent(isSubMenu and panelID or optionsWindow)

-    self.lastAddedControl = button
+    lam.lastAddedControl[self.panelID] = button
     return button
 end

@@ -386,7 +386,7 @@ function lam.Panel:AddDescription(text, titleText)
     local controlName = self:getUniqueName()
     local isSubMenu = type(panelID) == "userdata"
     local textBox = wm:CreateTopLevelWindow(controlName)
-    textBox:SetAnchor(TOPLEFT, self.lastAddedControl, BOTTOMLEFT, 0, 10)
+    textBox:SetAnchor(TOPLEFT, lam.lastAddedControl[self.panelID], BOTTOMLEFT, 0, 10)
     textBox:SetResizeToFitDescendents(true)
     textBox:SetWidth(510)

@@ -417,7 +417,7 @@ function lam.Panel:AddDescription(text, titleText)
     ZO_OptionsWindow_InitializeControl(textBox)
     textBox:SetParent(isSubMenu and panelID or optionsWindow)

-    self.lastAddedControl = textBox
+    lam.lastAddedControl[self.panelID] = textBox

     return textBox
 end
@@ -447,7 +447,7 @@ function lam.Panel:AddSubMenu(text, tooltip)
     local controlName = self:getUniqueName()
     local menubtn = wm:CreateTopLevelWindow(controlName)
     menubtn:SetParent(optionsWindow)
-    menubtn:SetAnchor(TOPLEFT, self.lastAddedControl, BOTTOMLEFT, 0, 6)
+    menubtn:SetAnchor(TOPLEFT, lam.lastAddedControl[self.panelID], BOTTOMLEFT, 0, 6)
     menubtn:SetDimensions(510, 28)
     menubtn:SetMouseEnabled(true)

@@ -512,7 +512,7 @@ function lam.Panel:AddSubMenu(text, tooltip)

     ZO_OptionsWindow_InitializeControl(menubtn)

-    self.lastAddedControl = menubtn
+    lam.lastAddedControl[self.panelID] = menubtn

     lam:AddHeader(scroll, controlName.."MenuHeader", text)	--create the header for our menu