Overview update

This commit is contained in:
kepler155c@gmail.com 2019-01-28 17:54:00 -05:00
parent dddb2a6b97
commit 02629e266b
4 changed files with 131 additions and 317 deletions

View File

@ -583,11 +583,11 @@ function UI.Window:sync()
end
end
function UI.Window:enable()
function UI.Window:enable(...)
self.enabled = true
if self.children then
for _,child in pairs(self.children) do
child:enable()
child:enable(...)
end
end
end
@ -607,10 +607,12 @@ function UI.Window:setTextScale(textScale)
end
function UI.Window:clear(bg, fg)
if self.canvas then
self.canvas:clear(bg or self.backgroundColor, fg or self.textColor)
else
self:clearArea(1 + self.offx, 1 + self.offy, self.width, self.height, bg)
if self.enabled then
if self.canvas then
self.canvas:clear(bg or self.backgroundColor, fg or self.textColor)
else
self:clearArea(1 + self.offx, 1 + self.offy, self.width, self.height, bg)
end
end
end
@ -628,16 +630,18 @@ function UI.Window:clearArea(x, y, width, height, bg)
end
function UI.Window:write(x, y, text, bg, tc)
bg = bg or self.backgroundColor
tc = tc or self.textColor
x = x - self.offx
y = y - self.offy
if y <= self.height and y > 0 then
if self.canvas then
self.canvas:write(x, y, text, bg, tc)
else
self.parent:write(
self.x + x - 1, self.y + y - 1, tostring(text), bg, tc)
if self.enabled then
bg = bg or self.backgroundColor
tc = tc or self.textColor
x = x - self.offx
y = y - self.offy
if y <= self.height and y > 0 then
if self.canvas then
self.canvas:write(x, y, text, bg, tc)
else
self.parent:write(
self.x + x - 1, self.y + y - 1, tostring(text), bg, tc)
end
end
end
end
@ -2056,6 +2060,7 @@ function UI.MenuBar:eventHandler(event)
if event.type == 'button_press' and event.button.dropmenu then
if event.button.dropmenu.enabled then
event.button.dropmenu:hide()
self:refocus()
return true
else
local x, y = getPosition(event.button)
@ -2123,7 +2128,6 @@ function UI.DropMenu:setParent()
end
function UI.DropMenu:enable()
self.enabled = false
end
function UI.DropMenu:show(x, y)
@ -2131,10 +2135,7 @@ function UI.DropMenu:show(x, y)
self.canvas:move(x, y)
self.canvas:setVisible(true)
self.enabled = true
for _,child in pairs(self.children) do
child:enable()
end
UI.Window.enable(self)
self:draw()
self:capture(self)
@ -2442,16 +2443,12 @@ function UI.SlideOut:setParent()
end
function UI.SlideOut:enable()
self.enabled = false
end
function UI.SlideOut:show(...)
self:addTransition('expandUp')
self.canvas:setVisible(true)
self.enabled = true
for _,child in pairs(self.children) do
child:enable(...)
end
UI.Window.enable(self, ...)
self:draw()
self:capture(self)
self:focusFirst()
@ -2459,12 +2456,7 @@ end
function UI.SlideOut:disable()
self.canvas:setVisible(false)
self.enabled = false
if self.children then
for _,child in pairs(self.children) do
child:disable()
end
end
UI.Window.disable(self)
end
function UI.SlideOut:hide()
@ -2553,7 +2545,6 @@ function UI.Notification:draw()
end
function UI.Notification:enable()
self.enabled = false
end
function UI.Notification:error(value, timeout)

View File

