Quantcast

Added a profile system. The code is pretty sloppy, but it works for now.

Safturento [11-08-11 - 00:42]
Added a profile system. The code is pretty sloppy, but it works for now.
Filename
stAddonManager.lua
stAddonManager.toc
diff --git a/stAddonManager.lua b/stAddonManager.lua
index 46ea8d2..b45b6c1 100644
--- a/stAddonManager.lua
+++ b/stAddonManager.lua
@@ -1,3 +1,4 @@
+local addonName = select(1, ...)
 ------------------------------------------------------
 -- MEDIA & CONFIG ------------------------------------
 ------------------------------------------------------
@@ -7,7 +8,7 @@ local blankTex = [[Interface\AddOns\stAddonManager\media\blankTex.tga]]
 local glowTex = [[Interface\AddOns\stAddonManager\media\glowTex.tga]]

 local bordercolor = {0, 0, 0, 1}
-local backdropcolor = {0.05, 0.05, 0.05, 0.9}
+local backdropcolor = {0.05, 0.05, 0.05}
 local backdrop = {
 	bgFile = blankTex,
 	edgeFile =  blankTex,
@@ -28,35 +29,26 @@ stAddonManager:SetPoint("TOP", stAddonManager.header, "TOP", 0, 0)
 ------------------------------------------------------
 -- FUNCTIONS -----------------------------------------
 ------------------------------------------------------
-local function SkinFrame(frame, shadowed)
+local function SkinFrame(frame, transparent)
+	local bgR, bgG, bgB, bgA = unpack(backdropcolor)
+	if transparent then
+		if type(transparent) == "boolean" then
+			bgA = 0.9
+		else
+			bgA = transparent
+		end
+	end
 	frame:SetBackdrop(backdrop)
-	frame:SetBackdropColor(unpack(backdropcolor))
+	frame:SetBackdropColor(bgR, bgG, bgB, bgA)
 	frame:SetBackdropBorderColor(unpack(bordercolor))
-
-	if shadowed and not frame.shadow then
-		local shadow = CreateFrame("Frame", nil, frame)
-		shadow:SetFrameLevel(frame:GetFrameLevel())
-		shadow:SetFrameStrata(frame:GetFrameStrata())
-		shadow:SetPoint("TOPLEFT", -3, 3)
-		shadow:SetPoint("BOTTOMLEFT", -3, -3)
-		shadow:SetPoint("TOPRIGHT", 3, 3)
-		shadow:SetPoint("BOTTOMRIGHT", 3, -3)
-		shadow:SetBackdrop( {
-			edgeFile = glowTex, edgeSize = 3,
-			insets = {left = 5, right = 5, top = 5, bottom = 5},
-		})
-		shadow:SetBackdropColor(0, 0, 0, 0)
-		shadow:SetBackdropBorderColor(0, 0, 0, 0.8)
-		frame.shadow = shadow
-	end
 end

-local function CreateBackdrop(frame, shadowed)
+local function CreateBackdrop(frame, transparent)
 	if not frame.backdrop then
 		local backdrop = CreateFrame("Frame", nil, frame)
 		backdrop:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 1, 1)
 		backdrop:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", -1, -1)
-		SkinFrame(backdrop, shadowed)
+		SkinFrame(backdrop, transparent)
 		backdrop:SetFrameLevel(frame:GetFrameLevel()>0 and frame:GetFrameLevel()-1 or 0)
 		backdrop:SetFrameStrata(frame:GetFrameStrata())

@@ -99,7 +91,7 @@ local function SkinScrollBar(frame, thumbTrim)
 				frame.thumbbg = CreateFrame("Frame", nil, frame)
 				frame.thumbbg:SetPoint("TOPLEFT", frame:GetThumbTexture(), "TOPLEFT", 2, 14)
 				frame.thumbbg:SetPoint("BOTTOMRIGHT", frame:GetThumbTexture(), "BOTTOMRIGHT", -2, -14)
-				SkinFrame(frame.thumbbg)
+				SkinFrame(frame.thumbbg, true)
 				if frame.trackbg then
 					frame.thumbbg:SetFrameLevel(frame.trackbg:GetFrameLevel()+2)
 				end
@@ -124,97 +116,414 @@ function stAddonManager:UpdateAddonList(queryString)
 	return addons
 end

