Quantcast

Removed the Search/Clear buttons - they're redundant now that the SearchBox behaves properly.

James D. Callahan III [04-20-10 - 04:19]
Removed the Search/Clear buttons - they're redundant now that the SearchBox behaves properly.
Filename
Frame.lua
diff --git a/Frame.lua b/Frame.lua
index e875aa3..ee9a8ea 100644
--- a/Frame.lua
+++ b/Frame.lua
@@ -1510,10 +1510,8 @@ ExpandButton:SetScript("OnClick",
 			       ListFrame:Update(expand_mode, false)

 			       if expanded then
-				       addon:Debug("Contracting")
 				       self:Contract()
 			       else
-				       addon:Debug("Expanding")
 				       self:Expand()
 			       end
 		       end)
@@ -1532,8 +1530,6 @@ end
 function ExpandButton:Contract()
 	self.is_expanded = nil

-	addon:Debug("ExpandButton:Contract")
-
 	self:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up")
 	self:SetPushedTexture("Interface\\Buttons\\UI-PlusButton-Down")
 	self:SetHighlightTexture("Interface\\Buttons\\UI-PlusButton-Hilight")
@@ -1618,13 +1614,8 @@ do
 end	-- do

 -------------------------------------------------------------------------------
--- Container frame for search widgets - keeps them all grouped for easier movement.
+-- Search EditBox
 -------------------------------------------------------------------------------
-local SearchContainer = CreateFrame("Frame", nil, MainPanel)
-SearchContainer:SetPoint("LEFT", ExpandButtonFrame.right, "RIGHT", 10, 2)
-SearchContainer:SetPoint("RIGHT", WidgetContainer2, "RIGHT", 0, 0)
-SearchContainer:SetHeight(30)
-
 local SearchBox = CreateFrame("EditBox", nil, MainPanel, "InputBoxTemplate")

 SearchBox:EnableMouse(true)
@@ -1632,7 +1623,7 @@ SearchBox:SetAutoFocus(false)
 SearchBox:SetFontObject(ChatFontSmall)
 SearchBox:SetWidth(110)
 SearchBox:SetHeight(12)
-SearchBox:SetPoint("LEFT", SearchContainer, "LEFT", 0, 0)
+SearchBox:SetPoint("LEFT", ExpandButtonFrame.right, "RIGHT", 10, 2)
 SearchBox:Show()

 MainPanel.search_editbox = SearchBox
@@ -1640,14 +1631,27 @@ MainPanel.search_editbox = SearchBox
 SearchBox:SetText(_G.SEARCH)
 SearchBox:SetHistoryLines(10)