@ -1,145 +0,0 @@
local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local fs = _G.fs
return function(args)
local columns = {
{ heading = 'Name', key = 'name' },
}
if UI.term.width > 28 then
table.insert(columns,
{ heading = 'Size', key = 'size', width = 5 }
)
end
args = args or { }
local selectFile = UI.Dialog {
x = args.x or 3,
y = args.y or 2,
z = args.z or 2,
-- rex = args.rex or -3,
-- rey = args.rey or -3,
height = args.height,
width = args.width,
title = 'Select File',
grid = UI.ScrollingGrid {
x = 2,
y = 2,
ex = -2,
ey = -4,
path = '',
sortColumn = 'name',
columns = columns,
},
path = UI.TextEntry {
x = 2,
y = -2,
ex = -11,
limit = 256,
accelerators = {
enter = 'path_enter',
}
},
cancel = UI.Button {
text = 'Cancel',
x = -9,
y = -2,
event = 'cancel',
},
}
function selectFile:enable(path, fn)
self:setPath(path)
self.fn = fn
UI.Dialog.enable(self)
end
function selectFile:setPath(path)
self.grid.dir = path
while not fs.isDir(self.grid.dir) do
self.grid.dir = fs.getDir(self.grid.dir)
end
self.path.value = self.grid.dir
end
function selectFile.grid:draw()
local files = fs.listEx(self.dir)
if #self.dir > 0 then
table.insert(files, {
name = '..',
isDir = true,
})
end
self:setValues(files)
self:setIndex(1)
UI.Grid.draw(self)
end
function selectFile.grid:getDisplayValues(row)
if row.size then
row = Util.shallowCopy(row)
row.size = Util.toBytes(row.size)
end
return row
end
function selectFile.grid:getRowTextColor(file)
if file.isDir then
return colors.cyan
end
if file.isReadOnly then
return colors.pink
end
return colors.white
end
function selectFile.grid:sortCompare(a, b)
if self.sortColumn == 'size' then
return a.size < b.size
end
if a.isDir == b.isDir then
return a.name:lower() < b.name:lower()
end
return a.isDir
end
function selectFile:eventHandler(event)
if event.type == 'grid_select' then
self.grid.dir = fs.combine(self.grid.dir, event.selected.name)
self.path.value = self.grid.dir
if event.selected.isDir then
self.grid:draw()
self.path:draw()
else
UI:setPreviousPage()
self.fn(self.path.value)
end
elseif event.type == 'path_enter' then
if fs.isDir(self.path.value) then
self:setPath(self.path.value)
self.grid:draw()
self.path:draw()
else
UI:setPreviousPage()
self.fn(self.path.value)
end
elseif event.type == 'cancel' then
UI:setPreviousPage()
self.fn()
else
return UI.Dialog.eventHandler(self, event)
end
return true
end
return selectFile
end

View File

@ -19,7 +19,6 @@ local gridColumns = {
{ heading = 'Status', key = 'status' },
}
local trusted = Util.readTable('usr/.known_hosts')
local config = Config.load('network', { })
if UI.term.width >= 30 then
@ -36,20 +35,16 @@ local page = UI.Page {
UI.MenuBar.spacer,
{ text = 'Reboot r', event = 'reboot' },
} },
--{ text = 'Chat', event = 'chat' },
{ text = 'Trust', dropdown = {
{ text = 'Establish', event = 'trust' },
-- { text = 'Remove', event = 'untrust' },
} },
{ text = 'Help', event = 'help', noCheck = true },
{
text = '\187',
x = -3,
dropdown = {
{ text = 'Ports', event = 'ports', noCheck = true },
-- { text = 'Show all', event = 'show_all', noCheck = true },
-- UI.MenuBar.spacer,
-- { text = 'Show trusted', event = 'show_trusted', noCheck = true },
{ text = 'Port Status', event = 'ports', modem = true },
UI.MenuBar.spacer,
{ text = 'Help', event = 'help', noCheck = true },
},
},
},
@ -117,25 +112,30 @@ function page.ports.grid:update()
local connections = { }
for i = 0, 65535 do
if device.wireless_modem.isOpen(i) then
local conn = {
port = i
}
local socket = findConnection(i)
if socket then
conn.state = 'CONNECTED'
local host = socket.dhost
if network[host] then
host = network[host].label
pcall(function() -- guard against modem removal
if device.wireless_modem then
for i = 0, 65535 do
if device.wireless_modem.isOpen(i) then
local conn = {
port = i
}
local socket = findConnection(i)
if socket then
conn.state = 'CONNECTED'
local host = socket.dhost
if network[host] then
host = network[host].label
end
conn.connection = host .. ':' .. socket.dport
else
conn.state = 'LISTEN'
end
table.insert(connections, conn)
end
conn.connection = host .. ':' .. socket.dport
else
conn.state = 'LISTEN'
end
table.insert(connections, conn)
end
end
end)
self.values = connections
UI.Grid.update(self)
end
@ -173,18 +173,6 @@ function page:eventHandler(event)
elseif event.type == 'trust' then
shell.openForegroundTab('trust ' .. t.id)
elseif event.type == 'untrust' then
local trustList = Util.readTable('usr/.known_hosts') or { }
trustList[t.id] = nil
Util.writeTable('usr/.known_hosts', trustList)
elseif event.type == 'chat' then
multishell.openTab({
path = 'sys/apps/shell',
args = { 'chat join opusChat-' .. t.id .. ' guest-' .. os.getComputerID() },
title = 'Chatroom',
focused = true,
})
elseif event.type == 'reboot' then
sendCommand(t.id, 'reboot')
@ -228,11 +216,6 @@ This only needs to be done once.
Event.off(self.portsHandler)
self.ports:hide()
elseif event.type == 'show_all' then
config.showTrusted = false
self.grid:setValues(network)
Config.update('network', config)
elseif event.type == 'show_trusted' then
config.showTrusted = true
Config.update('network', config)
@ -245,16 +228,15 @@ end
function page.menuBar:getActive(menuItem)
local t = page.grid:getSelected()
if menuItem.event == 'untrust' then
local trustList = Util.readTable('usr/.known_hosts') or { }
return t and trustList[t.id]
if menuItem.modem then
return not not device.wireless_modem
end
return menuItem.noCheck or not not t
end
function page.grid:getRowTextColor(row, selected)
if not row.active then
return colors.orange
return colors.lightGray
end
return UI.Grid.getRowTextColor(self, row, selected)
end
@ -278,17 +260,7 @@ function page.grid:getDisplayValues(row)
end
Event.onInterval(1, function()
local t = { }
if config.showTrusted then
for k,v in pairs(network) do
if trusted[k] then
t[k] = v
end
end
page.grid:setValues(t)
else
page.grid:update()
end
page.grid:update()
page.grid:draw()
page:sync()
end)

