Quantcast

Update to Chat frame alignments and arrow button history selections in the editbox

failcoder [08-15-15 - 01:18]
Update to Chat frame alignments and arrow button history selections in the editbox
Filename
SVUI_!Core/system/api.lua
SVUI_!Core/system/dock.lua
SVUI_Chat/SVUI_Chat.lua
SVUI_QuestTracker/components/quests.lua
diff --git a/SVUI_!Core/system/api.lua b/SVUI_!Core/system/api.lua
index 117d751..484bdb5 100644
--- a/SVUI_!Core/system/api.lua
+++ b/SVUI_!Core/system/api.lua
@@ -388,8 +388,9 @@ local SecureFadeCallback = function(self, callback, alwaysOnHide, alwaysOnShow)
         self.___fadehidefunc = callback;
     elseif(alwaysOnShow) then
         self.___fadeshowfunc = callback;
+    else
+        self.___fadefunc = callback;
     end
-    self.___fadefunc = callback;
 end
 --[[
 ##########################################################
diff --git a/SVUI_!Core/system/dock.lua b/SVUI_!Core/system/dock.lua
index 31891da..338f621 100644
--- a/SVUI_!Core/system/dock.lua
+++ b/SVUI_!Core/system/dock.lua
@@ -1697,9 +1697,12 @@ function MOD:NewDocklet(location, globalName, readableName, texture, onenter)
 		self.private.Opacity[globalName] = 1;
 	end

+	local parentWidth, parentHeight = newParent.Window:GetSize();
+
 	frame:SetParent(newParent.Window);
-	frame:SetSize(newParent.Window:GetSize());
-	frame:SetAllPoints(newParent.Window);
+	frame:SetSize(parentWidth, parentHeight);
+	frame:SetPoint("TOPLEFT", newParent.Window, "TOPLEFT", 0, 0);
+	frame:SetPoint("BOTTOMRIGHT", newParent.Window, "BOTTOMRIGHT", 0, 0);
 	frame:SetFrameStrata("BACKGROUND");

 	frame.Parent = newParent;
diff --git a/SVUI_Chat/SVUI_Chat.lua b/SVUI_Chat/SVUI_Chat.lua
index a404389..bfe1ffb 100644
--- a/SVUI_Chat/SVUI_Chat.lua
+++ b/SVUI_Chat/SVUI_Chat.lua
@@ -33,6 +33,7 @@ local match         = string.match;
 local gsub          = string.gsub;
 local len          	= string.len;
 local sub          	= string.sub;
+local trim          = string.trim;
 --MATH
 local math          = _G.math;
 local floor         = math.floor
@@ -507,10 +508,49 @@ function MOD:GetLines(...)
 end

 do
-	local TabSafety = {};
+	local EB_HISTORY, EBH_LINE = {},{};
 	local refreshLocked = false;
 	local doskey = false;

+	local _hook_AddHistoryLine = function(self, text)
+		if(not text or len(text) == 0) then
+			return
+		end
+		local cmd = text:match("^(/%S+)")
+		if(cmd and IsSecureCmd(cmd)) then
+			return
+		end
+		local ebName = self:GetName();
+		for i = 1, #EB_HISTORY[ebName] do
+			if EB_HISTORY[ebName][i] == text then
+				EBH_LINE[ebName] = i + 1
+				return
+			end
+		end
+		tinsert(EB_HISTORY[ebName], text)
+		while(#EB_HISTORY[ebName] > self:GetHistoryLines()) do
+			tremove(EB_HISTORY[ebName], 1)
+		end
+		EBH_LINE[ebName] = #EB_HISTORY[ebName] + 1;
+	end
+
+	local function UpdateFromEditBoxHistory(self, increment)
+		local ebName = self:GetName();
+		if(#EB_HISTORY[ebName] == 0) then return end
+		local current_line = EBH_LINE[ebName] + increment
+		if(current_line < 1) then
+			current_line = #EB_HISTORY[ebName];
+		elseif(current_line > #EB_HISTORY[ebName]) then
+			current_line = 1;
+		end
+		EBH_LINE[ebName] = current_line;
+		if(EB_HISTORY[ebName][current_line] ~= self:GetText()) then
+			local text = EB_HISTORY[ebName][current_line];
+			self:SetText(trim(text));
+			self:SetCursorPosition(len(text));
+		end
+	end
+
 	local SetHyperlink = ItemRefTooltip.SetHyperlink
 	function ItemRefTooltip:SetHyperlink(data, ...)
 		if (data):sub(1, 3) == "url" then
@@ -535,17 +575,21 @@ do
 		end
 	end

-	local EditBox_OnKeyUp = function(self, button)
-		if(not button) then return end
+	local EditBox_OnArrowPressed = function(self, key)
+		if(not key) then return end
 		if(doskey) then
-			if(button == KEY_LEFT) then
+			if(key == "LEFT") then
 				self:SetCursorPosition(0)
-			elseif(button == KEY_RIGHT) then
+			elseif(key == "RIGHT") then
 				self:SetCursorPosition(self:GetNumLetters())
 			end
 			doskey = false
-		elseif((button == KEY_UP) or (button == KEY_DOWN)) then
+		elseif key == "UP" then
+			doskey = true
+			return UpdateFromEditBoxHistory(self, -1)
+		elseif key == "DOWN" then
 			doskey = true
+			return UpdateFromEditBoxHistory(self, 1)
 		end
 	end

@@ -673,6 +717,14 @@ do
 	    end
 	end

+	local ChatDock_ResizeCallback = function(self)
+		if(not InCombatLockdown()) then
+			local chat = self.Owner;
+			chat:ClearAllPoints();
+			chat:SetAllPoints(self);
+		end
+	end
+
 	local ChatDock_HideCallback = function(self)
 		--print('ChatDock_HideCallback ' .. self:GetName())
 		--print('ChatDock_HideCallback: ' .. self.Button:GetName())
@@ -690,14 +742,7 @@ do
 		chat:FadeIn(0.2, chat:GetAlpha(), 1)
 	end

-	local ChatDock_ResizeCallback = function(self)
-		local chat = self.Owner;
-		chat:ClearAllPoints();
-		chat:SetAllPoints(self);
-		--chat:SetSize(self:GetSize());
-	end
-
-	local ChatDock_LeftClickCallback = function(self,button)
+	local ChatDock_LeftClickCallback = function(self, button)
 		local chatTab = self.link
 		local chatFrame = _G[("ChatFrame%d"):format(chatTab:GetID())];
 		if(not self.isFloating) then
@@ -712,6 +757,10 @@ do
 			ScrollIndicator:Show()
 			SV.Animate:Flash(ScrollIndicator,1,true)
 		end
+		if(not InCombatLockdown()) then
+			chatFrame:ClearAllPoints();
+			chatFrame:SetAllPoints(chatFrame.Dock);
+		end
 	end

 	local ChatDock_FontSizeSliderFunc = function(self, value)
@@ -737,6 +786,7 @@ do
 		--chat.Panel:Hide();
 		chat.Dock = SV.Dock:NewDocklet("BottomLeft", format("SVUI_ChatFrameDock%d", chatID), "Chat Frame "..chatID, MOD.media.dockIcon, ChatDockTab_OnEnter);
 		chat.Dock.Owner = chat;
+
 		local ChatDock_ExtendedOptions;
 		if(chatID == 1) then
 			ScrollIndicator:ClearAllPoints()
@@ -768,6 +818,7 @@ do

 		chat.Dock:SetVisibilityCallbacks(ChatDock_ShowCallback, ChatDock_HideCallback, ChatDock_ResizeCallback);
 		chat.Dock:SetClickCallbacks(ChatDock_LeftClickCallback, false, ChatDock_ExtendedOptions);
+		--chat.Dock:FadeCallback(ChatDock_ResizeCallback, false, true);
 		-------------------------------------------
 		SV:FontManager(chat, "chatdialog", "LEFT")
 		SV:FontManager(tabText, "chattab")
@@ -782,7 +833,7 @@ do

 		chat:SetFrameLevel(10)
 		chat:SetClampRectInsets(0, 0, 0, 0)
-		chat:SetClampedToScreen(true)
+		chat:SetClampedToScreen(false);
 		chat:SetMovable(true);
 		chat:SetUserPlaced(true);

@@ -834,10 +885,16 @@ do
 		editBox:SetAltArrowKeyMode(false)
 		editBox:SetAllPoints(chat.Dock.Parent.Alert)
 		SV.API:Set("!_EditBox", editBox, false, false, -2, -1)
-		editBox:HookScript("OnEditFocusGained", EditBox_OnEditFocusGained)
-		editBox:HookScript("OnEditFocusLost", EditBox_OnEditFocusLost)
-		editBox:HookScript("OnTextChanged", EditBox_OnTextChanged)
-		editBox:HookScript("OnKeyUp", EditBox_OnKeyUp)
+
+		if(not EB_HISTORY[editBoxName]) then
+			editBox:HookScript("OnEditFocusGained", EditBox_OnEditFocusGained)
+			editBox:HookScript("OnEditFocusLost", EditBox_OnEditFocusLost)
+			editBox:HookScript("OnTextChanged", EditBox_OnTextChanged)
+			editBox:HookScript("OnArrowPressed", EditBox_OnArrowPressed)
+			hooksecurefunc(editBox, "AddHistoryLine", _hook_AddHistoryLine)
+			EB_HISTORY[editBoxName] = {};
+			EBH_LINE[editBoxName] = {};
+		end

 		editBox.DockLink = chat.Dock.Parent;
 		-------------------------------------------
@@ -1514,7 +1571,7 @@ do
 		end
 	end

-	local _hook_FCF_OpenTemporaryWindow = function(chatType, chatTarget, sourceChatFrame, selectWindow)
+	local _hook_FCF_OpenTemporaryWindow = function(...)
 		--print('_hook_FCF_OpenTemporaryWindow')
 		for id, chatFrameName in pairs(CHAT_FRAMES) do
 			local frame = _G[chatFrameName];
@@ -1532,9 +1589,10 @@ do
 		--print(chatFrame:GetName())
 	end

-	local _hook_FCF_DockFrame = function()
-		--print('_hook_FCF_DockFrame')
-		MOD.RefreshChatFrames();
+	local _hook_FCF_OpenNewWindow = function(...)
+		--print('_hook_FCF_OpenNewWindow')
+		OpenNewSVUIChatFrame(...);
+		--print(chatFrame:GetName())
 	end

 	local _hook_FCF_FadeInChatFrame = function(chat)
@@ -1560,26 +1618,41 @@ do
 		return FCFDock_ScrollToSelectedTab(dock);
 	end

+	_G.FCF_UpdateDockPosition = function() end
+	_G.FCF_RestorePositionAndDimensions = function() end
+
+	--TESTS
+	local _hook_FCF_DockFrame = function(self)
+		FCF_SetLocked(self, false);
+		if(self.Dock) then
+			local key = self.Dock:GetName();
+			MOD.private.activeTabs[key] = true;
+			self.oldAlpha = 0;
+			self.Dock:UpdateBackdrop();
+			--self.Dock.Parent.Bar:SetDefault(self.Dock.Button)
+		end;
+		MOD.RefreshChatFrames();
+	end
+
 	function SetAllChatHooks()
 		NewHook('FCF_StartAlertFlash', _hook_FCFStartAlertFlash)
 		NewHook('FCF_StopAlertFlash', _hook_FCFStopAlertFlash)
-		NewHook('FCF_OpenNewWindow', OpenNewSVUIChatFrame)
-		--NewHook('FCFDock_AddChatFrame', OpenNewSVUIChatFrame)
+		NewHook('FCF_OpenNewWindow', _hook_FCF_OpenNewWindow)
 		NewHook('FCF_UnDockFrame', MOD.RefreshChatFrames)
-		NewHook('FCF_DockFrame', MOD.RefreshChatFrames)
-		--NewHook('FCF_DockUpdate', MOD.RefreshChatFrames)
-		NewHook('FCF_OpenTemporaryWindow', _hook_FCF_OpenTemporaryWindow)
+		NewHook('FCF_DockFrame', _hook_FCF_DockFrame)
+		--NewHook('FCF_OpenTemporaryWindow', _hook_FCF_OpenTemporaryWindow)
 		NewHook('ChatEdit_OnEnterPressed', _hook_ChatEditOnEnterKey)
 		NewHook('FCF_SetChatWindowFontSize', _hook_ChatFontUpdate)
 		NewHook(GeneralDockManager, 'SetPoint', _hook_GDMFrameSetPoint)
 		NewHook(GeneralDockManagerScrollFrame, 'SetPoint', _hook_GDMScrollSetPoint)
 		--NewHook("FCF_SetWindowColor", _hook_FCF_SetWindowColor)
 		--NewHook("FCFDock_UpdateTabs", function() print('FCFDock_UpdateTabs') end)
-
 		NewHook("FCF_Close", _hook_FCF_Close)
 		NewHook("ChatEdit_UpdateHeader", _hook_OnUpdateHeader)

 		-- TESTING
+		--NewHook('FCFDock_AddChatFrame', _hook_FCFDock_AddChatFrame)
+		--NewHook('FCF_DockUpdate', _hook_FCF_DockUpdate)
 		--NewHook("FCF_FadeInChatFrame", _hook_FCF_FadeInChatFrame)
 		--NewHook("FCF_FadeOutChatFrame", _hook_FCF_FadeOutChatFrame)
 	end
diff --git a/SVUI_QuestTracker/components/quests.lua b/SVUI_QuestTracker/components/quests.lua
index 2ef320b..6b9ffba 100644
--- a/SVUI_QuestTracker/components/quests.lua
+++ b/SVUI_QuestTracker/components/quests.lua
@@ -1157,15 +1157,17 @@ local function ReAnchorItemBar()
 	anchor1 = prefix1 .. anchor1;
 	anchor2 = prefix2 .. anchor2;

+	local parentWindow = MOD.Docklet.Parent.Window;
+
 	ItemBar:ClearAllPoints();
 	ItemBar:SetParent(SV.Screen);
-	ItemBar:SetPoint(anchor1, MOD.Docklet.Parent, anchor2, xOff, yOff);
+	ItemBar:SetPoint(anchor1, parentWindow, anchor2, xOff, yOff);
 	if(isHorizontal) then
-		ItemBar:SetWidth(MOD.Docklet.Parent:GetWidth());
+		ItemBar:SetWidth(parentWindow:GetWidth());
 		ItemBar:SetHeight(32);
 	else
 		ItemBar:SetWidth(32);
-		ItemBar:SetHeight(MOD.Docklet.Parent:GetHeight());
+		ItemBar:SetHeight(parentWindow:GetHeight());
 	end
 end