---------------------------------------------------------------------------------
--
-- Prat - A framework for World of Warcraft chat mods
--
-- Copyright (C) 2006-2007  Prat Development Team
--
-- This program is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License
-- as published by the Free Software Foundation; either version 2
-- of the License, or (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to:
--
-- Free Software Foundation, Inc.,
-- 51 Franklin Street, Fifth Floor,
-- Boston, MA  02110-1301, USA.
--
--
-------------------------------------------------------------------------------


--[[
Name: Prat_Clear
Revision: $Revision: r24999 $
Author(s): Fin (fin@instinct.org)
Website: http://files.wowace.com/Prat/
Documentation: http://www.wowace.com/wiki/Prat/Integrated_Modules#Clear
Subversion: http://svn.wowace.com/wowace/trunk/Prat/
Discussions: http://groups.google.com/group/wow-prat
Issues and feature requests: http://code.google.com/p/prat/issues/list
Description: Adds /clear (or /cls) and /clearall (or /clsall) commands for clearing chat frames (default=off).
Dependencies: Prat
]]

-- set prat module name
local PRAT_MODULE = Prat:RequestModuleName("PratClear")

-- define localized strings
local L = AceLibrary("AceLocale-2.2"):new(PRAT_MODULE)

L:RegisterTranslations("enUS", function() return {
	["Clear"] = true,
	['Clearall'] = true,
	["Adds /clear (or /cls) and /clearall (or /clsall) commands for clearing chat frames"] = true,
	["Clears the current chat frame"] = true,
	['Clears all chat frames'] = true,
} end)


L:RegisterTranslations("deDE", function() return {
	["Clear"] = "Leeren",
	['Clearall'] = "Leere alles",
	["Adds /clear (or /cls) and /clearall (or /clsall) commands for clearing chat frames"] = "F\195\188gt /clear (oder /cls) und /clearall (oder /clsall) Befehle f\195\188rs Leeren der Chatfenster hinzu.",
	["Clears the current chat frame"] = "Leert das gegenw\195\164rtige Chatfenster.",
	['Clears all chat frames'] = "Leert alle Chatfenster.",
} end)


--[[
L:RegisterTranslations("frFR", function() return {
	["Clear"] = "",
	['Clearall'] = "",
	["Adds /clear (or /cls) and /clearall (or /clsall) commands for clearing chat frames"] = "",
	["Clears the current chat frame"] = "",
	['Clears all chat frames'] = "",
} end)
]]

--[[
L:RegisterTranslations("esES", function() return {
	["Clear"] = "",
	['Clearall'] = "",
	["Adds /clear (or /cls) and /clearall (or /clsall) commands for clearing chat frames"] = "",
	["Clears the current chat frame"] = "",
	['Clears all chat frames'] = "",
} end)
]]

L:RegisterTranslations("koKR", function() return {
	["Clear"] = "클리어",
	['Clearall'] = "전체클리어",
	["Adds /clear (or /cls) and /clearall (or /clsall) commands for clearing chat frames"] = "대화창 클리어를 위한 명령어 /clear (혹은 /cls)와 /clearall (혹은 /clsall)을 추가합니다.",
	["Clears the current chat frame"] = "현재 대화창을 클리어 합니다.",
	['Clears all chat frames'] = "모든 대화창을 클리어 합니다.",
} end)

-- get prat module categories
local cat = Prat.Categories

-- create prat module
Prat_Clear = Prat:NewModule(PRAT_MODULE)
Prat_Clear.revision = tonumber(string.sub("$Revision:  24999 $", 12, -3))

-- define key module values
Prat_Clear.moduleName = L["Clear"]
Prat_Clear.moduleDesc = L["Adds /clear (or /cls) and /clearall (or /clsall) commands for clearing chat frames"]
Prat_Clear.consoleName = string.lower(Prat_Clear.moduleName)
Prat_Clear.guiName = Prat_Clear.moduleName
-- list here: http://groups-beta.google.com/group/wow-prat/web/prat-categories
Prat_Clear.Categories = { cat.FRAME, cat.BEHAVIOR }


-- define the default db values
Prat_Clear.defaultDB = {
	on = false,
	}

-- build the options menu using prat templates
Prat_Clear.toggleOptions = { }

--[[------------------------------------------------
	Module Event Functions
------------------------------------------------]]--

-- things to do when the module is enabled
function Prat_Clear:OnModuleEnable()
	local slashcmds, cmdopts

	-- clear
	cmdopts_clear = {
		name	= L['Clear'],
		desc	= L['Clears the current chat frame'],
		type	= "execute",
		func	= function() Prat_Clear:clear(SELECTED_CHAT_FRAME) end,
		}

	-- cleartastic
	cmdopts_clearall = {
		name	= L['Clearall'],
		desc	= L['Clears all chat frames'],
		type	= 'execute',
		func	= function() Prat_Clear:clearAll() end,
		}

	Prat:RegisterChatCommand({ '/clear', '/cls' }, cmdopts_clear, 'PRATCLEAR')
	Prat:RegisterChatCommand({ '/clearall', '/clsall' }, cmdopts_clearall, 'PRATCLEARALL')
end

-- things to do when the module is disabled
function Prat_Clear:OnModuleDisable()
	-- unregister events
	self:UnregisterAllEvents()
end

--[[ - - ------------------------------------------------
	Core Functions

	NananananananananaPRATMAN

	Holy smokes Pratman, it's COREFUNCTIONELLA!

	* kAPOooOWeeE! *

	* BAM! *
--------------------------------------------- - ]]--


function Prat_Clear:clear(chatframe)
	local vartype = type(chatframe)
	local type = chatframe:GetFrameType() or nil

	if self.db.profile.on and type == 'ScrollingMessageFrame' then
		chatframe:Clear()
	end
end

function Prat_Clear:clearAll()
	for i = 1, NUM_CHAT_WINDOWS do
		self:clear(getglobal('ChatFrame' .. i))
	end
end