View File

@ -3,7 +3,6 @@ _G.requireInjector(_ENV)
local class = require('class')
local Config = require('config')
local Event = require('event')
local FileUI = require('ui.fileui')
local NFT = require('nft')
local Packages = require('packages')
local SHA1 = require('sha1')
@ -13,6 +12,7 @@ local Util = require('util')
local colors = _G.colors
local fs = _G.fs
local os = _G.os
local pocket = _G.pocket
local shell = _ENV.shell
local term = _G.term
@ -75,7 +75,7 @@ function UI.VerticalTabBar:setParent()
self.x = 1
self.width = 8
self.height = nil
self.ey = -1
self.ey = -2
UI.TabBar.setParent(self)
for k,c in pairs(self.children) do
c.x = 1
@ -88,17 +88,60 @@ end
local cx = 9
local cy = 1
if sx < 30 then
UI.VerticalTabBar = UI.TabBar
cx = 1
cy = 2
end
local page = UI.Page {
container = UI.Viewport {
x = cx,
y = cy,
},
tray = UI.Window {
y = -1, width = 8,
backgroundColor = colors.lightGray,
newApp = UI.Button {
text = '+', event = 'new',
},
volume = UI.Button {
x = 3,
text = '\15', event = 'volume',
}
},
editor = UI.SlideOut {
backgroundColor = colors.cyan,
titleBar = UI.TitleBar {
title = 'Edit Application',
event = 'slide_hide',
},
form = UI.Form {
y = 2, ey = -2,
[1] = UI.TextEntry {
formLabel = 'Title', formKey = 'title', limit = 11, help = 'Application title',
required = true,
},
[2] = UI.TextEntry {
formLabel = 'Run', formKey = 'run', limit = 100, help = 'Full path to application',
required = true,
},
[3] = UI.TextEntry {
formLabel = 'Category', formKey = 'category', limit = 11, help = 'Category of application',
required = true,
},
iconFile = UI.TextEntry {
x = 11, ex = -12, y = 7,
limit = 128, help = 'Path to icon file',
shadowText = 'Path to icon file',
},
loadIcon = UI.Button {
x = 11, y = 9,
text = 'Load', event = 'loadIcon', help = 'Load icon file',
},
image = UI.NftImage {
backgroundColor = colors.black,
y = 7, x = 2, height = 3, width = 8,
},
},
notification = UI.Notification(),
statusBar = UI.StatusBar(),
},
notification = UI.Notification(),
accelerators = {
r = 'refresh',
@ -172,7 +215,6 @@ local function loadApplications()
end
table.sort(buttons, function(a, b) return a.text < b.text end)
table.insert(buttons, 1, { text = 'Recent' })
table.insert(buttons, { text = '+', event = 'new' })
Util.removeByValue(page.children, page.tabBar)
@ -421,12 +463,12 @@ function page:eventHandler(event)
if config.currentCategory ~= 'Recent' then
category = config.currentCategory or 'Apps'
end
UI:setPage('editor', { category = category })
self.editor:show({ category = category })
elseif event.type == 'edit' then
local focused = page:getFocused()
if focused.app then
UI:setPage('editor', focused.app)
self.editor:show(focused.app)
end
else
@ -435,40 +477,7 @@ function page:eventHandler(event)
return true
end
local formWidth = math.max(UI.term.width - 8, 26)
local editor = UI.Dialog {
height = 11,
width = formWidth,
title = 'Edit Application',
form = UI.Form {
y = 2,
height = 9,
title = UI.TextEntry {
formLabel = 'Title', formKey = 'title', limit = 11, help = 'Application title',
required = true,
},
run = UI.TextEntry {
formLabel = 'Run', formKey = 'run', limit = 100, help = 'Full path to application',
required = true,
},
category = UI.TextEntry {
formLabel = 'Category', formKey = 'category', limit = 11, help = 'Category of application',
required = true,
},
loadIcon = UI.Button {
x = 11, y = 6,
text = 'Icon', event = 'loadIcon', help = 'Select icon'
},
image = UI.NftImage {
y = 6, x = 2, height = 3, width = 8,
},
},
statusBar = UI.StatusBar(),
iconFile = '',
}
function editor:enable(app)
function page.editor:show(app)
if app then
self.form:setValues(app)
@ -481,16 +490,16 @@ function editor:enable(app)
end
self.form.image:setImage(icon)
end
UI.Dialog.enable(self)
UI.SlideOut.show(self)
self:focusFirst()
end
function editor.form.image:draw()
function page.editor.form.image:draw()
self:clear()
UI.NftImage.draw(self)
end
function editor:updateApplications(app)
function page.editor:updateApplications(app)
if not app.key then
app.key = SHA1.sha1(app.title)
end
@ -499,51 +508,39 @@ function editor:updateApplications(app)
loadApplications()
end
function editor:eventHandler(event)
function page.editor:eventHandler(event)
if event.type == 'form_cancel' or event.type == 'cancel' then
UI:setPreviousPage()
self:hide()
elseif event.type == 'focus_change' then
self.statusBar:setStatus(event.focused.help or '')
self.statusBar:draw()
elseif event.type == 'loadIcon' then
local fileui = FileUI({
x = self.x,
y = self.y,
z = 2,
width = self.width,
height = self.height,
})
UI:setPage(fileui, fs.getDir(self.iconFile), function(fileName)
if fileName then
self.iconFile = fileName
local s, m = pcall(function()
local iconLines = Util.readFile(fileName)
if not iconLines then
error('Must be an NFT image - 3 rows, 8 cols max')
end
local icon, m = parseIcon(iconLines)
if not icon then
error(m)
end
if extSupport then
self.form.values.iconExt = iconLines
else
self.form.values.icon = iconLines
end
self.form.image:setImage(icon)
self.form.image:draw()
end)
if not s and m then
local msg = m:gsub('.*: (.*)', '%1')
page.notification:error(msg)
end
local s, m = pcall(function()
local iconLines = Util.readFile(self.form.iconFile.value)
if not iconLines then
error('Must be an NFT image - 3 rows, 8 cols max')
end
local icon, m = parseIcon(iconLines)
if not icon then
error(m)
end
if extSupport then
self.form.values.iconExt = iconLines
else
self.form.values.icon = iconLines
end
self.form.image:setImage(icon)
self.form.image:draw()
end)
if not s and m then
local msg = m:gsub('.*: (.*)', '%1')
self.notification:error(msg)
end
elseif event.type == 'form_invalid' then
page.notification:error(event.message)
self.notification:error(event.message)
elseif event.type == 'form_complete' then
local values = self.form.values
@ -555,13 +552,12 @@ function editor:eventHandler(event)
Config.update('Overview', config)
os.queueEvent('overview_refresh')
else
return UI.Dialog.eventHandler(self, event)
return UI.SlideOut.eventHandler(self, event)
end
return true
end
UI:setPages({
editor = editor,
main = page,
})