This commit is contained in:
kepler155c@gmail.com 2020-04-12 18:46:26 -06:00
parent 775871c548
commit 9eeec8719c
8 changed files with 191 additions and 199 deletions

View File

@ -82,12 +82,53 @@ local Browser = UI.Page {
},
sortColumn = 'name',
y = 2, ey = -2,
sortCompare = function(self, a, b)
if self.sortColumn == 'fsize' then
return a.size < b.size
elseif self.sortColumn == 'flags' then
return a.flags < b.flags
end
if a.isDir == b.isDir then
return a.name:lower() < b.name:lower()
end
return a.isDir
end,
getRowTextColor = function(_, file)
if file.marked then
return colors.green
end
if file.isDir then
return colors.cyan
end
if file.isReadOnly then
return colors.pink
end
return colors.white
end,
eventHandler = function(self, event)
if event.type == 'copy' then -- let copy be handled by parent
return false
end
return UI.ScrollingGrid.eventHandler(self, event)
end
},
statusBar = UI.StatusBar {
columns = {
{ key = 'status' },
{ key = 'totalSize', width = 6 },
},
draw = function(self)
if self.parent.dir then
local info = '#:' .. Util.size(self.parent.dir.files)
local numMarked = Util.size(marked)
if numMarked > 0 then
info = info .. ' M:' .. numMarked
end
self:setValue('info', info)
self:setValue('totalSize', formatSize(self.parent.dir.totalSize))
UI.StatusBar.draw(self)
end
end,
},
question = UI.Question {
y = -2, x = -19,
@ -181,51 +222,6 @@ function Browser.menuBar:getActive(menuItem)
return true
end
function Browser.grid:sortCompare(a, b)
if self.sortColumn == 'fsize' then
return a.size < b.size
elseif self.sortColumn == 'flags' then
return a.flags < b.flags
end
if a.isDir == b.isDir then
return a.name:lower() < b.name:lower()
end
return a.isDir
end
function Browser.grid:getRowTextColor(file)
if file.marked then
return colors.green
end
if file.isDir then
return colors.cyan
end
if file.isReadOnly then
return colors.pink
end
return colors.white
end
function Browser.grid:eventHandler(event)
if event.type == 'copy' then -- let copy be handled by parent
return false
end
return UI.ScrollingGrid.eventHandler(self, event)
end
function Browser.statusBar:draw()
if self.parent.dir then
local info = '#:' .. Util.size(self.parent.dir.files)
local numMarked = Util.size(marked)
if numMarked > 0 then
info = info .. ' M:' .. numMarked
end
self:setValue('info', info)
self:setValue('totalSize', formatSize(self.parent.dir.totalSize))
UI.StatusBar.draw(self)
end
end
function Browser:setStatus(status, ...)
self.notification:info(string.format(status, ...))
end
@ -261,7 +257,6 @@ function Browser:getDirectory(directory)
end
function Browser:updateDirectory(dir)
dir.size = 0
dir.totalSize = 0
Util.clear(dir.files)

View File

@ -4,7 +4,7 @@ local colors = _G.colors
local peripheral = _G.peripheral
local settings = _G.settings
local tab = UI.Tab {
return peripheral.find('monitor') and UI.Tab {
tabTitle = 'Kiosk',
description = 'Kiosk options',
form = UI.Form {
@ -29,9 +29,7 @@ local tab = UI.Tab {
backgroundColor = colors.black,
value = 'Settings apply to kiosk mode selected during startup'
},
}
function tab:enable()
enable = function(self)
local choices = { }
peripheral.find('monitor', function(side)
@ -44,9 +42,8 @@ function tab:enable()
self.form.textScale.value = settings.get('kiosk.textscale')
UI.Tab.enable(self)
end
function tab:eventHandler(event)
end,
eventHandler = function(self, event)
if event.type == 'choice_change' then
if self.form.monitor.value then
settings.set('kiosk.monitor', self.form.monitor.value)
@ -57,7 +54,4 @@ function tab:eventHandler(event)
settings.save('.settings')
end
end
if peripheral.find('monitor') then
return tab
end
}

View File

@ -4,7 +4,7 @@ local Util = require('opus.util')
local fs = _G.fs
local os = _G.os
local labelTab = UI.Tab {
return UI.Tab {
tabTitle = 'Label',
description = 'Set the computer label',
labelText = UI.Text {
@ -40,14 +40,11 @@ local labelTab = UI.Tab {
{ key = 'value', textColor = colors.yellow },
},
},
}
function labelTab:eventHandler(event)
eventHandler = function(self, event)
if event.type == 'update_label' and self.label.value then
os.setComputerLabel(self.label.value)
self:emit({ type = 'success_message', message = 'Label updated' })
return true
end
end
return labelTab
end,
}

View File

@ -5,7 +5,7 @@ local UI = require('opus.ui')
local colors = _G.colors
local device = _G.device
local tab = UI.Tab {
return UI.Tab {
tabTitle = 'Network',
description = 'Networking options',
info = UI.TextArea {
@ -27,9 +27,7 @@ Reboot to take effect.]], Ansi.yellow, Ansi.reset)
x = 10, ex = -3, y = 3,
nochoice = 'auto',
},
}
function tab:enable()
enable = function(self)
local width = 7
local choices = {
{ name = 'auto', value = 'auto' },
@ -50,9 +48,8 @@ function tab:enable()
self.modem.value = config.wirelessModem or 'auto'
UI.Tab.enable(self)
end
function tab:eventHandler(event)
end,
eventHandler = function(self, event)
if event.type == 'choice_change' then
local config = Config.load('os')
config.wirelessModem = self.modem.value
@ -61,5 +58,4 @@ function tab:eventHandler(event)
return true
end
end
return tab
}

View File

@ -4,7 +4,7 @@ local UI = require('opus.ui')
local colors = _G.colors
local passwordTab = UI.Tab {
return UI.Tab {
tabTitle = 'Password',
description = 'Wireless network password',
[1] = UI.Window {
@ -30,9 +30,8 @@ local passwordTab = UI.Tab {
textColor = colors.yellow,
inactive = true,
value = 'Add a password to enable other computers to connect to this one.',
}
}
function passwordTab:eventHandler(event)
},
eventHandler = function(self, event)
if event.type == 'update_password' then
if not self.newPass.value or #self.newPass.value == 0 then
self:emit({ type = 'error_message', message = 'Invalid password' })
@ -44,5 +43,4 @@ function passwordTab:eventHandler(event)
return true
end
end
return passwordTab
}

View File

@ -38,7 +38,7 @@ if not _colors.backgroundColor then
_colors.fileColor = colors.white
end
local tab = UI.Tab {
return UI.Tab {
tabTitle = 'Shell',
description = 'Shell options',
grid1 = UI.ScrollingGrid {
@ -54,6 +54,13 @@ local tab = UI.Tab {
columns = { { key = 'name' } },
values = allColors,
sortColumn = 'name',
getRowTextColor = function(self, row)
local selected = self.parent.grid1:getSelected()
if _colors[selected.name] == row.value then
return colors.yellow
end
return UI.Grid.getRowTextColor(self, row)
end
},
directory = UI.Checkbox {
x = 2, y = -2,
@ -73,18 +80,7 @@ local tab = UI.Tab {
},
display = UI.Window {
x = 2, ex = -2, y = -8, height = 5,
},
}
function tab.grid2:getRowTextColor(row)
local selected = tab.grid1:getSelected()
if _colors[selected.name] == row.value then
return colors.yellow
end
return UI.Grid.getRowTextColor(self, row)
end
function tab.display:draw()
draw = function(self)
self:clear(_colors.backgroundColor)
local offset = 0
if config.displayDirectory then
@ -105,9 +101,9 @@ function tab.display:draw()
self:write(1, 3 + offset, 'startup',
_colors.backgroundColor, _colors.fileColor)
end
function tab:eventHandler(event)
end,
},
eventHandler = function(self, event)
if event.type =='checkbox_change' then
config.displayDirectory = not not event.checked
self.display:draw()
@ -136,5 +132,4 @@ function tab:eventHandler(event)
end
return UI.Tab.eventHandler(self, event)
end
return tab
}

View File

@ -41,9 +41,9 @@ end
function Entry:updateScroll()
local ps = self.scroll
local value = _val(self.value)
if self.pos > #value then
self.pos = #value
local len = #_val(self.value)
if self.pos > len then
self.pos = len
self.scroll = 0 -- ??
end
if self.pos - self.scroll > self.width then
@ -51,6 +51,11 @@ function Entry:updateScroll()
elseif self.pos < self.scroll then
self.scroll = self.pos
end
if self.scroll > 0 then
if self.scroll + self.width > len then
self.scroll = len - self.width
end
end
if ps ~= self.scroll then
self.textChanged = true
end
@ -217,6 +222,10 @@ function Entry:paste(ie)
end
end
function Entry:forcePaste()
os.queueEvent('clipboard_paste')
end
function Entry:clearLine()
if #_val(self.value) > 0 then
self:reset()
@ -363,7 +372,7 @@ local mappings = {
--[ 'control-d' ] = Entry.cutNextWord,
[ 'control-x' ] = Entry.cut,
[ 'paste' ] = Entry.paste,
-- [ 'control-y' ] = Entry.paste, -- well this won't work...
[ 'control-y' ] = Entry.forcePaste, -- well this won't work...
[ 'mouse_doubleclick' ] = Entry.markWord,
[ 'mouse_tripleclick' ] = Entry.markAll,

View File

@ -1096,6 +1096,14 @@ function UI.Device:addTransition(effect, args, canvas)
effect = Transition[effect] or error('Invalid transition')
end
-- there can be only one
for k,v in pairs(self.transitions) do
if v.canvas == canvas then
table.remove(self.transitions, k)
break
end
end
table.insert(self.transitions, { effect = effect, args = args or { }, canvas = canvas })
end