-local function LoadWindow()
-	if not stAddonManager.Loaded then
-		local window = stAddonManager
-		local header = window.header
+local function GetEnabledAddons()
+	local EnabledAddons = {}
+		for i=1, GetNumAddOns() do
+			local name, _, _, enabled = GetAddOnInfo(i)
+			if enabled then
+				tinsert(EnabledAddons, name)
+			end
+		end
+	return EnabledAddons
+end
+
+local function LoadProfileWindow()
+	local self = stAddonManager
+	if self.ProfileWindow then ToggleFrame(self.ProfileWindow) return end
+
+	local window = CreateFrame("Frame", "stAddonManager_ProfileWindow", self)
+	window:SetPoint("TOPLEFT", self, "TOPRIGHT", 5, 0)
+	window:SetSize(200, 300)
+	SkinFrame(window, true)

-		tinsert(UISpecialFrames,window:GetName());
+	local header = CreateFrame("Frame", "stAddonmanager_ProfileWindow_Header", window)
+	header:SetPoint("TOP", window, "TOP", 0, 0)
+	SkinFrame(header)
+	header:SetSize(window:GetWidth(), 20)
+
+	local hTitle = header:CreateFontString(nil, "OVERLAY")
+	hTitle:SetFont(unpack(font))
+	hTitle:SetPoint("CENTER")
+	hTitle:SetText("Profiles")
+	header.title = hTitle
+	window.header = header
+
+	--Create scroll frame (God damn these things are a pain)
+	local scrollBG = CreateFrame("Frame", window:GetName().."_ScrollBackground", window)
+	scrollBG:SetPoint("TOPLEFT", header, "BOTTOMLEFT", 5, -55)
+	scrollBG:SetWidth(window:GetWidth()-10)
+	scrollBG:SetHeight(window:GetHeight()-80)
+	SkinFrame(scrollBG)
+
+	local scrollFrame = CreateFrame("ScrollFrame", window:GetName().."_ScrollFrame", window, "UIPanelScrollFrameTemplate")
+	scrollFrame:SetPoint("TOPLEFT", scrollBG, "TOPLEFT", 0, -2)
+	scrollFrame:SetWidth(scrollBG:GetWidth()-25)
+	scrollFrame:SetHeight(scrollBG:GetHeight()-5)
+	SkinScrollBar(_G[window:GetName().."_ScrollFrameScrollBar"])
+	scrollFrame:SetFrameLevel(window:GetFrameLevel()+1)
+
+	scrollFrame.Anchor = CreateFrame("Frame", window:GetName().."_ScrollAnchor", scrollFrame)
+	scrollFrame.Anchor:SetPoint("TOPLEFT", scrollFrame, "TOPLEFT", 0, -3)
+	scrollFrame.Anchor:SetWidth(window:GetWidth()-40)
+	scrollFrame.Anchor:SetHeight(scrollFrame:GetHeight()-4)
+	scrollFrame.Anchor:SetFrameLevel(scrollFrame:GetFrameLevel()+1)
+	scrollFrame:SetScrollChild(scrollFrame.Anchor)
+
+	local EnableAll = CreateFrame("Button", window:GetName().."_EnableAllButton", window)
+	SkinFrame(EnableAll)
+	EnableAll:SetSize((window:GetWidth()-15)/2, 20)
+	EnableAll:SetPoint("TOPLEFT", header, "BOTTOMLEFT", 5, -5)
+	EnableAll.text = EnableAll:CreateFontString(nil, "OVERLAY")
+	EnableAll.text:SetFont(unpack(font))
+	EnableAll.text:SetText("Enable All")
+	EnableAll.text:SetPoint("CENTER")
+	EnableAll:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
+	EnableAll:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
+	EnableAll:SetScript("OnClick", function(self)
+		for i, addon in pairs(stAddonManager.AllAddons) do
+			EnableAddOn(addon.name)
+			stAddonManager.Buttons[i]:SetBackdropColor(0/255, 170/255, 255/255)
+			addon.enabled = true
+		end
+	end)
+
+	local DisableAll = CreateFrame("Button", window:GetName().."_DisableAllButton", window)
+	SkinFrame(DisableAll)
+	DisableAll:SetSize(EnableAll:GetSize())
+	DisableAll:SetPoint("TOPRIGHT", header, "BOTTOMRIGHT", -5, -5)
+	DisableAll.text = DisableAll:CreateFontString(nil, "OVERLAY")
+	DisableAll.text:SetFont(unpack(font))
+	DisableAll.text:SetText("Disable All")
+	DisableAll.text:SetPoint("CENTER")
+	DisableAll:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
+	DisableAll:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
+	DisableAll:SetScript("OnClick", function(self)
+		for i, addon in pairs(stAddonManager.AllAddons) do
+			if addon.name ~= addonName then
+				DisableAddOn(addon.name)
+				stAddonManager.Buttons[i]:SetBackdropColor(unpack(backdropcolor))
+				addon.enabled = false
+			end
+		end
+	end)
+
+	if not stAddonProfiles then
+		stAddonProfiles = {}
+	end
+
+	local SaveProfile = CreateFrame("Button", window:GetName().."_SaveProfileButton", window)
+	SkinFrame(SaveProfile)
+	SaveProfile:SetHeight(20)
+	SaveProfile:SetPoint("TOPLEFT", EnableAll, "BOTTOMLEFT", 0, -5)
+	SaveProfile:SetPoint("TOPRIGHT", DisableAll, "BOTTOMRIGHT", 0, -5)
+	SaveProfile.text = SaveProfile:CreateFontString(nil, "OVERLAY")
+	SaveProfile.text:SetFont(unpack(font))
+	SaveProfile.text:SetText("New Profile")
+	SaveProfile.text:SetPoint("CENTER")
+	SaveProfile:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
+	SaveProfile:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
+	SaveProfile:SetScript("OnClick", function(self)
+		if not self.editbox then
+			local ebox = CreateFrame("EditBox", nil, self)
+			SkinFrame(ebox)
+			ebox:SetAllPoints(self)
+			ebox:SetFont(unpack(font))
+			ebox:SetText("Profile Name")
+			ebox:SetAutoFocus(false)
+			ebox:SetFocus(true)
+			ebox:HighlightText()
+			ebox:SetTextInsets(3, 0, 0, 0)
+			ebox:SetScript("OnEditFocusGained", function(self) self:HighlightText() end)
+			ebox:SetScript("OnEscapePressed", function(self) self:SetText("Profile Name") self:ClearFocus() self:Hide() end)
+			ebox:SetScript("OnEnterPressed", function(self)
+				local profileName = self:GetText()
+				self:ClearFocus()
+				self:SetText("Profile Name")
+				self:Hide()
+				if not profileName then return end
+				stAddonProfiles[profileName] = GetEnabledAddons()
+				stAddonManager:UpdateProfileList()
+			end)
+
+			self.editbox = ebox
+		else
+			self.editbox:Show()
+			self.editbox:SetFocus(true)
+			self.editbox:HighlightText()
+		end
+	end)
+	self.SaveProfile = SaveProfile
+
+	self:SetScript("OnHide", function(self)
+		if self.SaveProfile.editbox then self.SaveProfile.editbox:Hide() end
+		window:Hide()
+		self.profileButton.text:SetText(">")
+	end)
+
+	local function CreateMenuButton(parent, width, height, text, ...)
+		local button = CreateFrame("Button", nil, parent)
+		button:SetFrameLevel(parent:GetFrameLevel()+1)
+		button:SetSize(width, height)
+		SkinFrame(button)
+		if ... then button:SetPoint(...) end

