1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-14 20:54:50 +00:00
opus/sys/apps/inspect.lua

150 lines
3.5 KiB
Lua
Raw Normal View History

2019-11-13 06:04:31 +00:00
local UI = require('opus.ui')
2019-11-13 04:13:17 +00:00
local colors = _G.colors
local multishell = _ENV.multishell
2019-11-13 06:04:31 +00:00
local name = ({ ... })[1] or error('Syntax: inspect COMPONENT')
2019-11-13 04:13:17 +00:00
local events = { }
local page
local function isRelevant(el)
return page.testContainer == el or el.parent and isRelevant(el.parent)
end
local emitter = UI.Window.emit
function UI.Window:emit(event)
if not event._recorded and isRelevant(self) then
2019-11-13 04:13:17 +00:00
local t = { }
for k,v in pairs(event) do
if k ~= 'type' and k ~= 'recorded' then
table.insert(t, k .. ':' .. (type(v) == 'table' and (v.UIElement and v.uid or 'tbl') or tostring(v)))
end
end
table.insert(events, 1, { type = event.type, value = table.concat(t, ' '), raw = event })
while #events > 10 do
table.remove(events)
end
2019-11-13 06:04:31 +00:00
page.tabs.events.grid:update()
if page.tabs.events.enabled then
page.tabs.events.grid:draw()
end
2019-11-13 04:13:17 +00:00
end
event._recorded = true
2019-11-13 04:13:17 +00:00
return emitter(self, event)
end
-- do not load component until emit hook is in place
local component = UI[name] and UI[name]() or error('Invalid component')
if not component.example then
error('No example present')
end
2019-11-13 04:13:17 +00:00
page = UI.Page {
testContainer = UI.Window {
ey = 10,
2019-11-13 06:04:31 +00:00
testing = component.example(),
2019-11-13 04:13:17 +00:00
},
tabs = UI.Tabs {
y = 11,
properties = UI.Tab {
tabTitle = 'Properties',
grid = UI.ScrollingGrid {
headerBackgroundColor = colors.red,
sortColumn = 'key',
columns = {
{ heading = 'key', key = 'key' },
{ heading = 'value', key = 'value', }
},
accelerators = {
grid_select = 'edit_property',
},
},
},
methodsTab = UI.Tab {
tabTitle = 'Methods',
grid = UI.ScrollingGrid {
headerBackgroundColor = colors.red,
sortColumn = 'key',
columns = {
{ heading = 'key', key = 'key' },
},
},
},
events = UI.Tab {
tabTitle = 'Events',
grid = UI.ScrollingGrid {
headerBackgroundColor = colors.red,
values = events,
autospace = true,
columns = {
{ heading = 'type', key = 'type' },
{ heading = 'value', key = 'value', }
},
}
}
},
editor = UI.SlideOut {
y = -4, height = 4,
backgroundColor = colors.green,
titleBar = UI.TitleBar {
event = 'editor_cancel',
title = 'Enter value',
},
entry = UI.TextEntry {
y = 3, x = 2, ex = 10,
accelerators = {
enter = 'editor_apply',
},
},
},
eventHandler = function (self, event)
if event.type == 'focus_change' and isRelevant(event.focused) then
local t = { }
for k,v in pairs(event.focused) do
table.insert(t, {
key = k,
value = tostring(v),
})
end
self.tabs.properties.grid:setValues(t)
self.tabs.properties.grid:update()
self.tabs.properties.grid:draw()
t = { }
for k,v in pairs(getmetatable(event.focused)) do
if type(v) == 'function' then
table.insert(t, {
key = k,
})
end
end
self.tabs.methodsTab.grid:setValues(t)
self.tabs.methodsTab.grid:update()
self.tabs.methodsTab.grid:draw()
elseif event.type == 'grid_select' and event.element == self.tabs.events.grid then
event.selected.raw._recorded = nil
2019-11-13 04:13:17 +00:00
multishell.openTab({
path = 'sys/apps/Lua.lua',
args = { event.selected.raw },
focused = true,
})
elseif event.type == 'grid_select' and event.element == self.tabs.properties.grid then
self.editor.entry.value = event.selected.value
self.editor:show()
elseif event.type == 'editor_cancel' then
self.editor:hide()
elseif event.type == 'editor_apply' then
self.editor:hide()
end
return UI.Page.eventHandler(self, event)
end
}
UI:setPage(page)
UI:pullEvents()