1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-15 05:04:50 +00:00
opus/sys/apps/System.lua

86 lines
1.9 KiB
Lua
Raw 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', ...)
2016-12-14 18:54:13 +00:00
local systemPage = UI.Page {
2018-01-24 22:39:38 +00:00
tabs = UI.Tabs {
2019-01-30 20:11:41 +00:00
settings = UI.Tab {
2018-12-23 03:11:16 +00:00
tabTitle = 'Category',
2019-03-22 05:40:29 +00:00
grid = UI.ScrollingGrid {
2018-12-23 03:11:16 +00:00
y = 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,
2018-01-24 22:39:38 +00:00
},
},
},
notification = UI.Notification(),
accelerators = {
[ 'control-q' ] = 'quit',
2018-01-24 22:39:38 +00:00
},
2016-12-14 18:54:13 +00:00
}
2016-12-11 19:24:52 +00:00
2018-12-23 03:11:16 +00:00
function systemPage.tabs.settings:eventHandler(event)
if event.type == 'grid_select' then
local tab = event.selected.tab
if not systemPage.tabs[tab.tabTitle] then
systemPage.tabs:add({ [ tab.tabTitle ] = tab })
tab:disable()
2018-01-24 22:39:38 +00:00
end
2018-12-23 03:11:16 +00:00
systemPage.tabs:selectTab(tab)
self.parent:draw()
2018-01-24 22:39:38 +00:00
return true
end
2016-12-11 19:24:52 +00:00
end
2018-12-23 03:11:16 +00:00
function systemPage:eventHandler(event)
if event.type == 'quit' then
UI:exitPullEvents()
2016-12-11 19:24:52 +00:00
2018-12-23 03:11:16 +00:00
elseif event.type == 'success_message' then
self.notification:success(event.message)
2017-10-11 15:37:52 +00:00
2018-12-23 03:11:16 +00:00
elseif event.type == 'info_message' then
self.notification:info(event.message)
2017-10-11 15:37:52 +00:00
2018-12-23 03:11:16 +00:00
elseif event.type == 'error_message' then
self.notification:error(event.message)
2016-12-11 19:24:52 +00:00
2018-01-24 22:39:38 +00:00
elseif event.type == 'tab_activate' then
event.activated:focusFirst()
2018-12-23 03:11:16 +00:00
2018-01-24 22:39:38 +00:00
else
return UI.Page.eventHandler(self, event)
end
return true
2016-12-11 19:24:52 +00:00
end
2018-12-23 03:11:16 +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.tabTitle, description = m.description })
end
end
return plugins
end
local programDir = fs.getDir(shell.getRunningProgram())
local plugins = loadDirectory(fs.combine(programDir, 'system'), { })
systemPage.tabs.settings.grid:setValues(plugins)
2016-12-11 19:24:52 +00:00
UI:setPage(systemPage)
2017-10-08 21:45:01 +00:00
UI:pullEvents()