-		window:SetSize(300,300)
-		header:SetSize(300,20)
+		button.text = button:CreateFontString(nil, "OVERLAY")
+		button.text:SetFont(unpack(font))
+		button.text:SetPoint("CENTER")
+		if text then button.text:SetText(text) end

-		SkinFrame(window)
-		SkinFrame(header)
+		button:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
+		button:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)

-		header:EnableMouse(true)
-		header:SetMovable(true)
-		header:SetScript("OnMouseDown", function(self) self:StartMoving() end)
-		header:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
+		return button
+	end
+
+	local buttons = {}
+	function stAddonManager:UpdateProfileList()
+		local i = 1

-		local hTitle = stAddonManager.header:CreateFontString(nil, "OVERLAY")
-		hTitle:SetFont(unpack(font))
-		hTitle:SetPoint("CENTER")
-		hTitle:SetText("|cff00aaffst|rAddonManager")
-		header.title = hTitle
+		local sort = function(t, func)
+			local temp = {}
+			local i = 0

-		local close = CreateFrame("Button", nil, header)
-		close:SetPoint("RIGHT", header, "RIGHT", 0, 0)
-		close:SetFrameLevel(header:GetFrameLevel()+2)
-		close:SetSize(20, 20)
-		close.text = close:CreateFontString(nil, "OVERLAY")
-		close.text:SetFont(unpack(font))
-		close.text:SetText("x")
-		close.text:SetPoint("CENTER", close, "CENTER", 0, 0)
-		close:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
-		close:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
-		close:SetScript("OnClick", function() window:Hide() end)
-		header.close = close
-
-		addonListBG = CreateFrame("Frame", window:GetName().."_ScrollBackground", window)
-		addonListBG:SetPoint("TOPLEFT", header, "TOPLEFT", 10, -50)
-		addonListBG:SetWidth(window:GetWidth()-20)
-		addonListBG:SetHeight(window:GetHeight()-60)
-		SkinFrame(addonListBG)
+			for n in pairs(t) do
+				table.insert(temp, n)
+			end
+
+			table.sort(temp, func)
+
+			local iter = function()
+				i = i + 1
+				if temp[i] == nil then
+					return nil
+				else
+					return temp[i], t[temp[i]]
+				end
+			end
+
+			return iter
+		end

