mirror of https://github.com/kepler155c/opus
more editor work
This commit is contained in:
parent
cd58ecd861
commit
7659b81d49
|
@ -171,6 +171,30 @@ local page = UI.Page {
|
||||||
y = 6, x = 2, height = 3, width = 8,
|
y = 6, x = 2, height = 3, width = 8,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
file_open = UI.FileSelect {
|
||||||
|
modal = true,
|
||||||
|
enable = function() end,
|
||||||
|
transitionHint = 'expandUp',
|
||||||
|
show = function(self)
|
||||||
|
UI.FileSelect.enable(self)
|
||||||
|
self:focusFirst()
|
||||||
|
self:draw()
|
||||||
|
end,
|
||||||
|
disable = function(self)
|
||||||
|
UI.FileSelect.disable(self)
|
||||||
|
self.parent:focusFirst()
|
||||||
|
-- need to recapture as we are opening a modal within another modal
|
||||||
|
self.parent:capture(self.parent)
|
||||||
|
end,
|
||||||
|
eventHandler = function(self, event)
|
||||||
|
if event.type == 'select_cancel' then
|
||||||
|
self:disable()
|
||||||
|
elseif event.type == 'select_file' then
|
||||||
|
self:disable()
|
||||||
|
end
|
||||||
|
return UI.FileSelect.eventHandler(self, event)
|
||||||
|
end,
|
||||||
|
},
|
||||||
notification = UI.Notification(),
|
notification = UI.Notification(),
|
||||||
statusBar = UI.StatusBar(),
|
statusBar = UI.StatusBar(),
|
||||||
},
|
},
|
||||||
|
@ -412,7 +436,7 @@ function page.container:setCategory(categoryName, animate)
|
||||||
child.y = row
|
child.y = row
|
||||||
end
|
end
|
||||||
|
|
||||||
self:setViewHeight(row + 3)
|
self:setViewHeight(row + (config.listMode and 1 or 4))
|
||||||
|
|
||||||
if k < count then
|
if k < count then
|
||||||
col = col + child.width
|
col = col + child.width
|
||||||
|
@ -615,12 +639,11 @@ function page.editor:eventHandler(event)
|
||||||
self:loadImage(filename)
|
self:loadImage(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
elseif event.type == 'select_file' then
|
||||||
|
self:loadImage(event.file)
|
||||||
|
|
||||||
elseif event.type == 'loadIcon' then
|
elseif event.type == 'loadIcon' then
|
||||||
local success, filename = shell.run('fileui.lua')
|
self.file_open:show()
|
||||||
self.parent:dirty(true)
|
|
||||||
if success and filename then
|
|
||||||
self:loadImage(filename)
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif event.type == 'form_invalid' then
|
elseif event.type == 'form_invalid' then
|
||||||
self.notification:error(event.message)
|
self.notification:error(event.message)
|
||||||
|
|
|
@ -1,138 +1,35 @@
|
||||||
local UI = require('opus.ui')
|
local UI = require('opus.ui')
|
||||||
local Util = require('opus.util')
|
local Util = require('opus.util')
|
||||||
|
|
||||||
local colors = _G.colors
|
|
||||||
local fs = _G.fs
|
|
||||||
local shell = _ENV.shell
|
local shell = _ENV.shell
|
||||||
|
|
||||||
local selected
|
|
||||||
|
|
||||||
-- fileui [--path=path] [--exec=filename]
|
-- fileui [--path=path] [--exec=filename]
|
||||||
|
|
||||||
local page = UI.Page {
|
local page = UI.Page {
|
||||||
title = 'Select File',
|
fileselect = UI.FileSelect { },
|
||||||
-- x = 3, ex = -3, y = 2, ey = -2,
|
eventHandler = function(self, event)
|
||||||
grid = UI.ScrollingGrid {
|
if event.type == 'select_file' then
|
||||||
x = 2, y = 2, ex = -2, ey = -4,
|
self.selected = event.file
|
||||||
path = '',
|
UI:quit()
|
||||||
sortColumn = 'name',
|
|
||||||
columns = {
|
elseif event.type == 'select_cancel' then
|
||||||
{ heading = 'Name', key = 'name' },
|
UI:quit()
|
||||||
{ heading = 'Size', key = 'size', width = 5 }
|
end
|
||||||
},
|
|
||||||
getDisplayValues = function(_, row)
|
return UI.FileSelect.eventHandler(self, event)
|
||||||
if row.size then
|
|
||||||
row = Util.shallowCopy(row)
|
|
||||||
row.size = Util.toBytes(row.size)
|
|
||||||
end
|
|
||||||
return row
|
|
||||||
end,
|
|
||||||
getRowTextColor = function(_, file)
|
|
||||||
if file.isDir then
|
|
||||||
return colors.cyan
|
|
||||||
end
|
|
||||||
if file.isReadOnly then
|
|
||||||
return colors.pink
|
|
||||||
end
|
|
||||||
return colors.white
|
|
||||||
end,
|
|
||||||
sortCompare = function(self, 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,
|
|
||||||
draw = function(self)
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
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',
|
|
||||||
},
|
|
||||||
draw = function(self)
|
|
||||||
self:fillArea(1, 1, self.width, self.height, string.rep('\127', self.width), colors.black, colors.gray)
|
|
||||||
self:drawChildren()
|
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
function page:enable(path)
|
|
||||||
self:setPath(path or shell.dir())
|
|
||||||
UI.Page.enable(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
function page: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 page: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
|
|
||||||
selected = self.path.value
|
|
||||||
UI:quit()
|
|
||||||
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
|
|
||||||
selected = self.path.value
|
|
||||||
UI:quit()
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif event.type == 'cancel' then
|
|
||||||
UI:quit()
|
|
||||||
else
|
|
||||||
return UI.Page.eventHandler(self, event)
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local _, args = Util.parse(...)
|
local _, args = Util.parse(...)
|
||||||
|
|
||||||
UI:setPage(page, args.path)
|
UI:setPage(page, args.path)
|
||||||
UI:start()
|
UI:start()
|
||||||
UI.term:setCursorBlink(false)
|
UI.term:setCursorBlink(false)
|
||||||
|
|
||||||
if args.exec and selected then
|
if args.exec and page.selected then
|
||||||
shell.openForegroundTab(string.format('%s %s', args.exec, selected))
|
shell.openForegroundTab(string.format('%s %s', args.exec, page.selected))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--print('selected: ' .. tostring(selected))
|
-- print('selected: ' .. tostring(selected))
|
||||||
return selected
|
return page.selected
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
local fs = _G.fs
|
||||||
|
|
||||||
|
local function deleteIfExists(path)
|
||||||
|
if fs.exists(path) then
|
||||||
|
fs.delete(path)
|
||||||
|
print("Deleted outdated file at: "..path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- cleanup outdated files
|
||||||
|
deleteIfExists('sys/apps/shell')
|
||||||
|
deleteIfExists('sys/etc/app.db')
|
||||||
|
deleteIfExists('sys/extensions')
|
||||||
|
deleteIfExists('sys/network')
|
||||||
|
deleteIfExists('startup')
|
||||||
|
deleteIfExists('sys/apps/system/turtle.lua')
|
||||||
|
deleteIfExists('sys/autorun/gps.lua')
|
||||||
|
deleteIfExists('sys/autorun/gpshost.lua')
|
||||||
|
deleteIfExists('sys/apps/network/redserver.lua')
|
||||||
|
deleteIfExists('sys/apis')
|
||||||
|
deleteIfExists('sys/autorun/apps.lua')
|
||||||
|
deleteIfExists('sys/init/6.tl3.lua')
|
||||||
|
|
||||||
|
-- remove this file
|
||||||
|
-- deleteIfExists('sys/autorun/upgraded.lua')
|
|
@ -50,7 +50,10 @@
|
||||||
title = "System",
|
title = "System",
|
||||||
category = "System",
|
category = "System",
|
||||||
icon = "\030 \0307\031f| \010\0307\031f---o\030 \031 \010\030 \009 \0307\031f| ",
|
icon = "\030 \0307\031f| \010\0307\031f---o\030 \031 \010\030 \009 \0307\031f| ",
|
||||||
iconExt = "\030 \0318\138\0308\031 \130\0318\128\031 \129\030 \0318\133\010\030 \0318\143\0308\128\0317\143\0318\128\030 \143\010\030 \0318\138\135\143\139\133",
|
iconExt = "22070b02424\
|
||||||
|
0277044\
|
||||||
|
7071724",
|
||||||
|
--iconExt = "\030 \0318\138\0308\031 \130\0318\128\031 \129\030 \0318\133\010\030 \0318\143\0308\128\0317\143\0318\128\030 \143\010\030 \0318\138\135\143\139\133",
|
||||||
run = "System.lua",
|
run = "System.lua",
|
||||||
},
|
},
|
||||||
[ "2a4d562b1d9a9c90bdede6fac8ce4f7402462b86" ] = {
|
[ "2a4d562b1d9a9c90bdede6fac8ce4f7402462b86" ] = {
|
||||||
|
|
|
@ -687,31 +687,39 @@ function UI.Window:sync()
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.Window:enable(...)
|
function UI.Window:enable(...)
|
||||||
self.enabled = true
|
if not self.enabled then
|
||||||
if self.transitionHint then
|
self.enabled = true
|
||||||
self:addTransition(self.transitionHint)
|
if self.transitionHint then
|
||||||
end
|
self:addTransition(self.transitionHint)
|
||||||
|
end
|
||||||
|
|
||||||
if self.modal then
|
if self.modal then
|
||||||
self:raise()
|
self:raise()
|
||||||
self:capture(self)
|
self:capture(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
for child in self:eachChild() do
|
for child in self:eachChild() do
|
||||||
child:enable(...)
|
if not child.enabled then
|
||||||
|
child:enable(...)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.Window:disable()
|
function UI.Window:disable()
|
||||||
self.enabled = false
|
if self.enabled then
|
||||||
self.parent:dirty(true)
|
self.enabled = false
|
||||||
|
self.parent:dirty(true)
|
||||||
|
|
||||||
if self.modal then
|
if self.modal then
|
||||||
self:release(self)
|
self:release(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
for child in self:eachChild() do
|
for child in self:eachChild() do
|
||||||
child:disable()
|
if child.enabled then
|
||||||
|
child:disable()
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,118 @@
|
||||||
|
local class = require('opus.class')
|
||||||
|
local UI = require('opus.ui')
|
||||||
|
local Util = require('opus.util')
|
||||||
|
|
||||||
|
local colors = _G.colors
|
||||||
|
local fs = _G.fs
|
||||||
|
|
||||||
|
UI.FileSelect = class(UI.Window)
|
||||||
|
UI.FileSelect.defaults = {
|
||||||
|
UIElement = 'FileSelect',
|
||||||
|
}
|
||||||
|
function UI.FileSelect:postInit()
|
||||||
|
self.grid = UI.ScrollingGrid {
|
||||||
|
x = 2, y = 2, ex = -2, ey = -4,
|
||||||
|
dir = '/',
|
||||||
|
sortColumn = 'name',
|
||||||
|
columns = {
|
||||||
|
{ heading = 'Name', key = 'name' },
|
||||||
|
{ heading = 'Size', key = 'size', width = 5 }
|
||||||
|
},
|
||||||
|
getDisplayValues = function(_, row)
|
||||||
|
if row.size then
|
||||||
|
row = Util.shallowCopy(row)
|
||||||
|
row.size = Util.toBytes(row.size)
|
||||||
|
end
|
||||||
|
return row
|
||||||
|
end,
|
||||||
|
getRowTextColor = function(_, file)
|
||||||
|
if file.isDir then
|
||||||
|
return colors.cyan
|
||||||
|
end
|
||||||
|
if file.isReadOnly then
|
||||||
|
return colors.pink
|
||||||
|
end
|
||||||
|
return colors.white
|
||||||
|
end,
|
||||||
|
sortCompare = function(self, 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,
|
||||||
|
draw = function(self)
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
self.path = UI.TextEntry {
|
||||||
|
x = 2,
|
||||||
|
y = -2,
|
||||||
|
ex = -11,
|
||||||
|
limit = 256,
|
||||||
|
accelerators = {
|
||||||
|
enter = 'path_enter',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.cancel = UI.Button {
|
||||||
|
text = 'Cancel',
|
||||||
|
x = -9,
|
||||||
|
y = -2,
|
||||||
|
event = 'select_cancel',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function UI.FileSelect:draw()
|
||||||
|
self:fillArea(1, 1, self.width, self.height, string.rep('\127', self.width), colors.black, colors.gray)
|
||||||
|
self:drawChildren()
|
||||||
|
end
|
||||||
|
|
||||||
|
function UI.FileSelect:enable(path)
|
||||||
|
self:setPath(path or '')
|
||||||
|
UI.Window.enable(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function UI.FileSelect: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 UI.FileSelect: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
|
||||||
|
self:emit({ type = 'select_file', file = '/' .. self.path.value, element = self })
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
|
||||||
|
elseif event.type == 'path_enter' then
|
||||||
|
if self.path.value then
|
||||||
|
if fs.isDir(self.path.value) then
|
||||||
|
self:setPath(self.path.value)
|
||||||
|
self.grid:draw()
|
||||||
|
self.path:draw()
|
||||||
|
else
|
||||||
|
self:emit({ type = 'select_file', file = '/' .. self.path.value, element = self })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
|
@ -32,10 +32,6 @@ function UI.Page:enable()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.Page:disable()
|
|
||||||
UI.Window.disable(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
function UI.Page:sync()
|
function UI.Page:sync()
|
||||||
if self.enabled then
|
if self.enabled then
|
||||||
self:checkFocus()
|
self:checkFocus()
|
||||||
|
@ -58,7 +54,6 @@ function UI.Page:pointToChild(x, y)
|
||||||
return UI.Window.pointToChild(self, x, y)
|
return UI.Window.pointToChild(self, x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- need to add offsets to this test
|
|
||||||
local function getPosition(element)
|
local function getPosition(element)
|
||||||
local x, y = 1, 1
|
local x, y = 1, 1
|
||||||
repeat
|
repeat
|
||||||
|
|
|
@ -13,6 +13,7 @@ local _unpack = table.unpack
|
||||||
local _bor = bit32.bor
|
local _bor = bit32.bor
|
||||||
local _bxor = bit32.bxor
|
local _bxor = bit32.bxor
|
||||||
|
|
||||||
|
local byteArrayMT
|
||||||
byteArrayMT = {
|
byteArrayMT = {
|
||||||
__tostring = function(a) return string.char(_unpack(a)) end,
|
__tostring = function(a) return string.char(_unpack(a)) end,
|
||||||
__index = {
|
__index = {
|
||||||
|
|
Loading…
Reference in New Issue