This extension can edit self exceprions
--[[ <HCExtension>
@name GuiEx
@author mai62
@version 0.1
@description GUI example
@exception microsoft.com
@exception google.com
@event Options/options
</HCExtension> ]]
function get_exceptions_list()
local fn= hc.script_name
local ret= ''
local f = io.open(fn, 'r')
if not f then return ret end
local s
while true do
s = f:read("*line")
if not s then break end
local x= re.find(s, [[^@exception\s*(.+)]], 1)
if x then ret= ret..x..'\r\n' end
end
f:close()
return ret
end
function options()
require "vcl"
Form = VCL.Form('Form')
x,y,w,h= hc.window_pos()
Form._ = { Caption='GuiEx', width=360, height=210, BorderStyle='Fixed3D' }
Form._ = { left=x+(w-Form.width)/2, top=y+(h-Form.height)/2 }
Label1 = VCL.Label(Form, "Label1")
Label1._ = { caption='Exceptions for this extension:', WordWrap=true, top=8, left=10, height=16, width=300}
Memo1 = VCL.Memo(Form, "Memo1")
Memo1._ = { parentfont=true, top=30, left=10, width=Form.clientwidth-20, height=100, scrollbars='ssVertical', wordwrap=false}
Memo1:SetText(get_exceptions_list())
OkButton = VCL.Button(Form, "OkButton")
OkButton._ = {onclick = "onOkButtonClick", width=100, left=10, caption = "OK", top= Form.clientheight-OkButton.height-10}
CancelButton = VCL.Button(Form, "CancelButton")
CancelButton._ = {onclick = "onCancelButtonClick", width=100, left=120, top=OkButton.top, caption = "Cancel"}
Form:ShowModal()
Form:Free()
Form=nil
end
function save_exeptions(list)
local fn= hc.script_name
local f = io.open(fn, 'rb')
if not f then return end
local sfile = f:read("*a")
f:close()
if not sfile then return end
local header= re.find(sfile, "^--\\[\\[\\s<HCExtension>\r\n(.+)</HCExtension> \\]\\]\r\n", 1)
header= re.replace(header, "(?-s)(@exception.*\r\n)", "", true)
header= re.replace(header, "(.+)(@event.*$)", "\\1"..list.."\\2")
header= "--[[ <HCExtension>\r\n"..header.."</HCExtension> ]]\r\n"
sfile= re.replace(sfile, "^--\\[\\[\\s<HCExtension>\r\n(?:.+)</HCExtension> \\]\\]\r\n(.*)", header.."\\1")
f = io.open(fn, 'wb')
if f then
f:write(sfile)
f:close()
end
end
function onOkButtonClick(Sender)
local list={}
if Memo1:Count()>0 then list= Memo1:GetText() end
local slist= ''
if #list>0 then
local i
for i=1, #list do
if list[i] then
slist= slist..'@exception '..list[i]..'\r\n'
end
end
end
Form:Close()
save_exeptions(slist)
hc.reload_extension('GuiEx')
end
function onCancelButtonClick(Sender)
Form:Close()
end