-		--Create scroll frame (God damn these things are a pain)
-		local scrollFrame = CreateFrame("ScrollFrame", window:GetName().."_ScrollFrame", window, "UIPanelScrollFrameTemplate")
-		scrollFrame:SetPoint("TOPLEFT", addonListBG, "TOPLEFT", 0, -2)
-		scrollFrame:SetWidth(addonListBG:GetWidth()-25)
-		scrollFrame:SetHeight(addonListBG:GetHeight()-5)
-		SkinScrollBar(_G[window:GetName().."_ScrollFrameScrollBar"])
-		scrollFrame:SetFrameLevel(window:GetFrameLevel()+1)
+		for i=1, #buttons do
+			buttons[i]:Hide()
+			buttons[i].overlay:Hide()
+			buttons[i]:SetHeight(20)
+		end
+
+		for profileName, addonList in sort(stAddonProfiles, function(a, b) return strlower(b) > strlower(a) end) do
+			if not buttons[i] then
+				local button = CreateMenuButton(scrollFrame.Anchor, scrollFrame:GetWidth()-4, 20, "<Profile Name>")
+				button.text:ClearAllPoints()
+				button.text:SetPoint("CENTER", button, "TOP", 0, -10)
+
+				local overlay = CreateFrame("Frame", nil, button)
+				overlay:EnableMouse(true) --just to stop the mouseover highlight when your mouse goes between the buttons
+				overlay:SetPoint("BOTTOM", button, "BOTTOM", 0, 3)
+				overlay:SetPoint("TOP", button, "TOP", 0, -20)
+				overlay:SetWidth(button:GetWidth()-10)
+				overlay:SetFrameLevel(button:GetFrameLevel()+1)
+				overlay:Hide()
+
+				overlay.set = CreateMenuButton(overlay, overlay:GetWidth(), 18, "Set to..", "TOP", overlay, "TOP", 0, 0)
+				overlay.add = CreateMenuButton(overlay, overlay:GetWidth(), 18, "Add to..", "TOP", overlay.set, "BOTTOM", 0, -3)
+				overlay.remove = CreateMenuButton(overlay, overlay:GetWidth(), 18, "Remove from..", "TOP", overlay.add, "BOTTOM", 0, -3)
+				overlay.delete = CreateMenuButton(overlay, overlay:GetWidth(), 18, "Delete Profile", "TOP", overlay.remove, "BOTTOM", 0, -3)
+
+				button.overlay = overlay
+
+				button:SetScript("OnClick", function(self)
+					if self.overlay:IsShown() then
+						for i=1, #buttons do
+							buttons[i].overlay:Hide()
+							buttons[i]:SetHeight(20)
+						end
+					else
+						for i=1, #buttons do
+							buttons[i].overlay:Hide()
+							buttons[i]:SetHeight(20)
+						end
+
+						self.overlay:Show()
+						self:SetHeight(25+(18*4)+(3*3))
+					end
+				end)
+
+				buttons[i] = button
+			end
+
+			buttons[i]:Show()
+			buttons[i].text:SetText(profileName)
+			local overlay = buttons[i].overlay
+			overlay.set:SetScript("OnClick", function(self)
+				DisableAllAddOns()
+				for i, name in pairs(addonList) do EnableAddOn(name) end
+				stAddonManager.AllAddons = stAddonManager:UpdateAddonList()
+				stAddonManager:UpdateList(stAddonManager.AllAddons)
+			end)
+			overlay.add:SetScript("OnClick", function(self)
+				for i, name in pairs(addonList) do EnableAddOn(name) end
+				stAddonManager.AllAddons = stAddonManager:UpdateAddonList()
+				stAddonManager:UpdateList(stAddonManager.AllAddons)
+			end)
+			overlay.remove:SetScript("OnClick", function(self)
+				for i, name in pairs(addonList) do if name ~= addonName then DisableAddOn(name) end end
+				stAddonManager.AllAddons = stAddonManager:UpdateAddonList()
+				stAddonManager:UpdateList(stAddonManager.AllAddons)
+			end)
+			overlay.delete:SetScript("OnClick", function(self)
+				if IsShiftKeyDown() then
+					stAddonProfiles[profileName] = nil
+					stAddonManager:UpdateProfileList()
+				else
+					print("|cff00aaffst|rAddonManager: Are you sure you want to delete this profile? Hold down shift and click again if you are.")
+				end
+			end)
+
+			i = i + 1
+		end

