Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --AceEditor by Somepotato, if used do tell, I'm curiouz liek that.
- --v 1.0
- local fontList={}
- local PANEL={}
- local function escape(str)
- return select(1,str:gsub("[^%w _~%.%-]",function(c) local b=string.format("%X",tostring(string.byte(c))) return "%"..(#b==1 and "0"..b or b) end))
- end
- local function unescape(str)
- return str:gsub("%%(%x%x)",function(c) return string.char(tonumber("0x"..c)) end)
- end
- function PANEL:OnCallback(_,func,args)
- if(func=="OnLoad") then
- self.Loaded=true
- if(self.OnLoadSetCode) then self:SetCode(self.OnLoadSetCode) self.OnLoadSetCode=nil end
- if(self.OnLoad) then
- self:OnLoad()
- end
- elseif(func == "ReceiveCode") then
- self.code=unescape(args[1])
- if(self.OnCodeChanged) then
- self:OnCodeChanged(self.code)
- end
- end
- end
- function PANEL:Init()
- self:NewObjectCallback("glua","ReceiveCode")
- self:NewObjectCallback("glua","OnLoad")
- self:SetHTML([[<body onload='glua.OnLoad()'></body> <div id="editor" style="position:fixed;top:0;left:0;right:0;bottom:0">LOADING...</div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var editor = ace.edit("editor");editor.setTheme("ace/theme/monokai");editor.getSession().setMode("ace/mode/lua");
- function SetCode(code){
- editor.setValue(unescape(code),1)
- }
- function GetCode(){
- glua.ReceiveCode(escape(editor.getValue()));
- }
- editor.on("change",GetCode)
- function populateFontList(arr){
- var ret="";
- for(var k in arr){
- ret+=arr[k]+"\n"
- }
- editor.setValue(ret);
- }
- </script>
- ]])
- self.Loaded = false
- self:SetCode("")
- end
- function PANEL:SetCode(code)
- if not self.Loaded then
- self.OnLoadSetCode = code
- return
- end
- self.code=code
- self:RunJavascript("SetCode(\""..escape(code).."\")")
- end
- function PANEL:GetCode()
- return self.code or ""
- end
- vgui.Register("AceEditor",PANEL,"Awesomium")
Advertisement
Add Comment
Please, Sign In to add comment