77 lines
1.8 KiB
Lua
77 lines
1.8 KiB
Lua
gluesteak.include("gmodWiki.lua")
|
|
|
|
|
|
local CodeEditor = {
|
|
setFill = function(self, b)
|
|
if (b) then
|
|
self:Dock(FILL)
|
|
end
|
|
end,
|
|
|
|
setText = function(self, text)
|
|
self.html:RunJavascript("SetContent(" .. "'" .. text .. "')")
|
|
end,
|
|
|
|
createButton = function(self)
|
|
|
|
self.runLuaBtn = vgui.Create("DButton", self.right)
|
|
self.runLuaBtn:Dock(BOTTOM)
|
|
self.runLuaBtn:SetTall(self.runLuaBtn:GetTall() * 1.5)
|
|
self.runLuaBtn:SetText("Run lua")
|
|
self.runLuaBtn.DoClick = function()
|
|
|
|
if (not self.currentCode) then
|
|
print("[Warning] Nothing inside code editor")
|
|
return
|
|
end
|
|
RunString(self.currentCode)
|
|
end
|
|
self.runLuaBtn:SetTextColor(Color(255,255,255))
|
|
self.runLuaBtn.Paint = function(self, w, h)
|
|
draw.RoundedBox(0, 0, 0, w, h, Color(57, 58, 49))
|
|
end
|
|
|
|
end,
|
|
|
|
showButton = function(self, b)
|
|
self.shouldHaveButton = b
|
|
end,
|
|
|
|
Init = function(self)
|
|
self.shouldHaveButton = true
|
|
self:SetSize(250, 250)
|
|
|
|
-- self:SetPos(20, 30)
|
|
|
|
|
|
self.right = vgui.Create("PANEL", self)
|
|
self.right:Dock(FILL)
|
|
|
|
self.html = vgui.Create("DHTML", self.right)
|
|
self.html:Dock(FILL)
|
|
self.html:SetAllowLua(true)
|
|
self.html:OpenURL("asset://garrysmod/lua/menu_plugins/luaviewer/index.html") --thx metastruct
|
|
self.html:AddFunction("gmodinterface", "OnCode", function(code)
|
|
self.currentCode = code
|
|
end)
|
|
|
|
-- self.html:RunJavascript("SetContent(" .. "'" .. content .. "')")
|
|
|
|
|
|
|
|
self.html:AddFunction("gmodinterface", "DoLog", function(logstr) print("Log\t=\t", logstr) end)
|
|
timer.Simple(0.1, function()
|
|
if (self.shouldHaveButton) then
|
|
self:createButton()
|
|
else
|
|
self.html:RunJavascript([[SetFontSize(10)]])
|
|
end
|
|
end)
|
|
end
|
|
|
|
}
|
|
vgui.Register("CodeEditor", CodeEditor, "DPanel")
|
|
|
|
-- editor = vgui.Create("CodeEditor")
|
|
-- editor:setFill(false)
|
|
-- editor:showButton(true) |