-		scrollFrame.Anchor = CreateFrame("Frame", window:GetName().."_ScrollAnchor", scrollFrame)
-		scrollFrame.Anchor:SetPoint("TOPLEFT", scrollFrame, "TOPLEFT", 0, -3)
-		scrollFrame.Anchor:SetWidth(window:GetWidth()-40)
-		scrollFrame.Anchor:SetHeight(scrollFrame:GetHeight())
-		scrollFrame.Anchor:SetFrameLevel(scrollFrame:GetFrameLevel()+1)
-		scrollFrame:SetScrollChild(scrollFrame.Anchor)
+		local prevButton
+		for i,button in pairs(buttons) do
+			if i == 1 then
+				button:SetPoint("TOPLEFT", scrollFrame.Anchor, "TOPLEFT", 4, -2)
+			else
+				button:SetPoint("TOP", prevButton, "BOTTOM", 0, -3)
+			end
+			prevButton = button
+		end
+	end
+	stAddonManager:UpdateProfileList()
+
+	self.ProfileWindow = window
+end
+
+local function LoadWindow()
+	if stAddonManager.Loaded then stAddonManager:Show(); return  end
+	local window = stAddonManager
+	local header = window.header
+
+	tinsert(UISpecialFrames,window:GetName());
+
+	window:SetSize(300,300)
+	header:SetSize(300,20)
+
+	SkinFrame(window, true)
+	SkinFrame(header)
+
+	header:EnableMouse(true)
+	header:SetMovable(true)
+	header:SetScript("OnMouseDown", function(self) self:StartMoving() end)
+	header:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
+
+	local hTitle = stAddonManager.header:CreateFontString(nil, "OVERLAY")
+	hTitle:SetFont(unpack(font))
+	hTitle:SetPoint("CENTER")
+	hTitle:SetText("|cff00aaffst|rAddonManager")
+	header.title = hTitle
+
+	local close = CreateFrame("Button", nil, header)
+	close:SetPoint("RIGHT", header, "RIGHT", 0, 0)
+	close:SetFrameLevel(header:GetFrameLevel()+2)
+	close:SetSize(20, 20)
+	close.text = close:CreateFontString(nil, "OVERLAY")
+	close.text:SetFont(unpack(font))
+	close.text:SetText("x")
+	close.text:SetPoint("CENTER", close, "CENTER", 0, 0)
+	close:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
+	close:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
+	close:SetScript("OnClick", function() window:Hide() end)
+	header.close = close

-		--Load up addon information
-		stAddonManager.AllAddons = stAddonManager:UpdateAddonList()
-		stAddonManager.FilteredAddons = stAddonManager:UpdateAddonList()
-		stAddonManager.showEnabled = true
-		stAddonManager.showDisabled = true
+	local addonListBG = CreateFrame("Frame", window:GetName().."_ScrollBackground", window)
+	addonListBG:SetPoint("TOPLEFT", header, "TOPLEFT", 10, -50)
+	addonListBG:SetWidth(window:GetWidth()-20)
+	addonListBG:SetHeight(window:GetHeight()-60)
+	SkinFrame(addonListBG)
+
+	--Create scroll frame (God damn these things are a pain)
+	local scrollFrame = CreateFrame("ScrollFrame", window:GetName().."_ScrollFrame", window, "UIPanelScrollFrameTemplate")
+	scrollFrame:SetPoint("TOPLEFT", addonListBG, "TOPLEFT", 0, -2)
+	scrollFrame:SetWidth(addonListBG:GetWidth()-25)
+	scrollFrame:SetHeight(addonListBG:GetHeight()-5)
+	SkinScrollBar(_G[window:GetName().."_ScrollFrameScrollBar"])
+	scrollFrame:SetFrameLevel(window:GetFrameLevel()+1)
+
+	scrollFrame.Anchor = CreateFrame("Frame", window:GetName().."_ScrollAnchor", scrollFrame)
+	scrollFrame.Anchor:SetPoint("TOPLEFT", scrollFrame, "TOPLEFT", 0, -3)
+	scrollFrame.Anchor:SetWidth(window:GetWidth()-40)
+	scrollFrame.Anchor:SetHeight(scrollFrame:GetHeight())
+	scrollFrame.Anchor:SetFrameLevel(scrollFrame:GetFrameLevel()+1)
+	scrollFrame:SetScrollChild(scrollFrame.Anchor)
+
+	--Load up addon information
+	stAddonManager.AllAddons = stAddonManager:UpdateAddonList()
+	stAddonManager.FilteredAddons = stAddonManager:UpdateAddonList()
+	stAddonManager.showEnabled = true
+	stAddonManager.showDisabled = true
+
+	stAddonManager.Buttons = {}
+
+	-- local lockedAddons = {}
+	-- if not stLockedAddons then
+		-- stLockedAddons = {}
+	-- else
+		-- lockedAddons = {}
+	-- end
+
+	--Create initial list
+	for i, addon in pairs(stAddonManager.AllAddons) do
+		local button = CreateFrame("Frame", nil, scrollFrame.Anchor)
+		button:SetFrameLevel(scrollFrame.Anchor:GetFrameLevel() + 1)
+		button:SetSize(16, 16)
+		SkinFrame(button)
+		if addon.enabled then
+		button:SetBackdropColor(0/255, 170/255, 255/255)
+		end

