Reverting to last release.

This commit is contained in:
Andrew Tomaka 2011-08-12 18:38:52 -04:00
parent a663d6d8aa
commit a78df7bc99

View file

@ -1,26 +1,32 @@
ChatSaver = LibStub('AceAddon-3.0'):NewAddon('ChatSaver','AceConsole-3.0','AceHook-3.0','AceEvent-3.0') ChatSaver = LibStub('AceAddon-3.0'):NewAddon('ChatSaver','AceConsole-3.0','AceHook-3.0','AceEvent-3.0');
local core = ChatSaver local core = ChatSaver;
function core:OnInitialize() function core:OnInitialize()
if ChatSaverDB == nil then self:RegisterChatCommand('cs','SlashCommand');
core.firstrun = true
ChatSaverDB = {} if(ChatSaverDB == nil) then
core.firstrun = true;
ChatSaverDB = {};
else else
core.firstrun = false core.firstrun = false;
end end
end end
function core:OnEnable() function core:OnEnable()
self:Hook('ToggleChatChannel','ToggleChatChannel',true) self:RawHook(SlashCmdList,'JOIN','JoinChannel',true);
self:RawHook(SlashCmdList,'LEAVE','LeaveChannel',true);
self:Hook('ToggleChatChannel','ToggleChatChannel',true);
self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','ProcessChannelChange') self:RegisterEvent('CHANNEL_UI_UPDATE','RejoinChannels');
if core.firstrun then if(core.firstrun) then
self:RegisterEvent('CHANNEL_UI_UPDATE','SetupChatSaver') self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','SetupChatSaver');
else
self:RegisterEvent('CHANNEL_UI_UPDATE','RejoinChannels')
end end
end end
function core:SlashCommand()
core:RejoinChannels();
end
--[[ --[[
-- CHANNEL FUNCTIONS -- CHANNEL FUNCTIONS
-- Because GetChannelName() and GetChannelDisplayInfo() are less -- Because GetChannelName() and GetChannelDisplayInfo() are less
@ -28,116 +34,135 @@ end
]] -- ]] --
function core:GetChannelInfo(id) function core:GetChannelInfo(id)
local channelNumber,channelName = GetChannelName(id) local channelNumber,channelName = GetChannelName(id);
local channelTable = core:GetChannelTable() local channelTable = core:GetChannelTable();
if channelName == nil then if(channelName == nil) then
id = channelTable[id] id = channelTable[id];
if id ~= nil then if(id ~= nil) then
channelNumber,channelName = GetChannelName(id) channelNumber,channelName = GetChannelName(id);
end end
end end
return channelNumber,channelName,core:GetChannelCategory(channelNumber) return channelNumber,channelName,core:GetChannelCategory(channelNumber);
end end
function core:GetChannelTable() function core:GetChannelTable()
local channelList = { GetChannelList() } local channelList = { GetChannelList() };
local channelTable = {} local channelTable = {};
for i = 1,#channelList,2 do for i = 1,#channelList,2 do
channelTable[channelList[i]] = channelList[i + 1] channelTable[channelList[i]] = channelList[i + 1];
channelTable[channelList[i + 1]] = channelList[i] channelTable[channelList[i + 1]] = channelList[i];
if type(channelList[i + 1]) == 'string' then if(type(channelList[i + 1]) == 'string') then
channelTable[channelList[i + 1]:lower()] = channelList[i] channelTable[channelList[i + 1]:lower()] = channelList[i];
end end
end end
return channelTable return channelTable;
end end
function core:GetChannelCategory(number) function core:GetChannelCategory(number)
for i = 1,GetNumDisplayChannels(),1 do for i = 1,GetNumDisplayChannels(),1 do
local _,_,_,channelNumber,_,_,category = GetChannelDisplayInfo(i) local _,_,_,channelNumber,_,_,category = GetChannelDisplayInfo(i);
if channelNumber == number then if(channelNumber == number) then
return category return category;
end end
end end
end end
--[[ EVENT FUNCTIONS ]] -- --[[ EVENT FUNCTIONS ]] --
function core:ProcessChannelChange(_,message,_,_,_,_,_,_,index,name)
if message == 'YOU_JOINED' then
local number,_,category = core:GetChannelInfo(name)
if category == 'CHANNEL_CATEGORY_CUSTOM' then
ChatSaverDB[name] = {}
ChatSaverDB[name]['frames'] = {}
ChatSaverDB[name]['index'] = number
ChatSaverDB[name]['frames'][DEFAULT_CHAT_FRAME:GetID()] = true
end
elseif message == 'YOU_LEFT' then
ChatSaverDB[name] = nil
end
end
function core:RejoinChannels(...) function core:RejoinChannels(...)
local currentChannels = {} local currentChannels = {};
for i = 1,select('#',GetChannelList()) do for i = 1,select('#',GetChannelList()) do
currentChannels[select(i,GetChannelList())] = true currentChannels[select(i,GetChannelList())] = true
end end
local sortedChannels = {} local sortedChannels = {};
for channel,_ in pairs(ChatSaverDB) do for channel,_ in pairs(ChatSaverDB) do
table.insert(sortedChannels,channel) table.insert(sortedChannels,channel);
end end
table.sort(sortedChannels,function(a,b) return ChatSaverDB[a].index < ChatSaverDB[b].index end) table.sort(sortedChannels,function(a,b) return ChatSaverDB[a].index < ChatSaverDB[b].index end);
for _,channel in pairs(sortedChannels) do for _,channel in pairs(sortedChannels) do
if currentChannels[channel] == nil then if(currentChannels[channel] == nil) then
JoinPermanentChannel(channel) -- does not place in chat frame properly JoinPermanentChannel(channel); -- does not place in chat frame properly
for index,_ in pairs(ChatSaverDB[channel].frames) do for index,_ in pairs(ChatSaverDB[channel].frames) do
ChatFrame_AddChannel(_G['ChatFrame'..index],channel) ChatFrame_AddChannel(_G['ChatFrame'..index],channel);
end end
end end
end end
self:UnregisterEvent('CHANNEL_UI_UPDATE') self:UnregisterEvent('CHANNEL_UI_UPDATE');
end end
function core:SetupChatSaver(...) function core:SetupChatSaver(...)
for frame = 1,NUM_CHAT_WINDOWS do for frame = 1,NUM_CHAT_WINDOWS do
local chatWindowChannels = { GetChatWindowChannels(frame) } local chatWindowChannels = { GetChatWindowChannels(frame) };
for i = 1,#chatWindowChannels,2 do for i = 1,#chatWindowChannels,2 do
local number,name,category = core:GetChannelInfo(chatWindowChannels[i]) local number,name,category = core:GetChannelInfo(chatWindowChannels[i]);
if category == 'CHANNEL_CATEGORY_CUSTOM' then if(category == 'CHANNEL_CATEGORY_CUSTOM') then
if ChatSaverDB[name] == nil then if(ChatSaverDB[name] == nil) then
ChatSaverDB[name] = {} ChatSaverDB[name] = {};
ChatSaverDB[name]['frames'] = {} ChatSaverDB[name]['frames'] = {};
ChatSaverDB[name]['index'] = number ChatSaverDB[name]['index'] = number;
end end
ChatSaverDB[name]['frames'][frame] = true ChatSaverDB[name]['frames'][frame] = true;
end end
end end
end end
self:UnregisterEvent('CHANNEL_UI_UPDATE') self:UnregisterEvent('CHAT_MSG_CHANNEL_NOTICE');
end
function core:StoreChannel(_,_,_,_,_,_,_,_,_,name)
local number,channelName,category = core:GetChannelInfo(name);
if(category == 'CHANNEL_CATEGORY_CUSTOM') then
ChatSaverDB[name] = {};
ChatSaverDB[name]['frames'] = {};
ChatSaverDB[name]['index'] = number;
ChatSaverDB[name]['frames'][DEFAULT_CHAT_FRAME:GetID()] = true;
end
self:UnregisterEvent('CHAT_MSG_CHANNEL_NOTICE');
end end
--[[ HOOKED FUNCTIONS ]] -- --[[ HOOKED FUNCTIONS ]] --
function core:ToggleChatChannel(checked,channel) function core:JoinChannel(msg)
if ChatSaverDB[channel] == nil then self.hooks[SlashCmdList].JOIN(msg);
return
end
if checked then local name = gsub(msg,"%s*([^%s]+).*","%1");
ChatSaverDB[channel]['frames'][FCF_GetCurrentChatFrameID()] = true
else if(strlen(name) > 0 and string.match(name,"%a+")) then
ChatSaverDB[channel]['frames'][FCF_GetCurrentChatFrameID()] = nil self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','StoreChannel');
end
end
function core:LeaveChannel(msg)
self.hooks[SlashCmdList].LEAVE(msg);
local id = gsub(msg,"%s*([^%s]+).*","%1");
if(strlen(id) > 0) then
local _,name = core:GetChannelInfo(id);
ChatSaverDB[name] = nil;
end
end
function core:ToggleChatChannel(checked,channel)
if(ChatSaverDB[channel] == nil) then
return;
end
if(checked) then
ChatSaverDB[channel]['frames'][FCF_GetCurrentChatFrameID()] = true;
else
ChatSaverDB[channel]['frames'][FCF_GetCurrentChatFrameID()] = nil;
end end
end end