+-- Resets the SearchBox text and the state of all ListFrame and recipe_list entries.
+function SearchBox:Reset()
+	local recipe_list = private.recipe_list
+
+	for index, recipe in pairs(recipe_list) do
+		recipe:RemoveState("RELEVANT")
+	end
+	self.prev_search = nil
+
+	self:SetText(_G.SEARCH)
+	self:ClearFocus()
+	ListFrame:Update(false, false)
+end
+
 SearchBox:SetScript("OnEnterPressed",
 		    function(self)
 			    local searchtext = self:GetText()
 			    searchtext = searchtext:trim()

 			    if not searchtext or searchtext == "" then
-				    self:SetText(_G.SEARCH)
-				    ListFrame:Update(false, false)
+				    self:Reset()
 				    return
 			    end

@@ -1661,11 +1665,6 @@ SearchBox:SetScript("OnEnterPressed",
 			    self:AddHistoryLine(searchtext)
 			    SearchRecipes(searchtext)
 			    ListFrame:Update(false, false)
-
-			    ExpandButton:Contract()
-
-			    ARL_SearchButton:SetNormalFontObject("GameFontDisableSmall")
-			    ARL_SearchButton:Disable()
 		    end)

 SearchBox:SetScript("OnEditFocusGained",
@@ -1680,7 +1679,7 @@ SearchBox:SetScript("OnEditFocusLost",
 			    local text = self:GetText()

 			    if text == "" then
-				    self:SetText(_G.SEARCH)
+				    self:Reset()
 				    return
 			    end
 			    self:AddHistoryLine(text)
@@ -1693,16 +1692,8 @@ SearchBox:SetScript("OnTextSet",

 			    if text ~= "" and text ~= _G.SEARCH and text ~= self.prev_search then
 				    self:HighlightText()
-				    ARL_SearchButton:SetNormalFontObject("GameFontNormalSmall")
-				    ARL_SearchButton:Enable()
 			    else
-				    local recipe_list = private.recipe_list
-
-				    for spell_id in pairs(recipe_list) do
-					    recipe_list[spell_id]:RemoveState("RELEVANT")
-				    end
-				    ARL_SearchButton:SetNormalFontObject("GameFontDisableSmall")
-				    ARL_SearchButton:Disable()
+				    self:Reset()
 			    end
 		    end)

@@ -1733,63 +1724,12 @@ do

 				    if text ~= "" and text ~= _G.SEARCH and text ~= self.prev_search then
 					    updater:Show()
-					    ARL_SearchButton:SetNormalFontObject("GameFontNormalSmall")
-					    ARL_SearchButton:Enable()
 				    else
-					    ARL_SearchButton:SetNormalFontObject("GameFontDisableSmall")
-					    ARL_SearchButton:Disable()
+					    self:Reset()
 				    end
 			    end)
 end	-- do

-local ARL_ClearButton = GenericCreateButton("ARL_ClearButton", MainPanel, 28, 28, "GameFontNormalSmall", "GameFontHighlightSmall", "", "CENTER", L["CLEAR_DESC"], 3)
-ARL_ClearButton:SetPoint("LEFT", SearchBox, "RIGHT", -5, 0)
-
-ARL_ClearButton:SetScript("OnClick",
-			  function()
-				  local recipe_list = private.recipe_list
-
-				  -- Reset the search flags
-				  for index in pairs(recipe_list) do
-					  recipe_list[index]:RemoveState("RELEVANT")
-				  end
-				  ExpandButton:Contract()
-
-				  -- Disable the search button since we're not searching for anything now
-				  ARL_SearchButton:SetNormalFontObject("GameFontDisableSmall")
-				  ARL_SearchButton:Disable()
-
-				  MainPanel.search_editbox:SetText(_G.SEARCH)
-				  MainPanel.search_editbox:ClearFocus()
-				  MainPanel.search_editbox.prev_search = nil
-				  ListFrame:Update(false, false)
-			  end)
-
-local ARL_SearchButton = GenericCreateButton("ARL_SearchButton", MainPanel, 25, 74, "GameFontDisableSmall", "GameFontHighlightSmall", _G.SEARCH, "CENTER",
-					     L["SEARCH_DESC"], 1)
-ARL_SearchButton:SetPoint("LEFT", ARL_ClearButton, "RIGHT", 2, 0)
-
-ARL_SearchButton:Disable()
-ARL_SearchButton:SetScript("OnClick",
-			   function(this)
-				   local searchtext = MainPanel.search_editbox:GetText()
-				   searchtext = searchtext:trim()
-
-				   if searchtext ~= "" then
-					   MainPanel.search_editbox.prev_search = searchtext
-
-					   MainPanel.search_editbox:HighlightText()
-					   MainPanel.search_editbox:AddHistoryLine(searchtext)
-					   SearchRecipes(searchtext)
-					   ListFrame:Update(false, false)
-
-					   ExpandButton:Contract()
-
-					   ARL_SearchButton:SetNormalFontObject("GameFontDisableSmall")
-					   ARL_SearchButton:Disable()
-				   end
-			   end)
-
 -------------------------------------------------------------------------------
 -- Create the X-close button, and set its scripts.
 -------------------------------------------------------------------------------