CapsAdmin

Untitled

May 16th, 2011
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. local PANEL = vgui.Register("lua_editor", {}, "Panel")
  2.  
  3. function PANEL:Init()
  4.     self.Error = vgui.Create( "DLabel", self )     
  5.     self.Error:SetTextColor( Color( 255, 0, 0, 255 ) )
  6.     self.Error:SetFont("UIBold")
  7.     self.Error:Dock( BOTTOM )
  8.     self.Error:SetVisible( false )
  9.  
  10.     self.HTML = vgui.Create( "HTML", self )
  11.     self.HTML:SetURL("http://matt-zone.com/leditor/")
  12.     self.HTML:Dock( FILL )
  13.     self.HTML:SetVerticalScrollbarEnabled( true )
  14.     self.Content = ""
  15.     self:SetCode("Asjidjaisd")
  16.  
  17.     self.HTML.PageTitleChanged = function(HTML, title)
  18.         print(title)
  19.         if title and title ~= "" then
  20.             local decoded = ""
  21.  
  22.             local i = 1
  23.  
  24.             while i < #title do
  25.                 decoded = decoded .. string.char(tonumber(title:sub(i,i+1), 16))
  26.                 i = i + 2
  27.             end
  28.            
  29.             if self.Content != decoded then
  30.                 self.Content = decoded
  31.                 self:OnCodeChanged(decoded)
  32.                                
  33.                 local var = CompileString(decoded, "lua_editor", false)
  34.                 if type(var) == "string" then
  35.                     self:SetError(var)
  36.                 else
  37.                     self:SetError(false)
  38.                 end
  39.             end
  40.         end
  41.     end
  42. end
  43.  
  44. function PANEL:OnCodeChanged(code)
  45.  
  46. end
  47.  
  48. function PANEL:GetCode()
  49.     return self.Content
  50. end
  51.  
  52. function PANEL:SetCode(content)
  53.     local encoded = ""
  54.    
  55.     for i=1, #content do
  56.         encoded = encoded .. ("%02X"):format(content[i]:byte())
  57.     end
  58.    
  59.     self.Content = content            
  60.     self.HTML:RunJavascript("SetContent(\"" .. encoded .. "\")")
  61. end
  62.  
  63. function PANEL:SetError( err )
  64.     if err then
  65.         if not self.Error:IsVisible() then
  66.             self.Error:SetVisible( true )
  67.             self:InvalidateLayout()
  68.         end
  69.        
  70.         self.Error:SetText( err )
  71.         self.Error:SizeToContents()
  72.     else
  73.         if self.Error:IsVisible() then
  74.             self.Error:SetVisible( false )
  75.             self:InvalidateLayout()
  76.         end
  77.     end
  78. end
  79.  
  80. print("uhoh")
Advertisement
Add Comment
Please, Sign In to add comment