-		stAddonManager.Buttons = {}
+		if i == 1 then
+		button:SetPoint("TOPLEFT", scrollFrame.Anchor, "TOPLEFT", 5, -5)
+		else
+		button:SetPoint("TOP", stAddonManager.Buttons[i-1], "BOTTOM", 0, -5)
+		end
+		button.text = button:CreateFontString(nil, "OVERLAY")
+		button.text:SetFont(unpack(font))
+		button.text:SetJustifyH("LEFT")
+		button.text:SetPoint("LEFT", button, "RIGHT", 8, 0)
+		button.text:SetPoint("RIGHT", scrollFrame.Anchor, "RIGHT", 0, 0)
+		button.text:SetText(addon.title)

-		--Create initial list
-		for i, addon in pairs(stAddonManager.AllAddons) do
-			local button = CreateFrame("Frame", nil, scrollFrame.Anchor)
-			button:SetFrameLevel(scrollFrame.Anchor:GetFrameLevel() + 1)
-			button:SetSize(16, 16)
-			SkinFrame(button)
+		button:SetScript("OnEnter", function(self)
+		--tooltip stuff
+		end)
+
+		button:SetScript("OnMouseDown", function(self)
 			if addon.enabled then
-				button:SetBackdropColor(0/255, 170/255, 255/255)
+				self:SetBackdropColor(unpack(backdropcolor))
+				DisableAddOn(addon.name)
+				addon.enabled = false
+			else
+				self:SetBackdropColor(0/255, 170/255, 255/255)
+				EnableAddOn(addon.name)
+				addon.enabled = true
 			end
+		end)

-			if i == 1 then
-				button:SetPoint("TOPLEFT", scrollFrame.Anchor, "TOPLEFT", 5, -5)
+		stAddonManager.Buttons[i] = button
+	end
+
+	 function stAddonManager:UpdateList(AddonsTable)
+		--Start off by hiding all of the buttons
+		for _, b in pairs(stAddonManager.Buttons) do b:Hide() end
+
+		local bIndex = 1
+		for i, addon in pairs(AddonsTable) do
+			local button = stAddonManager.Buttons[bIndex]
+			button:Show()
+			if addon.enabled then
+				button:SetBackdropColor(0/255, 170/255, 255/255)
 			else
-				button:SetPoint("TOP", stAddonManager.Buttons[i-1], "BOTTOM", 0, -5)
+				button:SetBackdropColor(unpack(backdropcolor))
 			end
-			button.text = button:CreateFontString(nil, "OVERLAY")
-			button.text:SetFont(unpack(font))
-			button.text:SetJustifyH("LEFT")
-			button.text:SetPoint("LEFT", button, "RIGHT", 8, 0)
-			button.text:SetPoint("RIGHT", scrollFrame.Anchor, "RIGHT", 0, 0)
-			button.text:SetText(addon.title)
-
-			button:SetScript("OnEnter", function(self)
-				--tooltip stuff
-			end)

 			button:SetScript("OnMouseDown", function(self)
 				if addon.enabled then
@@ -228,94 +537,84 @@ local function LoadWindow()
 				end
 			end)

