From ef0404604e36a45ea950439c2396eb0ea3b5bdf9 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 26 Dec 2009 20:15:19 +0100 Subject: Template system rework. --- dalos-luafilter.lua | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'dalos-luafilter.lua') diff --git a/dalos-luafilter.lua b/dalos-luafilter.lua index 0d83fb4..9c87f93 100644 --- a/dalos-luafilter.lua +++ b/dalos-luafilter.lua @@ -1,4 +1,6 @@ dalosp.luafilter = { + templates = {}, + default_code = [[ -- available globals: @@ -101,21 +103,26 @@ end local data, otype, tname = f() if otype ~= "Lua Filter" then error("Wrong template type: " .. otype) end - self.extra.code = data.template.code + self:apply_template(data.template) end, gen_template = function (self) return { code = self.extra.close } end, + apply_template = function (self, data) + self.extra.code = data.code + end, + configure = function (self) local okay = false local text = iup.text { multiline = "Yes", font = "Courier", expand = "Yes", value = self.extra.code } local bok = iup.button { title = "Ok", action = function () okay = true return iup.CLOSE end } local bimport = iup.button { title = "Import", action = function() self:load_template() return iup.CLOSE end } local bexport = iup.button { title = "Export", action = function() self:save_template(self:gen_template()) end } + local busetpl = iup.button { title = "Use Template", action = function() self:use_template() end } local bcancel = iup.button { title = "Cancel", action = function () okay = false return iup.CLOSE end } - local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, bimport, bexport, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" } + local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, bimport, bexport, busetpl, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" } local r = dlg:popup() -- if r ~= iup.NOERROR then return end local newcode = text.value @@ -151,13 +158,17 @@ end obj.load_code = dalosp.luafilter.load_code obj.run_in_localenv = dalosp.luafilter.run_in_localenv - obj.load_template = dalosp.luafilter.load_template obj.gen_template = dalosp.luafilter.gen_template + obj.apply_template = dalosp.luafilter.apply_template obj:load_code(extra.code) return obj end, + + register_template = function (data, tname) + dalosp.luafilters.templates[tname] = data + end, } dalos.luafilter = dalosp.luafilter.create -dalos:register_obj("Lua Filter", dalos.luafilter, "Programmable") +dalos:register_obj("Lua Filter", dalos.luafilter, "Programmable", dalosp.luafilter.register_template) -- cgit v1.2.3