public
Description: WoW Addon - Lua notepad thing
Homepage: http://www.tekkub.net/
Clone URL: git://github.com/tekkub/tekpad.git
Click here to lend your support to: tekpad and make a donation at www.pledgie.com !
tekpad / tekPad.lua
100644 97 lines (71 sloc) 2.932 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
local LINEHEIGHT, maxoffset, offset = 12, 0, 0
 
 
local panel = LibStub("tekPanel-Auction").new("tekPadPanel", "tekPad")
 
 
local scroll = CreateFrame("ScrollFrame", nil, panel)
scroll:SetPoint("TOPLEFT", 21, -73)
scroll:SetPoint("BOTTOMRIGHT", -10, 38)
local HEIGHT = scroll:GetHeight()
 
local editbox = CreateFrame("EditBox", nil, scroll)
scroll:SetScrollChild(editbox)
editbox:SetPoint("TOP")
editbox:SetPoint("LEFT")
editbox:SetPoint("RIGHT")
editbox:SetHeight(1000)
editbox:SetFontObject(GameFontHighlightSmall)
editbox:SetTextInsets(2,2,2,2)
editbox:SetMultiLine(true)
editbox:SetAutoFocus(false)
editbox:SetScript("OnEscapePressed", editbox.ClearFocus)
editbox:SetScript("OnEditFocusLost", function(self) tekPadDB = self:GetText() end)
 
 
editbox:SetScript("OnShow", function(self)
local text = tekPadDB or ""
self:SetText(text)
self:SetFocus()
end)
 
 
local function doscroll(v)
offset = math.max(math.min(v, 0), maxoffset)
scroll:SetVerticalScroll(-offset)
editbox:SetPoint("TOP", 0, offset)
end
 
 
editbox:SetScript("OnCursorChanged", function(self, x, y, width, height)
LINEHEIGHT = height
if offset < y then
doscroll(y)
elseif math.floor(offset - HEIGHT + height*2) > y then
local v = y + HEIGHT - height*2
maxoffset = math.min(maxoffset, v)
doscroll(v)
end
end)
 
 
scroll:UpdateScrollChildRect()
scroll:EnableMouseWheel(true)
scroll:SetScript("OnMouseWheel", function(self, val) doscroll(offset + val*LINEHEIGHT*3) end)
 
 
local butt = CreateFrame("Button", nil, panel)
butt:SetWidth(80) butt:SetHeight(22)
butt:SetPoint("BOTTOMRIGHT", -7, 14)
 
butt:SetHighlightFontObject(GameFontHighlightSmall)
butt:SetNormalFontObject(GameFontNormalSmall)
 
butt:SetNormalTexture("Interface\\Buttons\\UI-Panel-Button-Up")
butt:SetPushedTexture("Interface\\Buttons\\UI-Panel-Button-Down")
butt:SetHighlightTexture("Interface\\Buttons\\UI-Panel-Button-Highlight")
butt:SetDisabledTexture("Interface\\Buttons\\UI-Panel-Button-Disabled")
butt:GetNormalTexture():SetTexCoord(0, 0.625, 0, 0.6875)
butt:GetPushedTexture():SetTexCoord(0, 0.625, 0, 0.6875)
butt:GetHighlightTexture():SetTexCoord(0, 0.625, 0, 0.6875)
butt:GetDisabledTexture():SetTexCoord(0, 0.625, 0, 0.6875)
butt:GetHighlightTexture():SetBlendMode("ADD")
 
butt:SetText("Run")
butt:SetScript("OnClick", function() RunScript(editbox:GetText()) end)
 
 
-----------------------------
-- Slash Handler --
-----------------------------
 
SLASH_TEKPADSLASH1 = "/pad"
SLASH_TEKPADSLASH2 = "/tekpad"
function SlashCmdList.TEKPADSLASH() ShowUIPanel(panel) end
 
 
----------------------------------------
-- Quicklaunch registration --
----------------------------------------
 
local ldb = LibStub and LibStub:GetLibrary("LibDataBroker-1.1", true)
if ldb then
local dataobj = ldb:GetDataObjectByName("tekPad") or ldb:NewDataObject("tekPad", {type = "launcher", icon = "Interface\\Icons\\INV_Misc_Note_01"})
dataobj.OnClick = SlashCmdList.TEKPADSLASH
end