diff options
Diffstat (limited to 'dalos-luafilter.lua')
-rw-r--r-- | dalos-luafilter.lua | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/dalos-luafilter.lua b/dalos-luafilter.lua index 8181442..0abf40a 100644 --- a/dalos-luafilter.lua +++ b/dalos-luafilter.lua @@ -32,11 +32,9 @@ end if not metatable then metatable = {} end local oldni, oldi = metatable.__newindex, metatable.__index metatable.__newindex = function (table, key, value) --- print("Setting _G[" .. key .. "] = " .. tostring(value)) localenv[key] = value end metatable.__index = function (table, key) --- print("Getting _G[" .. key .. "]") local l = localenv[key] if l then return localenv[key] end return rawget(_G, key) @@ -87,12 +85,32 @@ end self:run_in_localenv("input_change", ind) end, + load_template = function (self) + local dlg = iup.filedlg { + dialogtype = "Open", + filter = "*.dtpl", + } + iup.Popup(dlg) + if dlg.status == -1 then return end + + local s, v = pcall(Input, dlg.value) + if not s then error("Problem loading file " .. dlg.value) end + local f = preload(v) + if not f then error("Syntax error loading file " .. dlg.value) end + local data, otype, tname = f() + if otype ~= "Lua Filter" then error("Wrong template type: " .. otype) end + + self.extra.code = data.template.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{ code = self.extra.code } 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, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" } + 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 r = dlg:popup() -- if r ~= iup.NOERROR then return end local newcode = text.value @@ -128,6 +146,7 @@ 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:load_code(extra.code) return obj |