opus/sys/apps/System.lua

83 lines
1.9 KiB
Lua
Raw Permalink Normal View History

local UI = require('opus.ui')
local Util = require('opus.util')
2018-12-23 03:11:16 +00:00
local fs = _G.fs
local shell = _ENV.shell
2017-10-08 21:45:01 +00:00
2016-12-11 19:24:52 +00:00
UI:configure('System', ...)
2020-04-27 01:39:58 +00:00
local function loadDirectory(dir)
local plugins = { }
for _, file in pairs(fs.list(dir)) do
local s, m = Util.run(_ENV, fs.combine(dir, file))
if not s and m then
_G.printError('Error loading: ' .. file)
error(m or 'Unknown error')
elseif s and m then
table.insert(plugins, { tab = m, name = m.title, description = m.description })
end
end
return plugins
end
local programDir = fs.getDir(_ENV.arg[0])
2020-04-27 01:39:58 +00:00
local plugins = loadDirectory(fs.combine(programDir, 'system'), { })
local page = UI.Page {
2018-01-24 22:39:38 +00:00
tabs = UI.Tabs {
2019-01-30 20:11:41 +00:00
settings = UI.Tab {
2020-04-27 01:39:58 +00:00
title = 'Category',
2019-03-22 05:40:29 +00:00
grid = UI.ScrollingGrid {
x = 2, y = 2, ex = -2, ey = -2,
2018-01-24 22:39:38 +00:00
columns = {
2018-12-23 03:11:16 +00:00
{ heading = 'Name', key = 'name' },
{ heading = 'Description', key = 'description' },
2018-01-24 22:39:38 +00:00
},
2018-12-23 03:11:16 +00:00
sortColumn = 'name',
autospace = true,
2020-04-27 01:39:58 +00:00
values = plugins,
2018-01-24 22:39:38 +00:00
},
2020-04-27 01:39:58 +00:00
accelerators = {
grid_select = 'category_select',
}
2018-01-24 22:39:38 +00:00
},
},
notification = UI.Notification(),
accelerators = {
[ 'control-q' ] = 'quit',
2018-01-24 22:39:38 +00:00
},
2020-04-27 01:39:58 +00:00
eventHandler = function(self, event)
if event.type == 'quit' then
UI:quit()
2016-12-11 19:24:52 +00:00
2020-04-27 01:39:58 +00:00
elseif event.type == 'category_select' then
local tab = event.selected.tab
2016-12-11 19:24:52 +00:00
2020-04-27 01:39:58 +00:00
if not self.tabs[tab.title] then
self.tabs:add({ [ tab.title ] = tab })
end
self.tabs:selectTab(tab)
return true
2016-12-11 19:24:52 +00:00
2020-04-27 01:39:58 +00:00
elseif event.type == 'success_message' then
self.notification:success(event.message)
2017-10-11 15:37:52 +00:00
2020-04-27 01:39:58 +00:00
elseif event.type == 'info_message' then
self.notification:info(event.message)
2017-10-11 15:37:52 +00:00
2020-04-27 01:39:58 +00:00
elseif event.type == 'error_message' then
self.notification:error(event.message)
2016-12-11 19:24:52 +00:00
2020-04-27 01:39:58 +00:00
elseif event.type == 'tab_activate' then
event.activated:focusFirst()
2018-12-23 03:11:16 +00:00
2020-04-27 01:39:58 +00:00
else
return UI.Page.eventHandler(self, event)
2018-12-23 03:11:16 +00:00
end
2020-04-27 01:39:58 +00:00
return true
end,
}
2018-12-23 03:11:16 +00:00
2020-04-27 01:39:58 +00:00
UI:setPage(page)
UI:start()