+  HandyCache форум
|-+  Главная категория» English forum» GUI for extension exceptions
Имя пользователя:
Пароль:
Страниц: [1]   Вниз
  Отправить эту тему    Печать  
Автор Тема: GUI for extension exceptions  (Прочитано 5794 раз)
0 Пользователей и 1 Гость смотрят эту тему.
www
Новичок
*

Репутация: +5/-0
Offline Offline

Сообщений: 39


« : 03 июня 2011, 05:32:36 »

Is there any simple example of GUI for just extension exceptions? All of the default extensions seem to have complex codes.
Сообщить модератору   Записан
mai62
Автор HC
*****

Репутация: +226/-4
Offline Offline

Сообщений: 6383


« Ответ #1 : 03 июня 2011, 16:10:02 »

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
« Последнее редактирование: 03 июня 2011, 16:15:17 от mai62 » Сообщить модератору   Записан
www
Новичок
*

Репутация: +5/-0
Offline Offline

Сообщений: 39


« Ответ #2 : 03 июня 2011, 22:51:51 »

Thank you! That's exactly what I wanted.  Веселый
Сообщить модератору   Записан
Страниц: [1]   Вверх
  Отправить эту тему    Печать  

 
Перейти в: