diff options
-rw-r--r-- | dalos.lua | 53 |
1 files changed, 51 insertions, 2 deletions
@@ -459,6 +459,11 @@ dalosp.menu = { for k, v in ipairs(data.objects) do if not tlup[v.ntype] then error("Object " .. v.ntype .. " isn't declared") end end + if data.imports then + for i, v in ipairs(data.imports) do + dalosp.menu.load_file(v) + end + end dalos:clean() for k, v in ipairs(data.objects) do local tab = { x = v.x, y = v.y, name = v.name } @@ -474,6 +479,13 @@ dalosp.menu = { if not lup[v.dst] then error("Can't find object for id dst " .. v.dst) end d:createlink(lup[v.src], lup[v.dst], v.isrc, v.idst) end + if data.cross then + dalosp.cross = {} + if data.cross.north then dalosp.cross.north = tlup[data.cross.north] end + if data.cross.south then dalosp.cross.south = tlup[data.cross.south] end + if data.cross.west then dalosp.cross.west = tlup[data.cross.west] end + if data.cross.east then dalosp.cross.east = tlup[data.cross.east] end + end end, action_save = function(self) @@ -496,7 +508,12 @@ dalosp.menu = { for i, v in ipairs(s_obj) do v.lookup = nil end - local save = { objects = s_obj, links = s_links } + local s_cross = { } + if dalosp.cross.north then s_cross.north = dalosp.cross.north.name end + if dalosp.cross.sorth then s_cross.sorth = dalosp.cross.sorth.name end + if dalosp.cross.west then s_cross.west = dalosp.cross.west.name end + if dalosp.cross.east then s_cross.east = dalosp.cross.east.name end + local save = { objects = s_obj, links = s_links, cross = s_cross, imports = dalosp.imports } local dlg = iup.filedlg { dialogtype = "Save", } @@ -513,6 +530,34 @@ dalosp.menu = { end end, + load_file = function (file) + local s, v = pcall(load, file) + if not s then return end + if not dalosp.imports then dalosp.imports = {} end + for i, v in ipairs(dalosp.imports) do + if v == file then return end + end + table.insert(dalosp.imports, file) + end, + + action_import = function (self) + local dlg = iup.filedlg { + dialogtype = "Open", + } + iup.Popup(dlg) + if dlg.status == -1 then return end + + dalosp.menu.load_file(dlg.value) + end, + + action_reload = function (self) + if not dalosp.imports then return end + + for i, v in ipairs(dalosp.imports) do + pcall(load, v) + end + end, + action_exit = function (self) return iup.CLOSE end, @@ -559,6 +604,10 @@ dalosp.menu = { item_load.action = dalosp.menu.action_load local item_save = iup.item { title = "Save" } item_save.action = dalosp.menu.action_save + local item_import = iup.item { title = "Import" } + item_import.action = dalosp.menu.action_import + local item_reload = iup.item { title = "Reload all" } + item_reload.action = dalosp.menu.action_reload local item_exit = iup.item { title = "Exit" } item_exit.action = dalosp.menu.action_exit local item_about = iup.item { title = "About" } @@ -586,7 +635,7 @@ dalosp.menu = { item.action = function (self) dalosp.menu.set_cross(canvas, v, dalosp.SOUTH) end table.insert(south_menu, item) end - local menu_file = iup.submenu { iup.menu { item_load, item_save, iup.separator {}, item_exit }, title = "File" } + local menu_file = iup.submenu { iup.menu { item_load, item_save, iup.separator {}, item_import, item_reload, iup.separator {}, item_exit }, title = "File" } local menu_add = iup.submenu { iup.menu(add_menu), title = "Add" } local menu_cross = iup.submenu { iup.menu { iup.submenu { iup.menu(north_menu), title = "North" }, |