1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-18 09:17:40 +00:00

Overlapping windows

This commit is contained in:
kepler155c@gmail.com
2016-12-22 23:22:04 -05:00
parent 977998ebdb
commit d61260ec9b
13 changed files with 492 additions and 254 deletions

View File

@@ -35,26 +35,32 @@ local Browser = UI.Page {
},
fileMenu = UI.DropMenu {
buttons = {
{ text = 'Run', event = 'run' },
{ text = 'Edit e', event = 'edit' },
{ text = 'Shell s', event = 'shell' },
{ text = 'Quit q', event = 'quit' },
{ text = 'Run', event = 'run' },
{ text = 'Edit e', event = 'edit' },
{ text = 'Shell s', event = 'shell' },
UI.Text { value = ' ------------ ' },
{ text = 'Quit q', event = 'quit' },
UI.Text { },
}
},
editMenu = UI.DropMenu {
buttons = {
{ text = 'Mark m', event = 'mark' },
{ text = 'Cut ^x', event = 'cut' },
{ text = 'Copy ^c', event = 'copy' },
{ text = 'Paste ^v', event = 'paste' },
{ text = 'Delete del', event = 'delete' },
{ text = 'Unmark all u', event = 'unmark' },
{ text = 'Cut ^x', event = 'cut' },
{ text = 'Copy ^c', event = 'copy' },
{ text = 'Paste ^v', event = 'paste' },
UI.Text { value = ' --------------- ' },
{ text = 'Mark m', event = 'mark' },
{ text = 'Unmark all u', event = 'unmark' },
UI.Text { value = ' --------------- ' },
{ text = 'Delete del', event = 'delete' },
UI.Text { },
}
},
viewMenu = UI.DropMenu {
buttons = {
{ text = 'Refresh r', event = 'refresh' },
{ text = 'Hidden ^h', event = 'toggle_hidden' },
{ text = 'Refresh r', event = 'refresh' },
{ text = 'Hidden ^h', event = 'toggle_hidden' },
UI.Text { },
}
},
grid = UI.ScrollingGrid {
@@ -69,8 +75,8 @@ local Browser = UI.Page {
},
statusBar = UI.StatusBar {
columns = {
{ '', 'status', UI.term.width - 19 },
{ '', 'info', 10 },
{ '', 'status', UI.term.width - 8 },
--{ '', 'info', 10 },
{ 'Size: ', 'totalSize', 8 },
},
},

View File

@@ -1,4 +1,5 @@
require = requireInjector(getfenv(1))
local injector = requireInjector or load(http.get('http://pastebin.com/raw/c0TWsScv').readAll())()
require = injector(getfenv(1))
local Util = require('util')
local UI = require('ui')
local Event = require('event')
@@ -6,7 +7,7 @@ local History = require('history')
local sandboxEnv = Util.shallowCopy(getfenv(1))
sandboxEnv.exit = function() Event.exitPullEvents() end
sandboxEnv.require = requireInjector(sandboxEnv)
sandboxEnv.require = injector(sandboxEnv)
setmetatable(sandboxEnv, { __index = _G })
multishell.setTitle(multishell.getCurrent(), 'Lua')
@@ -20,7 +21,7 @@ local page = UI.Page({
buttons = {
{ text = 'Local', event = 'local' },
{ text = 'Global', event = 'global' },
{ text = 'Device', event = 'device' },
{ text = 'Device', event = 'device', name = 'Device' },
},
}),
prompt = UI.TextEntry({
@@ -66,6 +67,9 @@ end
function page:enable()
self:setFocus(self.prompt)
UI.Page.enable(self)
if not device then
self.menuBar.Device:disable()
end
end
function page:eventHandler(event)
@@ -233,6 +237,8 @@ function page:executeStatement(statement)
if s and m then
self:setResult(m)
elseif s and type(m) == 'boolean' then
self:setResult(m)
else
self.grid:setValues({ })
self.grid:draw()
@@ -242,10 +248,11 @@ function page:executeStatement(statement)
end
end
sandboxEnv.args = { ... }
if sandboxEnv.args[1] then
local args = { ... }
if args[1] then
command = 'args[1]'
page:setResult(sandboxEnv.args[1])
sandboxEnv.args = args
page:setResult(args[1])
end
UI:setPage(page)

View File

@@ -331,64 +331,68 @@ function page:eventHandler(event)
end
local formWidth = math.max(UI.term.width - 14, 26)
local gutter = math.floor((UI.term.width - formWidth) / 2) + 1
local editor = UI.Page({
backgroundColor = colors.blue,
form = UI.Form({
fields = {
{ label = 'Title', key = 'title', width = 15, limit = 11, display = UI.Form.D.entry,
help = 'Application title' },
{ label = 'Run', key = 'run', width = formWidth - 11, limit = 100, display = UI.Form.D.entry,
help = 'Full path to application' },
{ label = 'Category', key = 'category', width = 15, limit = 11, display = UI.Form.D.entry,
help = 'Category of application' },
{ text = 'Accept', event = 'accept', display = UI.Form.D.button,
x = 1, y = 9, width = 10 },
{ text = 'Cancel', event = 'cancel', display = UI.Form.D.button,
x = formWidth - 11, y = 9, width = 10 },
local editor = UI.Page {
backgroundColor = colors.white,
x = math.ceil((UI.term.width - formWidth) / 2) + 1,
y = math.ceil((UI.term.height - 11) / 2) + 1,
z = 2,
height = 11,
width = formWidth,
titleBar = UI.TitleBar {
title = 'Edit application',
},
inset = UI.Window {
x = 2,
y = 3,
rex = -2,
rey = -3,
form = UI.Form {
textColor = colors.black,
fields = {
{ label = 'Title', key = 'title', width = formWidth - 11, limit = 11, display = UI.Form.D.entry,
help = 'Application title' },
{ label = 'Run', key = 'run', width = formWidth - 11, limit = 100, display = UI.Form.D.entry,
help = 'Full path to application' },
{ label = 'Category', key = 'category', width = formWidth - 11, limit = 11, display = UI.Form.D.entry,
help = 'Category of application' },
{ text = 'Icon', event = 'loadIcon', display = UI.Form.D.button,
x = 10, y = 5, textColor = colors.white, help = 'Select icon' },
{ text = 'Ok', event = 'accept', display = UI.Form.D.button,
x = formWidth - 14, y = 7, textColor = colors.white },
{ text = 'Cancel', event = 'cancel', display = UI.Form.D.button,
x = formWidth - 9, y = 7, textColor = colors.white },
},
labelWidth = 8,
image = UI.NftImage {
y = 5,
x = 1,
height = 3,
width = 8,
},
},
labelWidth = 8,
x = gutter + 1,
y = math.max(2, math.floor((UI.term.height - 9) / 2)),
height = 9,
width = UI.term.width - (gutter * 2),
image = UI.NftImage({
y = 5,
x = 1,
height = 3,
width = 8,
}),
button = UI.Button({
x = 10,
y = 6,
text = 'Load icon',
width = 11,
event = 'loadIcon',
}),
}),
},
statusBar = UI.StatusBar(),
notification = UI.Notification(),
iconFile = '',
})
}
function editor:enable(app)
if app then
self.original = app
self.form:setValues(Util.shallowCopy(app))
self.inset.form:setValues(Util.shallowCopy(app))
local icon
if app.icon then
icon = parseIcon(app.icon)
end
self.form.image:setImage(icon)
self:setFocus(self.form.children[1])
self.inset.form.image:setImage(icon)
end
UI.Page.enable(self)
self:focusFirst()
end
function editor.form.image:draw()
function editor.inset.form.image:draw()
self:clear()
UI.NftImage.draw(self)
end
@@ -414,7 +418,13 @@ function editor:eventHandler(event)
self.statusBar:draw()
elseif event.type == 'loadIcon' then
local fileui = FileUI()
local fileui = FileUI({
x = self.x,
y = self.y,
z = 2,
width = self.width,
height = self.height,
})
--fileui:setTransition(UI.effect.explode)
UI:setPage(fileui, fs.getDir(self.iconFile), function(fileName)
if fileName then
@@ -428,18 +438,19 @@ function editor:eventHandler(event)
if not icon then
error(m)
end
self.form.values.icon = iconLines
self.form.image:setImage(icon)
self.form.image:draw()
self.inset.form.values.icon = iconLines
self.inset.form.image:setImage(icon)
self.inset.form.image:draw()
end)
if not s and m then
self.notification:error(m:gsub('.*: (.*)', '%1'))
local msg = m:gsub('.*: (.*)', '%1')
self.notification:error(msg)
end
end
end)
elseif event.type == 'accept' then
local values = self.form.values
local values = self.inset.form.values
if #values.run > 0 and #values.title > 0 and #values.category > 0 then
UI:setPreviousPage()
self:updateApplications(values, self.original)

View File

@@ -1,4 +1,5 @@
require = requireInjector(getfenv(1))
local injector = requireInjector or load(http.get('http://pastebin.com/raw/c0TWsScv').readAll())()
require = injector(getfenv(1))
local Util = require('util')
local Event = require('event')
local UI = require('ui')

View File

@@ -66,7 +66,7 @@ local keyMapping = {
pageUp = 'pageUp',
[ 'control-b' ] = 'pageUp',
pageDown = 'pageDown',
[ 'control-f' ] = 'pageDown',
-- [ 'control-f' ] = 'pageDown',
home = 'home',
[ 'end' ] = 'toend',
[ 'control-home' ] = 'top',
@@ -101,6 +101,7 @@ local keyMapping = {
paste = 'paste',
tab = 'tab',
[ 'control-z' ] = 'undo',
[ 'control-space' ] = 'autocomplete',
-- copy/paste
[ 'control-x' ] = 'cut',
@@ -114,6 +115,7 @@ local keyMapping = {
[ 'control-enter' ] = 'run',
-- search
[ 'control-f' ] = 'find_prompt',
[ 'control-slash' ] = 'find_prompt',
[ 'control-n' ] = 'find_next',
@@ -476,6 +478,41 @@ local __actions = {
end
end,
autocomplete = function()
local sLine = tLines[y]:sub(1, x - 1)
local nStartPos = sLine:find("[a-zA-Z0-9_%.]+$")
if nStartPos then
sLine = sLine:sub(nStartPos)
end
if #sLine > 0 then
local results = textutils.complete(sLine)
if #results == 0 then
setError('No completions available')
elseif #results == 1 then
actions.insertText(x, y, results[1])
elseif #results > 1 then
local prefix = results[1]
for n = 1, #results do
local result = results[n]
while #prefix > 0 do
if result:find(prefix, 1, true) == 1 then
break
end
prefix = prefix:sub(1, #prefix - 1)
end
end
if #prefix > 0 then
actions.insertText(x, y, prefix)
else
setStatus('Too many results')
end
end
end
end,
refresh = function()
actions.dirty_all()
mark.continue = mark.active
@@ -528,7 +565,7 @@ local __actions = {
find_prompt = function()
local text = actions.input('/')
if #text > 0 then
searchPattern = text
searchPattern = text:lower()
if searchPattern then
actions.unmark()
actions.find(searchPattern, x)