properly handle empty text entry fields (including transformations)
This commit is contained in:
@@ -276,7 +276,7 @@ function substitutionPage:eventHandler(event)
|
|||||||
self.info:draw()
|
self.info:draw()
|
||||||
|
|
||||||
elseif event.type == 'text_change' then
|
elseif event.type == 'text_change' then
|
||||||
local text = event.text
|
local text = event.text or ''
|
||||||
if #text == 0 then
|
if #text == 0 then
|
||||||
self.grid.values = self.allItems
|
self.grid.values = self.allItems
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ local tab = UI.Tab {
|
|||||||
shadowText = 'id',
|
shadowText = 'id',
|
||||||
width = 5,
|
width = 5,
|
||||||
limit = 3,
|
limit = 3,
|
||||||
|
transform = 'number',
|
||||||
},
|
},
|
||||||
add = UI.Button {
|
add = UI.Button {
|
||||||
x = 28, y = 3,
|
x = 28, y = 3,
|
||||||
@@ -78,23 +79,27 @@ end
|
|||||||
|
|
||||||
function tab:eventHandler(event)
|
function tab:eventHandler(event)
|
||||||
if event.type == 'form_complete' then
|
if event.type == 'form_complete' then
|
||||||
ccemux.detach(event.values.side)
|
if event.values.type == 'disk_drive' and not event.values.drive_id then
|
||||||
ccemux.attach(event.values.side, event.values.type)
|
self:emit({ type = 'error_message', message = 'Invalid drive ID' })
|
||||||
|
else
|
||||||
|
ccemux.detach(event.values.side)
|
||||||
|
ccemux.attach(event.values.side, event.values.type)
|
||||||
|
|
||||||
local config = Config.load('ccemux')
|
local config = Config.load('ccemux')
|
||||||
config[event.values.side] = {
|
config[event.values.side] = {
|
||||||
type = event.values.type
|
type = event.values.type
|
||||||
}
|
|
||||||
if event.values.type == 'disk_drive' and tonumber(event.values.drive_id) then
|
|
||||||
config[event.values.side].args = {
|
|
||||||
id = tonumber(event.values.drive_id)
|
|
||||||
}
|
}
|
||||||
end
|
if event.values.type == 'disk_drive' then
|
||||||
Config.update('ccemux', config)
|
config[event.values.side].args = {
|
||||||
self:updatePeripherals(config)
|
id = event.values.drive_id
|
||||||
self.grid:draw()
|
}
|
||||||
|
end
|
||||||
|
Config.update('ccemux', config)
|
||||||
|
self:updatePeripherals(config)
|
||||||
|
self.grid:draw()
|
||||||
|
|
||||||
self:emit({ type = 'success_message', message = 'Attached' })
|
self:emit({ type = 'success_message', message = 'Attached' })
|
||||||
|
end
|
||||||
|
|
||||||
elseif event.type == 'choice_change' then
|
elseif event.type == 'choice_change' then
|
||||||
if event.element == self.form.ptype then
|
if event.element == self.form.ptype then
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ local Util = require('opus.util')
|
|||||||
local peripheral = _G.peripheral
|
local peripheral = _G.peripheral
|
||||||
|
|
||||||
if not peripheral.find('speaker') then
|
if not peripheral.find('speaker') then
|
||||||
error('No speaker attached')
|
error('No speaker attached')
|
||||||
end
|
end
|
||||||
|
|
||||||
local rawSounds = Util.readLines('packages/games/etc/sounds.txt') or error('Unable to read sounds file')
|
local rawSounds = Util.readLines('packages/games/etc/sounds.txt') or error('Unable to read sounds file')
|
||||||
local sounds = { }
|
local sounds = { }
|
||||||
for _, s in pairs(rawSounds) do
|
for _, s in pairs(rawSounds) do
|
||||||
table.insert(sounds, { name = s })
|
table.insert(sounds, { name = s })
|
||||||
end
|
end
|
||||||
|
|
||||||
UI:configure('SoundPlayer', ...)
|
UI:configure('SoundPlayer', ...)
|
||||||
@@ -25,21 +25,21 @@ local page = UI.Page {
|
|||||||
x = 10, y = 2, ex = -3,
|
x = 10, y = 2, ex = -3,
|
||||||
limit = 32,
|
limit = 32,
|
||||||
},
|
},
|
||||||
grid = UI.ScrollingGrid {
|
grid = UI.ScrollingGrid {
|
||||||
y = 4,
|
y = 4,
|
||||||
columns = {
|
columns = {
|
||||||
{ heading = 'Name', key = 'name' },
|
{ heading = 'Name', key = 'name' },
|
||||||
},
|
},
|
||||||
values = sounds,
|
values = sounds,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function page:eventHandler(event)
|
function page:eventHandler(event)
|
||||||
if event.type == 'grid_select' then
|
if event.type == 'grid_select' then
|
||||||
Sound.play(event.selected.name)
|
Sound.play(event.selected.name)
|
||||||
|
|
||||||
elseif event.type == 'text_change' then
|
elseif event.type == 'text_change' then
|
||||||
if #event.text == 0 then
|
if not event.text then
|
||||||
self.grid.values = sounds
|
self.grid.values = sounds
|
||||||
else
|
else
|
||||||
self.grid.values = { }
|
self.grid.values = { }
|
||||||
@@ -51,12 +51,12 @@ function page:eventHandler(event)
|
|||||||
end
|
end
|
||||||
self.grid:update()
|
self.grid:update()
|
||||||
self.grid:setIndex(1)
|
self.grid:setIndex(1)
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
|
|
||||||
else
|
else
|
||||||
return UI.Page.eventHandler(self, event)
|
return UI.Page.eventHandler(self, event)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
UI:setPage(page)
|
UI:setPage(page)
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ local function rewriteFiles(p)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function tab:eventHandler(event)
|
function tab:eventHandler(event)
|
||||||
if event.type == 'add_path' then
|
if event.type == 'add_path' and self.entry.value then
|
||||||
table.insert(self.grid.values, {
|
table.insert(self.grid.values, {
|
||||||
value = self.entry.value,
|
value = self.entry.value,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ function page:eventHandler(event)
|
|||||||
Config.update('miloRemote', context.state)
|
Config.update('miloRemote', context.state)
|
||||||
|
|
||||||
elseif event.type == 'text_change' and event.element == self.statusBar.filter then
|
elseif event.type == 'text_change' and event.element == self.statusBar.filter then
|
||||||
self.filter = event.text
|
self.filter = event.text or ''
|
||||||
if #self.filter == 0 then
|
if #self.filter == 0 then
|
||||||
self.filter = nil
|
self.filter = nil
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ function page:eventHandler(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
elseif event.type == 'text_change' and event.element == self.statusBar.filter then
|
elseif event.type == 'text_change' and event.element == self.statusBar.filter then
|
||||||
self.filter = event.text
|
self.filter = event.text or ''
|
||||||
if #self.filter == 0 then
|
if #self.filter == 0 then
|
||||||
self.filter = nil
|
self.filter = nil
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ local manageTab = UI.Tab {
|
|||||||
[2] = UI.TextEntry {
|
[2] = UI.TextEntry {
|
||||||
width = 7,
|
width = 7,
|
||||||
formLabel = 'Min', formKey = 'low', help = 'Craft if below min',
|
formLabel = 'Min', formKey = 'low', help = 'Craft if below min',
|
||||||
validate = 'numeric',
|
transform = 'number',
|
||||||
},
|
},
|
||||||
[3] = UI.TextEntry {
|
[3] = UI.TextEntry {
|
||||||
width = 7,
|
width = 7,
|
||||||
formLabel = 'Max', formKey = 'limit', help = 'Send to trash if above max',
|
formLabel = 'Max', formKey = 'limit', help = 'Send to trash if above max',
|
||||||
validate = 'numeric',
|
transform = 'number',
|
||||||
},
|
},
|
||||||
[4] = UI.Checkbox {
|
[4] = UI.Checkbox {
|
||||||
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage',
|
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage',
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ local setup = UI.SlideOut {
|
|||||||
help = 'ID for the server',
|
help = 'ID for the server',
|
||||||
shadowText = 'Milo server ID',
|
shadowText = 'Milo server ID',
|
||||||
limit = 6,
|
limit = 6,
|
||||||
validate = 'numeric',
|
transform = 'number',
|
||||||
required = true,
|
required = true,
|
||||||
},
|
},
|
||||||
[2] = UI.TextEntry {
|
[2] = UI.TextEntry {
|
||||||
@@ -29,7 +29,7 @@ local setup = UI.SlideOut {
|
|||||||
help = 'Use a slot for sending to storage',
|
help = 'Use a slot for sending to storage',
|
||||||
shadowText = 'Inventory slot #',
|
shadowText = 'Inventory slot #',
|
||||||
limit = 5,
|
limit = 5,
|
||||||
validate = 'numeric',
|
transform = 'number',
|
||||||
required = false,
|
required = false,
|
||||||
},
|
},
|
||||||
[3] = UI.Checkbox {
|
[3] = UI.Checkbox {
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ local storageView = UI.WizardPage {
|
|||||||
formLabel = 'Priority', formKey = 'priority',
|
formLabel = 'Priority', formKey = 'priority',
|
||||||
help = 'Larger values get precedence',
|
help = 'Larger values get precedence',
|
||||||
limit = 4,
|
limit = 4,
|
||||||
validate = 'numeric',
|
transform = 'number',
|
||||||
shadowText = 'Numeric priority',
|
shadowText = 'Numeric priority',
|
||||||
},
|
},
|
||||||
[2] = UI.TextEntry {
|
[2] = UI.TextEntry {
|
||||||
formLabel = 'Refresh', formKey = 'refreshInterval',
|
formLabel = 'Refresh', formKey = 'refreshInterval',
|
||||||
shadowText = 'seconds between refresh',
|
shadowText = 'seconds between refresh',
|
||||||
limit = 4,
|
limit = 4,
|
||||||
validate = 'numeric',
|
tranform = 'number',
|
||||||
help = 'Refresh periodically',
|
help = 'Refresh periodically',
|
||||||
},
|
},
|
||||||
[3] = UI.TextArea {
|
[3] = UI.TextArea {
|
||||||
|
|||||||
@@ -42,11 +42,15 @@ function tab:eventHandler(event)
|
|||||||
config.enabled = not not event.checked
|
config.enabled = not not event.checked
|
||||||
|
|
||||||
elseif event.type == 'update' then
|
elseif event.type == 'update' then
|
||||||
config.timeout = self.timeout.value
|
if self.timeout.value then
|
||||||
Config.update('saver', config)
|
config.timeout = self.timeout.value
|
||||||
|
Config.update('saver', config)
|
||||||
|
|
||||||
self:emit({ type = 'success_message', message = 'Settings updated' })
|
self:emit({ type = 'success_message', message = 'Settings updated' })
|
||||||
os.queueEvent('config_update', 'saver', config)
|
os.queueEvent('config_update', 'saver', config)
|
||||||
|
else
|
||||||
|
self:emit({ type = 'error_message', message = 'Invalid timeout' })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return UI.Tab.eventHandler(self, event)
|
return UI.Tab.eventHandler(self, event)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,11 +42,15 @@ function tab:eventHandler(event)
|
|||||||
config.enabled = not not event.checked
|
config.enabled = not not event.checked
|
||||||
|
|
||||||
elseif event.type == 'update' then
|
elseif event.type == 'update' then
|
||||||
config.timeout = self.timeout.value
|
if self.timeout.value then
|
||||||
Config.update('secure', config)
|
config.timeout = self.timeout.value
|
||||||
|
Config.update('secure', config)
|
||||||
|
|
||||||
self:emit({ type = 'success_message', message = 'Settings updated' })
|
self:emit({ type = 'success_message', message = 'Settings updated' })
|
||||||
os.queueEvent('config_update', 'secure', config)
|
os.queueEvent('config_update', 'secure', config)
|
||||||
|
else
|
||||||
|
self:emit({ type = 'error_message', message = 'Invalid timeout' })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return UI.Tab.eventHandler(self, event)
|
return UI.Tab.eventHandler(self, event)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ local passwordPage = UI.WizardPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local function makeAddress(text, isPrivateKey)
|
local function makeAddress(text, isPrivateKey)
|
||||||
local privKey = text
|
local privKey = text or ''
|
||||||
if not isPrivateKey then
|
if not isPrivateKey then
|
||||||
privKey = Krist.toKristWalletFormat(privKey)
|
privKey = Krist.toKristWalletFormat(privKey)
|
||||||
end
|
end
|
||||||
@@ -116,7 +116,7 @@ end
|
|||||||
function passwordPage.form:eventHandler(event)
|
function passwordPage.form:eventHandler(event)
|
||||||
if (event.type == 'text_change' and event.element.pass) or
|
if (event.type == 'text_change' and event.element.pass) or
|
||||||
(event.type == 'checkbox_change' and event.element.ispkey) then
|
(event.type == 'checkbox_change' and event.element.ispkey) then
|
||||||
self.passEntry.shadowText = self.pkeyCheck.value and 'Private key' or 'Password'
|
self.passEntry.shadowText = self.pkeyCheck.value and 'Private key' or 'Password'
|
||||||
self.preview.value = makeAddress(self.passEntry.value, self.pkeyCheck.value)
|
self.preview.value = makeAddress(self.passEntry.value, self.pkeyCheck.value)
|
||||||
self:draw()
|
self:draw()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ local shopTab = UI.Tab {
|
|||||||
formLabel = 'Price', formKey = 'price',
|
formLabel = 'Price', formKey = 'price',
|
||||||
help = 'Per item cost',
|
help = 'Per item cost',
|
||||||
required = true,
|
required = true,
|
||||||
validate = 'numeric',
|
transform = 'number',
|
||||||
},
|
},
|
||||||
[3] = UI.TextEntry {
|
[3] = UI.TextEntry {
|
||||||
limit = 64,
|
limit = 64,
|
||||||
|
|||||||
Reference in New Issue
Block a user