Updated Edit Box Chat History
Xruptor [11-11-16 - 14:41]
Updated Edit Box Chat History
-Extended the Edit Box History feature. It will now store up to 40 previous history chat history lines. This persists with each login on a per character basis. This means if you logout and login again your history has been saved and loaded. You can access it immediately by using the UP and DOWN arrow keys.
-You can now use the UP and DOWN arrow keys on the EditBox to go forward and back in the history without using the ALT key.
-Updated the order in which the history is saved and processed.
-Added a few error checks just in case the EditBox is not available on the first chat window.
diff --git a/XanChat.lua b/XanChat.lua
index e10e750..4784d41 100644
--- a/XanChat.lua
+++ b/XanChat.lua
@@ -198,6 +198,7 @@ ChatFrame_AddMessageEventFilter("CHAT_MSG_CHANNEL", urlFilter)
local dummy = function(self) self:Hide() end
local msgHooks = {}
+local HistoryDB
StaticPopupDialogs["XANCHAT_APPLYCHANGES"] = {
text = "xanChat: Would you like to apply the changes now?",
@@ -397,6 +398,46 @@ FCF_ToggleLock = function()
end
--[[------------------------
+ Edit Box History
+--------------------------]]
+
+local function OnArrowPressed(self, key)
+ if #self.historyLines == 0 then
+ return
+ end
+ if key == "DOWN" then
+ self.historyIndex = self.historyIndex - 1
+ if self.historyIndex < 1 then
+ self.historyIndex = #self.historyLines
+ end
+ elseif key == "UP" then
+ self.historyIndex = self.historyIndex + 1
+ if self.historyIndex > #self.historyLines then
+ self.historyIndex = 1
+ end
+ else
+ return
+ end
+ self:SetText(self.historyLines[self.historyIndex])
+end
+
+local function AddEditBoxHistoryLine(editBox, line)
+ if not HistoryDB then return end
+
+ if ( strlen(line) > 0 ) then
+ for i, text in pairs(HistoryDB) do
+ if text == line then
+ return
+ end
+ end
+ tinsert(HistoryDB, #HistoryDB + 1, line)
+ if #HistoryDB > 40 then --max number of lines we want 40 seems like a good number
+ tremove(HistoryDB, 1)
+ end
+ end
+end
+
+--[[------------------------
PLAYER_LOGIN
--------------------------]]
@@ -411,6 +452,9 @@ end
function eFrame:PLAYER_LOGIN()
+ local currentPlayer = UnitName("player")
+ local currentRealm = select(2, UnitFullName("player")) --get shortend realm name with no spaces and dashes
+
--do the DB stuff
if not XCHT_DB then XCHT_DB = {} end
if XCHT_DB.hideSocial == nil then XCHT_DB.hideSocial = false end
@@ -420,6 +464,12 @@ function eFrame:PLAYER_LOGIN()
if XCHT_DB.editBoxTop == nil then XCHT_DB.editBoxTop = false end
if XCHT_DB.hideTabs == nil then XCHT_DB.hideTabs = false end
+ --setup the history DB
+ if not XCHT_HISTORY then XCHT_HISTORY = {} end
+ XCHT_HISTORY[currentRealm] = XCHT_HISTORY[currentRealm] or {}
+ XCHT_HISTORY[currentRealm][currentPlayer] = XCHT_HISTORY[currentRealm][currentPlayer] or {}
+ HistoryDB = XCHT_HISTORY[currentRealm][currentPlayer]
+
--turn off profanity filter
SetCVar("profanityFilter", 0)
@@ -467,37 +517,52 @@ function eFrame:PLAYER_LOGIN()
f:SetClampRectInsets(0,0,0,0)
local editBox = _G[n.."EditBox"]
-
- if not editBox.left then
- editBox.left = _G[n.."EditBoxLeft"]
- editBox.right = _G[n.."EditBoxRight"]
- editBox.mid = _G[n.."EditBoxMid"]
- end
- --remove alt keypress from the EditBox (no longer need alt to move around)
- editBox:SetAltArrowKeyMode(false)
-
- editBox.left:SetAlpha(0)
- editBox.right:SetAlpha(0)
- editBox.mid:SetAlpha(0)
-
- editBox.focusLeft:SetTexture([[Interface\ChatFrame\UI-ChatInputBorder-Left2]])
- editBox.focusRight:SetTexture([[Interface\ChatFrame\UI-ChatInputBorder-Right2]])
- editBox.focusMid:SetTexture([[Interface\ChatFrame\UI-ChatInputBorder-Mid2]])
+ if editBox then
- --do editbox positioning
- if XCHT_DB.editBoxTop then
- setEditBox(true)
- else
- setEditBox()
+ --do the editbox history stuff
+ ---------------------------------
+ editBox.historyLines = HistoryDB or {}
+ editBox.historyIndex = 0
+ editBox:HookScript("OnArrowPressed", OnArrowPressed)
+
+ hooksecurefunc(editBox, "AddHistoryLine", AddEditBoxHistoryLine)
+
+ for i, text in pairs(HistoryDB) do
+ editBox:AddHistoryLine(text)
+ end
+ ---------------------------------
+
+ if not editBox.left then
+ editBox.left = _G[n.."EditBoxLeft"]
+ editBox.right = _G[n.."EditBoxRight"]
+ editBox.mid = _G[n.."EditBoxMid"]
+ end
+
+ --remove alt keypress from the EditBox (no longer need alt to move around)
+ editBox:SetAltArrowKeyMode(false)
+
+ editBox.left:SetAlpha(0)
+ editBox.right:SetAlpha(0)
+ editBox.mid:SetAlpha(0)
+
+ editBox.focusLeft:SetTexture([[Interface\ChatFrame\UI-ChatInputBorder-Left2]])
+ editBox.focusRight:SetTexture([[Interface\ChatFrame\UI-ChatInputBorder-Right2]])
+ editBox.focusMid:SetTexture([[Interface\ChatFrame\UI-ChatInputBorder-Mid2]])
+
+ --do editbox positioning
+ if XCHT_DB.editBoxTop then
+ setEditBox(true)
+ else
+ setEditBox()
+ end
+
+ --when the editbox is on the top, complications occur because sometimes you are not allowed to click on the tabs.
+ --to fix this we'll just make the tab close the editbox
+ --also force the editbox to hide itself when it loses focus
+ _G[n.."Tab"]:HookScript("OnClick", function() editBox:Hide() end)
+ editBox:HookScript("OnEditFocusLost", function(self) self:Hide() end)
end
-
- --when the editbox is on the top, complications occur because sometimes you are not allowed to click on the tabs.
- --to fix this we'll just make the tab close the editbox
- --also force the editbox to hide itself when it loses focus
- _G[n.."Tab"]:HookScript("OnClick", function() editBox:Hide() end)
- editBox:HookScript("OnEditFocusLost", function(self) self:Hide() end)
-
--hide the scroll bars
if XCHT_DB.hideScroll then
_G[n.."ButtonFrameUpButton"]:Hide()
diff --git a/XanChat.toc b/XanChat.toc
index f04ba4d..d2c373f 100644
--- a/XanChat.toc
+++ b/XanChat.toc
@@ -2,8 +2,8 @@
## Title: xanChat
## Notes: A very minimalistic chat modification addon.
## Author: Xruptor
-## Version: 4.3
+## Version: 4.4
## OptionalDeps: tekDebug
-## SavedVariables: XCHT_DB
+## SavedVariables: XCHT_DB, XCHT_HISTORY
xanChat.lua