-			stAddonManager.Buttons[i] = button
+			button.text:SetText(addon.title)
+			bIndex = bIndex+1
 		end
+	end

-		local function UpdateList(AddonsTable)
-			--Start off by hiding all of the buttons
-			for _, b in pairs(stAddonManager.Buttons) do b:Hide() end
-
-			local bIndex = 1
-			for i, addon in pairs(AddonsTable) do
-				local button = stAddonManager.Buttons[bIndex]
-				button:Show()
-				if addon.enabled then
-					button:SetBackdropColor(0/255, 170/255, 255/255)
-				else
-					button:SetBackdropColor(unpack(backdropcolor))
-				end
-
-				button:SetScript("OnMouseDown", function(self)
-					if addon.enabled then
-						self:SetBackdropColor(unpack(backdropcolor))
-						DisableAddOn(addon.name)
-						addon.enabled = false
-					else
-						self:SetBackdropColor(0/255, 170/255, 255/255)
-						EnableAddOn(addon.name)
-						addon.enabled = true
-					end
-				end)
-
-				button.text:SetText(addon.title)
-				bIndex = bIndex+1
-			end
+	--Search Bar
+	local searchBar = CreateFrame("EditBox", window:GetName().."_SearchBar", window)
+	searchBar:SetFrameLevel(window:GetFrameLevel()+1)
+	searchBar:SetPoint("TOPLEFT", header, "BOTTOMLEFT", 10, -5)
+	searchBar:SetWidth(190)
+	searchBar:SetHeight(20)
+	SkinFrame(searchBar)
+	searchBar:SetFont(unpack(font))
+	searchBar:SetText("Search")
+	searchBar:SetAutoFocus(false)
+	searchBar:SetTextInsets(3, 0, 0 ,0)
+	searchBar:SetScript("OnEnterPressed", function(self) self:ClearFocus() end)
+	searchBar:SetScript("OnEscapePressed", function(self) searchBar:SetText("Search") stAddonManager:UpdateList(stAddonManager.AllAddons) searchBar:ClearFocus() end)
+	searchBar:SetScript("OnEditFocusGained", function(self) self:HighlightText() end)
+	searchBar:SetScript("OnTextChanged", function(self, input)
+		if input then
+			stAddonManager.FilteredAddons = stAddonManager:UpdateAddonList(self:GetText())
+			stAddonManager:UpdateList(stAddonManager.FilteredAddons)
 		end
+	end)

-		--Search Bar
-		local searchBar = CreateFrame("EditBox", window:GetName().."_SearchBar", window)
-		searchBar:SetFrameLevel(window:GetFrameLevel()+1)
-		searchBar:SetPoint("TOPLEFT", header, "BOTTOMLEFT", 10, -5)
-		searchBar:SetWidth(200)
-		searchBar:SetHeight(20)
-		SkinFrame(searchBar)
-		searchBar:SetFont(unpack(font))
-		searchBar:SetText("Search")
-		searchBar:SetAutoFocus(false)
-		searchBar:SetTextInsets(3, 0, 0 ,0)
-		searchBar:SetScript("OnEnterPressed", function(self) self:ClearFocus() end)
-		searchBar:SetScript("OnEscapePressed", function(self) searchBar:SetText("Search") UpdateList(stAddonManager.AllAddons) searchBar:ClearFocus() end)
-		searchBar:SetScript("OnEditFocusGained", function(self) self:HighlightText() end)
-		searchBar:SetScript("OnTextChanged", function(self, input)
-			if input then
-				stAddonManager.FilteredAddons = stAddonManager:UpdateAddonList(self:GetText())
-				UpdateList(stAddonManager.FilteredAddons)
-			end
-		end)
-
-		local sbClear = CreateFrame("Button", nil, searchBar)
-		sbClear:SetPoint("RIGHT", searchBar, "RIGHT", 0, 0)
-		sbClear:SetFrameLevel(searchBar:GetFrameLevel()+2)
-		sbClear:SetSize(20, 20)
-		sbClear.text = sbClear:CreateFontString(nil, "OVERLAY")
-		sbClear.text:SetFont(unpack(font))
-		sbClear.text:SetText("x")
-		sbClear.text:SetPoint("CENTER", sbClear, "CENTER", 0, 0)
-		sbClear:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
-		sbClear:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
-		sbClear:SetScript("OnClick", function(self) searchBar:SetText("Search") UpdateList(stAddonManager.AllAddons) searchBar:ClearFocus() end)
-		searchBar.clear = sbClear
+	local sbClear = CreateFrame("Button", nil, searchBar)
+	sbClear:SetPoint("RIGHT", searchBar, "RIGHT", 0, 0)
+	sbClear:SetFrameLevel(searchBar:GetFrameLevel()+2)
+	sbClear:SetSize(20, 20)
+	sbClear.text = sbClear:CreateFontString(nil, "OVERLAY")
+	sbClear.text:SetFont(unpack(font))
+	sbClear.text:SetText("x")
+	sbClear.text:SetPoint("CENTER", sbClear, "CENTER", 0, 0)
+	sbClear:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
+	sbClear:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
+	sbClear:SetScript("OnClick", function(self) searchBar:SetText("Search") stAddonManager:UpdateList(stAddonManager.AllAddons) searchBar:ClearFocus() end)
+	searchBar.clear = sbClear
+	stAddonManager.searchBar = searchBar

