diff --git a/sys/apps/Files.lua b/sys/apps/Files.lua index 7626dee..de51b37 100644 --- a/sys/apps/Files.lua +++ b/sys/apps/Files.lua @@ -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) diff --git a/sys/apps/system/kiosk.lua b/sys/apps/system/kiosk.lua index 29cb351..2f9510b 100644 --- a/sys/apps/system/kiosk.lua +++ b/sys/apps/system/kiosk.lua @@ -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,35 +29,29 @@ local tab = UI.Tab { backgroundColor = colors.black, value = 'Settings apply to kiosk mode selected during startup' }, -} + enable = function(self) + local choices = { } -function tab:enable() - local choices = { } + peripheral.find('monitor', function(side) + table.insert(choices, { name = side, value = side }) + end) - peripheral.find('monitor', function(side) - table.insert(choices, { name = side, value = side }) - end) + self.form.monitor.choices = choices + self.form.monitor.value = settings.get('kiosk.monitor') - self.form.monitor.choices = choices - self.form.monitor.value = settings.get('kiosk.monitor') + self.form.textScale.value = settings.get('kiosk.textscale') - self.form.textScale.value = settings.get('kiosk.textscale') - - UI.Tab.enable(self) -end - -function tab:eventHandler(event) - if event.type == 'choice_change' then - if self.form.monitor.value then - settings.set('kiosk.monitor', self.form.monitor.value) + UI.Tab.enable(self) + 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) + end + if self.form.textScale.value then + settings.set('kiosk.textscale', self.form.textScale.value) + end + settings.save('.settings') end - if self.form.textScale.value then - settings.set('kiosk.textscale', self.form.textScale.value) - end - settings.save('.settings') end -end - -if peripheral.find('monitor') then - return tab -end +} diff --git a/sys/apps/system/label.lua b/sys/apps/system/label.lua index 11ee539..19ff30a 100644 --- a/sys/apps/system/label.lua +++ b/sys/apps/system/label.lua @@ -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 }, }, }, + 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, } - -function labelTab:eventHandler(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 diff --git a/sys/apps/system/network.lua b/sys/apps/system/network.lua index adaf239..818899d 100644 --- a/sys/apps/system/network.lua +++ b/sys/apps/system/network.lua @@ -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,39 +27,35 @@ Reboot to take effect.]], Ansi.yellow, Ansi.reset) x = 10, ex = -3, y = 3, nochoice = 'auto', }, -} + enable = function(self) + local width = 7 + local choices = { + { name = 'auto', value = 'auto' }, + { name = 'disable', value = 'none' }, + } -function tab:enable() - local width = 7 - local choices = { - { name = 'auto', value = 'auto' }, - { name = 'disable', value = 'none' }, - } + for k,v in pairs(device) do + if v.isWireless and v.isWireless() and k ~= 'wireless_modem' then + table.insert(choices, { name = k, value = v.name }) + width = math.max(width, #k) + end + end - for k,v in pairs(device) do - if v.isWireless and v.isWireless() and k ~= 'wireless_modem' then - table.insert(choices, { name = k, value = v.name }) - width = math.max(width, #k) + self.modem.choices = choices + --self.modem.width = width + 4 + + local config = Config.load('os') + self.modem.value = config.wirelessModem or 'auto' + + UI.Tab.enable(self) + end, + eventHandler = function(self, event) + if event.type == 'choice_change' then + local config = Config.load('os') + config.wirelessModem = self.modem.value + Config.update('os', config) + self:emit({ type = 'success_message', message = 'reboot to take effect' }) + return true end end - - self.modem.choices = choices - --self.modem.width = width + 4 - - local config = Config.load('os') - self.modem.value = config.wirelessModem or 'auto' - - UI.Tab.enable(self) -end - -function tab:eventHandler(event) - if event.type == 'choice_change' then - local config = Config.load('os') - config.wirelessModem = self.modem.value - Config.update('os', config) - self:emit({ type = 'success_message', message = 'reboot to take effect' }) - return true - end -end - -return tab +} diff --git a/sys/apps/system/password.lua b/sys/apps/system/password.lua index 90e1367..86920fc 100644 --- a/sys/apps/system/password.lua +++ b/sys/apps/system/password.lua @@ -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,19 +30,17 @@ 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) - 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' }) + }, + 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' }) - else - Security.updatePassword(SHA.compute(self.newPass.value)) - self:emit({ type = 'success_message', message = 'Password updated' }) + else + Security.updatePassword(SHA.compute(self.newPass.value)) + self:emit({ type = 'success_message', message = 'Password updated' }) + end + return true end - return true end -end - -return passwordTab +} diff --git a/sys/apps/system/shell.lua b/sys/apps/system/shell.lua index 7f0751d..c0aa8ff 100644 --- a/sys/apps/system/shell.lua +++ b/sys/apps/system/shell.lua @@ -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,68 +80,56 @@ local tab = UI.Tab { }, display = UI.Window { x = 2, ex = -2, y = -8, height = 5, + draw = function(self) + self:clear(_colors.backgroundColor) + local offset = 0 + if config.displayDirectory then + self:write(1, 1, + '==' .. os.getComputerLabel() .. ':/dir/etc', + _colors.directoryBackgroundColor, _colors.directoryTextColor) + offset = 1 + end + + self:write(1, 1 + offset, '$ ', + _colors.promptBackgroundColor, _colors.promptTextColor) + + self:write(3, 1 + offset, 'ls /', + _colors.backgroundColor, _colors.commandTextColor) + + self:write(1, 2 + offset, 'sys usr', + _colors.backgroundColor, _colors.directoryColor) + + self:write(1, 3 + offset, 'startup', + _colors.backgroundColor, _colors.fileColor) + end, }, + eventHandler = function(self, event) + if event.type =='checkbox_change' then + config.displayDirectory = not not event.checked + self.display:draw() + + elseif event.type == 'grid_focus_row' and event.element == self.grid1 then + self.grid2:draw() + + elseif event.type == 'grid_select' and event.element == self.grid2 then + _colors[tab.grid1:getSelected().name] = event.selected.value + self.display:draw() + self.grid2:draw() + + elseif event.type == 'reset' then + config.color = defaults + config.displayDirectory = true + self.directory.value = true + _colors = Util.shallowCopy(defaults) + + Config.update('shellprompt', config) + self:draw() + + elseif event.type == 'update' then + config.color = _colors + Config.update('shellprompt', config) + + end + return UI.Tab.eventHandler(self, event) + end } - -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() - self:clear(_colors.backgroundColor) - local offset = 0 - if config.displayDirectory then - self:write(1, 1, - '==' .. os.getComputerLabel() .. ':/dir/etc', - _colors.directoryBackgroundColor, _colors.directoryTextColor) - offset = 1 - end - - self:write(1, 1 + offset, '$ ', - _colors.promptBackgroundColor, _colors.promptTextColor) - - self:write(3, 1 + offset, 'ls /', - _colors.backgroundColor, _colors.commandTextColor) - - self:write(1, 2 + offset, 'sys usr', - _colors.backgroundColor, _colors.directoryColor) - - self:write(1, 3 + offset, 'startup', - _colors.backgroundColor, _colors.fileColor) -end - -function tab:eventHandler(event) - if event.type =='checkbox_change' then - config.displayDirectory = not not event.checked - self.display:draw() - - elseif event.type == 'grid_focus_row' and event.element == self.grid1 then - self.grid2:draw() - - elseif event.type == 'grid_select' and event.element == self.grid2 then - _colors[tab.grid1:getSelected().name] = event.selected.value - self.display:draw() - self.grid2:draw() - - elseif event.type == 'reset' then - config.color = defaults - config.displayDirectory = true - self.directory.value = true - _colors = Util.shallowCopy(defaults) - - Config.update('shellprompt', config) - self:draw() - - elseif event.type == 'update' then - config.color = _colors - Config.update('shellprompt', config) - - end - return UI.Tab.eventHandler(self, event) -end - -return tab diff --git a/sys/modules/opus/entry.lua b/sys/modules/opus/entry.lua index 48c34fb..0dc3536 100644 --- a/sys/modules/opus/entry.lua +++ b/sys/modules/opus/entry.lua @@ -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, diff --git a/sys/modules/opus/ui.lua b/sys/modules/opus/ui.lua index 0ece43b..3a1657e 100644 --- a/sys/modules/opus/ui.lua +++ b/sys/modules/opus/ui.lua @@ -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