-		local reloadButton = CreateFrame("Button", window:GetName().."_ReloadUIButton", window)
-		reloadButton:SetPoint("LEFT", searchBar, "RIGHT", 5, 0)
-		reloadButton:SetWidth(window:GetWidth()-25-searchBar:GetWidth())
-		reloadButton:SetHeight(searchBar:GetHeight())
-		reloadButton.text = reloadButton:CreateFontString(nil, "OVERLAY")
-		reloadButton.text:SetPoint("CENTER")
-		reloadButton.text:SetFont(unpack(font))
-		reloadButton.text:SetText("ReloadUI")
-		reloadButton:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
-		reloadButton:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
-		reloadButton:SetScript("OnClick", function(self)
-			if InCombatLockdown() then return end
-			ReloadUI()
-		end)
-		SkinFrame(reloadButton)
-
-		stAddonManager.Loaded = true
-	else
-		stAddonManager:Show()
-	end
+	local profileButton = CreateFrame("Button", window:GetName().."_ProfileWindowButton", window)
+	profileButton:SetPoint("TOPRIGHT", header, "BOTTOMRIGHT", -10, -5)
+	profileButton:SetSize(20, 20)
+	SkinFrame(profileButton)
+	profileButton.text = profileButton:CreateFontString(nil, "OVERLAY")
+	profileButton.text:SetFont(unpack(font))
+	profileButton.text:SetText(">")
+	profileButton.text:SetPoint("CENTER", profileButton, "CENTER", 0, 0)
+	profileButton:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
+	profileButton:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
+	profileButton:SetScript("OnClick", function(self)
+		LoadProfileWindow()
+		if stAddonManager.ProfileWindow:IsShown() then
+			self.text:SetText("<")
+		else
+			self.text:SetText(">")
+		end
+	end)
+	stAddonManager.profileButton = profileButton
+
+	local reloadButton = CreateFrame("Button", window:GetName().."_ReloadUIButton", window)
+	reloadButton:SetPoint("LEFT", searchBar, "RIGHT", 5, 0)
+	reloadButton:SetPoint("RIGHT", profileButton, "LEFT", -5, 0)
+	reloadButton:SetHeight(searchBar:GetHeight())
+	reloadButton.text = reloadButton:CreateFontString(nil, "OVERLAY")
+	reloadButton.text:SetPoint("CENTER")
+	reloadButton.text:SetFont(unpack(font))
+	reloadButton.text:SetText("ReloadUI")
+	reloadButton:SetScript("OnEnter", function(self) self.text:SetTextColor(0/255, 170/255, 255/255) end)
+	reloadButton:SetScript("OnLeave", function(self) self.text:SetTextColor(255/255, 255/255, 255/255) end)
+	reloadButton:SetScript("OnClick", function(self)
+		if InCombatLockdown() then return end
+		ReloadUI()
+	end)
+	SkinFrame(reloadButton)
+	stAddonManager.reloadButton = reloadButton
+
+	stAddonManager.Loaded = true
 end

 SLASH_STADDONMANAGER1, SLASH_STADDONMANAGER2, SLASH_STADDONMANAGER3 = "/staddonmanager", "/stam", "/staddon"
diff --git a/stAddonManager.toc b/stAddonManager.toc
index 1aeb330..2a4e1a2 100644
--- a/stAddonManager.toc
+++ b/stAddonManager.toc
@@ -3,5 +3,6 @@
 ## Version: @project-version@
 ## Title: |cff00aaffst|rAddonManager
 ## Notes: A simple and minimalistic addon to disable/enabled addons without logging out.
+## SavedVariables: stAddonProfiles, stLockedAddons

 stAddonManager.lua
\ No newline at end of file