editor recent/peripherals/redo + cleanup
This commit is contained in:
@@ -27,6 +27,26 @@ local page = UI.Page {
|
|||||||
},
|
},
|
||||||
autospace = true,
|
autospace = true,
|
||||||
disableHeader = true,
|
disableHeader = true,
|
||||||
|
getDisplayValues = function(_, row)
|
||||||
|
row = Util.shallowCopy(row)
|
||||||
|
|
||||||
|
local function tovalue(s)
|
||||||
|
if type(s) == 'table' then
|
||||||
|
return 'table'
|
||||||
|
end
|
||||||
|
return s
|
||||||
|
end
|
||||||
|
|
||||||
|
for k,v in pairs(row) do
|
||||||
|
row[k] = tovalue(v)
|
||||||
|
end
|
||||||
|
|
||||||
|
return row
|
||||||
|
end,
|
||||||
|
draw = function(self)
|
||||||
|
self:adjustWidth()
|
||||||
|
UI.Grid.draw(self)
|
||||||
|
end,
|
||||||
},
|
},
|
||||||
accelerators = {
|
accelerators = {
|
||||||
f = 'filter',
|
f = 'filter',
|
||||||
@@ -36,81 +56,48 @@ local page = UI.Page {
|
|||||||
[ 'control-q' ] = 'quit',
|
[ 'control-q' ] = 'quit',
|
||||||
},
|
},
|
||||||
filtered = { },
|
filtered = { },
|
||||||
}
|
eventHandler = function(self, event)
|
||||||
|
if event.type == 'filter' then
|
||||||
|
local entry = self.grid:getSelected()
|
||||||
|
self.filtered[entry.event] = true
|
||||||
|
|
||||||
function page:eventHandler(event)
|
elseif event.type == 'toggle' then
|
||||||
|
self.paused = not self.paused
|
||||||
|
if self.paused then
|
||||||
|
self.menuBar.pauseButton.text = 'Resume'
|
||||||
|
else
|
||||||
|
self.menuBar.pauseButton.text = 'Pause '
|
||||||
|
end
|
||||||
|
self.menuBar:draw()
|
||||||
|
|
||||||
if event.type == 'filter' then
|
elseif event.type == 'grid_select' then
|
||||||
local entry = self.grid:getSelected()
|
multishell.openTab({
|
||||||
self.filtered[entry.event] = true
|
path = 'sys/apps/Lua.lua',
|
||||||
|
args = { event.selected },
|
||||||
|
focused = true,
|
||||||
|
})
|
||||||
|
|
||||||
elseif event.type == 'toggle' then
|
elseif event.type == 'reset' then
|
||||||
self.paused = not self.paused
|
self.filtered = { }
|
||||||
if self.paused then
|
self.grid:setValues({ })
|
||||||
self.menuBar.pauseButton.text = 'Resume'
|
self.grid:draw()
|
||||||
else
|
if self.paused then
|
||||||
self.menuBar.pauseButton.text = 'Pause '
|
|
||||||
end
|
|
||||||
self.menuBar:draw()
|
|
||||||
|
|
||||||
elseif event.type == 'grid_select' then
|
|
||||||
multishell.openTab({
|
|
||||||
path = 'sys/apps/Lua.lua',
|
|
||||||
args = { event.selected },
|
|
||||||
focused = true,
|
|
||||||
})
|
|
||||||
|
|
||||||
elseif event.type == 'reset' then
|
|
||||||
self.filtered = { }
|
|
||||||
self.grid:setValues({ })
|
|
||||||
self.grid:draw()
|
|
||||||
if self.paused then
|
|
||||||
self:emit({ type = 'toggle' })
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif event.type == 'clear' then
|
|
||||||
self.grid:setValues({ })
|
|
||||||
self.grid:draw()
|
|
||||||
|
|
||||||
elseif event.type == 'quit' then
|
|
||||||
UI:exitPullEvents()
|
|
||||||
|
|
||||||
--[[
|
|
||||||
elseif event.type == 'focus_change' then
|
|
||||||
if event.focused == self.grid then
|
|
||||||
if not self.paused then
|
|
||||||
self:emit({ type = 'toggle' })
|
self:emit({ type = 'toggle' })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
elseif event.type == 'clear' then
|
||||||
|
self.grid:setValues({ })
|
||||||
|
self.grid:draw()
|
||||||
|
|
||||||
|
elseif event.type == 'quit' then
|
||||||
|
UI:exitPullEvents()
|
||||||
|
|
||||||
|
else
|
||||||
|
return UI.Page.eventHandler(self, event)
|
||||||
end
|
end
|
||||||
--]]
|
return true
|
||||||
|
end,
|
||||||
else
|
}
|
||||||
return UI.Page.eventHandler(self, event)
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function page.grid:getDisplayValues(row)
|
|
||||||
row = Util.shallowCopy(row)
|
|
||||||
|
|
||||||
local function tovalue(s)
|
|
||||||
if type(s) == 'table' then
|
|
||||||
return 'table'
|
|
||||||
end
|
|
||||||
return s
|
|
||||||
end
|
|
||||||
|
|
||||||
for k,v in pairs(row) do
|
|
||||||
row[k] = tovalue(v)
|
|
||||||
end
|
|
||||||
|
|
||||||
return row
|
|
||||||
end
|
|
||||||
|
|
||||||
function page.grid:draw()
|
|
||||||
self:adjustWidth()
|
|
||||||
UI.Grid.draw(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
local updated = false
|
local updated = false
|
||||||
local timerId = os.startTimer(1)
|
local timerId = os.startTimer(1)
|
||||||
@@ -150,6 +137,6 @@ end
|
|||||||
kernel.hook('*', hookFunction)
|
kernel.hook('*', hookFunction)
|
||||||
|
|
||||||
UI:setPage(page)
|
UI:setPage(page)
|
||||||
UI:pullEvents()
|
UI:start()
|
||||||
|
|
||||||
kernel.unhook('*', hookFunction)
|
kernel.unhook('*', hookFunction)
|
||||||
|
|||||||
240
common/edit.lua
240
common/edit.lua
@@ -1,8 +1,11 @@
|
|||||||
local fuzzy = require('opus.fuzzy')
|
local Array = require('opus.array')
|
||||||
local UI = require('opus.ui')
|
local Config = require('opus.config')
|
||||||
local Util = require('opus.util')
|
local fuzzy = require('opus.fuzzy')
|
||||||
|
local UI = require('opus.ui')
|
||||||
|
local Util = require('opus.util')
|
||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
|
local device = _G.device
|
||||||
local fs = _G.fs
|
local fs = _G.fs
|
||||||
local multishell = _ENV.multishell
|
local multishell = _ENV.multishell
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
@@ -18,6 +21,8 @@ local _insert = table.insert
|
|||||||
local _remove = table.remove
|
local _remove = table.remove
|
||||||
local _unpack = table.unpack
|
local _unpack = table.unpack
|
||||||
|
|
||||||
|
local config = Config.load('edit')
|
||||||
|
|
||||||
local x, y = 1, 1
|
local x, y = 1, 1
|
||||||
local w, h = term.getSize()
|
local w, h = term.getSize()
|
||||||
local scrollX = 0
|
local scrollX = 0
|
||||||
@@ -30,7 +35,7 @@ local lastSave
|
|||||||
local dirty = { y = 1, ey = h }
|
local dirty = { y = 1, ey = h }
|
||||||
local mark = { }
|
local mark = { }
|
||||||
local searchPattern
|
local searchPattern
|
||||||
local undo = { chain = { } }
|
local undo = { chain = { }, redo = { } }
|
||||||
|
|
||||||
h = h - 1
|
h = h - 1
|
||||||
|
|
||||||
@@ -96,7 +101,9 @@ local keyMapping = {
|
|||||||
paste = 'paste',
|
paste = 'paste',
|
||||||
tab = 'tab',
|
tab = 'tab',
|
||||||
[ 'control-z' ] = 'undo',
|
[ 'control-z' ] = 'undo',
|
||||||
|
[ 'control-Z' ] = 'redo',
|
||||||
[ 'control-space' ] = 'autocomplete',
|
[ 'control-space' ] = 'autocomplete',
|
||||||
|
[ 'control-shift-space' ] = 'peripheral',
|
||||||
|
|
||||||
-- copy/paste
|
-- copy/paste
|
||||||
[ 'control-x' ] = 'cut',
|
[ 'control-x' ] = 'cut',
|
||||||
@@ -126,8 +133,9 @@ local page = UI.Page {
|
|||||||
buttons = {
|
buttons = {
|
||||||
{ text = 'File', dropdown = {
|
{ text = 'File', dropdown = {
|
||||||
{ text = 'New ', event = 'menu_action', action = 'file_new' },
|
{ text = 'New ', event = 'menu_action', action = 'file_new' },
|
||||||
{ text = 'Open ', event = 'menu_action', action = 'file_open' },
|
{ text = 'Open... ', event = 'menu_action', action = 'file_open' },
|
||||||
{ text = 'Quick Open... ^p', event = 'menu_action', action = 'quick_open' },
|
{ text = 'Quick Open... ^p', event = 'menu_action', action = 'quick_open' },
|
||||||
|
{ text = 'Recent... ', event = 'menu_action', action = 'recent' },
|
||||||
{ spacer = true },
|
{ spacer = true },
|
||||||
{ text = 'Save ^s', event = 'menu_action', action = 'save' },
|
{ text = 'Save ^s', event = 'menu_action', action = 'save' },
|
||||||
{ text = 'Save As... ^S', event = 'menu_action', action = 'save_as' },
|
{ text = 'Save As... ^S', event = 'menu_action', action = 'save_as' },
|
||||||
@@ -146,8 +154,10 @@ local page = UI.Page {
|
|||||||
{ text = 'Mark all ^a', event = 'menu_action', action = 'mark_all' },
|
{ text = 'Mark all ^a', event = 'menu_action', action = 'mark_all' },
|
||||||
} },
|
} },
|
||||||
{ text = 'Code', dropdown = {
|
{ text = 'Code', dropdown = {
|
||||||
{ text = 'Complete ^space', event = 'menu_action', action = 'autocomplete' },
|
{ text = 'Complete ^space', event = 'menu_action', action = 'autocomplete' },
|
||||||
{ text = 'Run ^enter', event = 'menu_action', action = 'run' },
|
{ text = 'Run ^enter', event = 'menu_action', action = 'run' },
|
||||||
|
{ spacer = true },
|
||||||
|
{ text = 'Peripheral ^SPACE', event = 'menu_action', action = 'peripheral' },
|
||||||
} },
|
} },
|
||||||
},
|
},
|
||||||
status = UI.Text {
|
status = UI.Text {
|
||||||
@@ -185,10 +195,10 @@ local page = UI.Page {
|
|||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
search = UI.MiniSlideOut {
|
search = UI.MiniSlideOut {
|
||||||
x = -20, y = -2,
|
x = '50%', y = -2,
|
||||||
label = 'Find',
|
label = 'Find',
|
||||||
search = UI.TextEntry {
|
search = UI.TextEntry {
|
||||||
x = 7, width = 12,
|
x = 7, ex = -3,
|
||||||
limit = 512,
|
limit = 512,
|
||||||
markBackgroundColor = colors.lightGray,
|
markBackgroundColor = colors.lightGray,
|
||||||
backgroundFocusColor = colors.gray,
|
backgroundFocusColor = colors.gray,
|
||||||
@@ -218,10 +228,10 @@ local page = UI.Page {
|
|||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
save_as = UI.MiniSlideOut {
|
save_as = UI.MiniSlideOut {
|
||||||
x = -24, y = -2,
|
x = '30%', y = -2,
|
||||||
label = 'Save',
|
label = 'Save',
|
||||||
filename = UI.TextEntry {
|
filename = UI.TextEntry {
|
||||||
x = 7, width = 16,
|
x = 7, ex = -3,
|
||||||
limit = 512,
|
limit = 512,
|
||||||
markBackgroundColor = colors.lightGray,
|
markBackgroundColor = colors.lightGray,
|
||||||
backgroundFocusColor = colors.gray,
|
backgroundFocusColor = colors.gray,
|
||||||
@@ -294,6 +304,42 @@ local page = UI.Page {
|
|||||||
return UI.FileSelect.eventHandler(self, event)
|
return UI.FileSelect.eventHandler(self, event)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
recent = UI.SlideOut {
|
||||||
|
transitionHint = 'expandUp',
|
||||||
|
grid = UI.Grid {
|
||||||
|
x = 2, y = 2, ey = -4, ex = -2,
|
||||||
|
columns = {
|
||||||
|
{ key = 'name', heading = 'Name' },
|
||||||
|
{ key = 'dir', heading = 'Directory' },
|
||||||
|
},
|
||||||
|
accelerators = {
|
||||||
|
backspace = 'slide_hide',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
cancel = UI.Button {
|
||||||
|
x = -9, y = -2,
|
||||||
|
text = 'Cancel',
|
||||||
|
event = 'slide_hide',
|
||||||
|
},
|
||||||
|
show = function(self)
|
||||||
|
local t = { }
|
||||||
|
for _,v in pairs(config.recent or { }) do
|
||||||
|
table.insert(t, { name = fs.getName(v), dir = fs.getDir(v), path = v })
|
||||||
|
end
|
||||||
|
self.grid:setValues(t)
|
||||||
|
self.grid:setIndex(1)
|
||||||
|
UI.SlideOut.show(self)
|
||||||
|
self:addTransition('expandUp', { easing = 'outBounce', ticks = 12 })
|
||||||
|
end,
|
||||||
|
eventHandler = function(self, event)
|
||||||
|
if event.type == 'grid_select' then
|
||||||
|
actions.process('open', event.selected.path)
|
||||||
|
self:hide()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return UI.SlideOut.eventHandler(self, event)
|
||||||
|
end,
|
||||||
|
},
|
||||||
quick_open = UI.SlideOut {
|
quick_open = UI.SlideOut {
|
||||||
filter_entry = UI.TextEntry {
|
filter_entry = UI.TextEntry {
|
||||||
x = 2, y = 2, ex = -2,
|
x = 2, y = 2, ex = -2,
|
||||||
@@ -346,10 +392,10 @@ local page = UI.Page {
|
|||||||
show = function(self)
|
show = function(self)
|
||||||
local listing = { }
|
local listing = { }
|
||||||
local function recurse(dir)
|
local function recurse(dir)
|
||||||
local files = fs.native.list(dir)
|
local files = fs.list(dir)
|
||||||
for _,f in ipairs(files) do
|
for _,f in ipairs(files) do
|
||||||
local fullName = fs.combine(dir, f)
|
local fullName = fs.combine(dir, f)
|
||||||
if fs.native.isDir(fullName) then
|
if fs.native.isDir(fullName) then -- skip virtual dirs
|
||||||
if f ~= '.git' then recurse(fullName) end
|
if f ~= '.git' then recurse(fullName) end
|
||||||
else
|
else
|
||||||
_insert(listing, {
|
_insert(listing, {
|
||||||
@@ -366,6 +412,7 @@ local page = UI.Page {
|
|||||||
self:apply_filter()
|
self:apply_filter()
|
||||||
self.filter_entry:reset()
|
self.filter_entry:reset()
|
||||||
UI.SlideOut.show(self)
|
UI.SlideOut.show(self)
|
||||||
|
self:addTransition('expandUp', { easing = 'outBounce', ticks = 12 })
|
||||||
end,
|
end,
|
||||||
eventHandler = function(self, event)
|
eventHandler = function(self, event)
|
||||||
if event.type == 'grid_up' then
|
if event.type == 'grid_up' then
|
||||||
@@ -404,6 +451,14 @@ local page = UI.Page {
|
|||||||
backspace = 'slide_hide',
|
backspace = 'slide_hide',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
cancel = UI.Button {
|
||||||
|
y = -1, x = -9,
|
||||||
|
text = 'Cancel',
|
||||||
|
backgroundColor = colors.black,
|
||||||
|
backgroundFocusColor = colors.black,
|
||||||
|
textColor = colors.lightGray,
|
||||||
|
event = 'slide_hide',
|
||||||
|
},
|
||||||
show = function(self, values)
|
show = function(self, values)
|
||||||
local m = 12
|
local m = 12
|
||||||
for _, v in pairs(values) do
|
for _, v in pairs(values) do
|
||||||
@@ -417,6 +472,72 @@ local page = UI.Page {
|
|||||||
self.grid:setIndex(1)
|
self.grid:setIndex(1)
|
||||||
UI.SlideOut.show(self)
|
UI.SlideOut.show(self)
|
||||||
end,
|
end,
|
||||||
|
eventHandler = function(self, event)
|
||||||
|
if event.type == 'grid_select' then
|
||||||
|
actions.process('insertText', x, y, event.selected.complete)
|
||||||
|
self:hide()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return UI.SlideOut.eventHandler(self, event)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
peripheral = UI.SlideOut {
|
||||||
|
x = '20%', y = 2,
|
||||||
|
transitionHint = 'slideLeft',
|
||||||
|
grid1 = UI.Grid {
|
||||||
|
x = 2, y = 2, ey = 5,
|
||||||
|
sortColumn = 'name',
|
||||||
|
columns = {
|
||||||
|
{ key = 'name', heading = 'Peripheral' },
|
||||||
|
},
|
||||||
|
accelerators = {
|
||||||
|
[ ' ' ] = 'down',
|
||||||
|
backspace = 'slide_hide',
|
||||||
|
grid_focus_row = 'select_peripheral',
|
||||||
|
grid_select = 'complete',
|
||||||
|
},
|
||||||
|
scan = function(self)
|
||||||
|
self.values = { }
|
||||||
|
for k, v in pairs(device) do
|
||||||
|
table.insert(self.values, { name = k, complete = 'peripheral.wrap("' .. v.side .. '")' })
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
postInit = function(self)
|
||||||
|
self:scan()
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
grid2 = UI.Grid {
|
||||||
|
x = 2, y = 6, ey = -2,
|
||||||
|
sortColumn = 'method',
|
||||||
|
columns = {
|
||||||
|
{ key = 'method', heading = 'Method' },
|
||||||
|
},
|
||||||
|
accelerators = {
|
||||||
|
[ ' ' ] = 'down',
|
||||||
|
backspace = 'slide_hide',
|
||||||
|
grid_select = 'complete',
|
||||||
|
},
|
||||||
|
showMethods = function(self)
|
||||||
|
local dev = device[self.parent.grid1:getSelected().name]
|
||||||
|
local t = { }
|
||||||
|
if dev then
|
||||||
|
pcall(function()
|
||||||
|
local docs = dev.getDocs and dev.getDocs()
|
||||||
|
for k, v in pairs(dev) do
|
||||||
|
if type(v) == 'function' then
|
||||||
|
local m = docs and docs[k] and docs[k]:match('^function%((.+)%).+')
|
||||||
|
table.insert(t, { method = k, complete = k .. '(' .. (m or '') .. ')' })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
self:setValues(t)
|
||||||
|
end,
|
||||||
|
enable = function(self)
|
||||||
|
self:showMethods()
|
||||||
|
UI.Grid.enable(self)
|
||||||
|
end,
|
||||||
|
},
|
||||||
cancel = UI.Button {
|
cancel = UI.Button {
|
||||||
y = -1, x = -9,
|
y = -1, x = -9,
|
||||||
text = 'Cancel',
|
text = 'Cancel',
|
||||||
@@ -426,10 +547,16 @@ local page = UI.Page {
|
|||||||
event = 'slide_hide',
|
event = 'slide_hide',
|
||||||
},
|
},
|
||||||
eventHandler = function(self, event)
|
eventHandler = function(self, event)
|
||||||
if event.type == 'grid_select' then
|
if event.type == 'complete' then
|
||||||
actions.process('insertText', x, y, event.selected.complete)
|
actions.process('insertText', x, y, event.selected.complete)
|
||||||
|
actions.process('left')
|
||||||
self:hide()
|
self:hide()
|
||||||
return true
|
return true
|
||||||
|
elseif event.type == 'select_peripheral' then
|
||||||
|
self.grid2:showMethods()
|
||||||
|
self.grid2:setIndex(1)
|
||||||
|
self.grid2:update()
|
||||||
|
self.grid2:draw()
|
||||||
end
|
end
|
||||||
return UI.SlideOut.eventHandler(self, event)
|
return UI.SlideOut.eventHandler(self, event)
|
||||||
end,
|
end,
|
||||||
@@ -527,6 +654,19 @@ local function getFileInfo(path)
|
|||||||
fi.isReadOnly = fs.isReadOnly(fi.abspath)
|
fi.isReadOnly = fs.isReadOnly(fi.abspath)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if abspath ~= config.filename then
|
||||||
|
config.filename = abspath
|
||||||
|
config.recent = config.recent or { }
|
||||||
|
|
||||||
|
Array.removeByValue(config.recent, '/' .. abspath)
|
||||||
|
table.insert(config.recent, 1, '/' .. abspath)
|
||||||
|
while #config.recent > 10 do
|
||||||
|
table.remove(config.recent)
|
||||||
|
end
|
||||||
|
|
||||||
|
Config.update('edit', config)
|
||||||
|
end
|
||||||
|
|
||||||
if multishell then
|
if multishell then
|
||||||
multishell.setTitle(multishell.getCurrent(), fs.getName(fi.path))
|
multishell.setTitle(multishell.getCurrent(), fs.getName(fi.path))
|
||||||
end
|
end
|
||||||
@@ -634,6 +774,7 @@ actions = {
|
|||||||
local last = _remove(undo.chain)
|
local last = _remove(undo.chain)
|
||||||
if last then
|
if last then
|
||||||
undo.active = true
|
undo.active = true
|
||||||
|
table.insert(undo.redo, { })
|
||||||
for i = #last, 1, -1 do
|
for i = #last, 1, -1 do
|
||||||
local u = last[i]
|
local u = last[i]
|
||||||
actions[u.action](_unpack(u.args))
|
actions[u.action](_unpack(u.args))
|
||||||
@@ -645,11 +786,36 @@ actions = {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
undo_add = function(entry)
|
undo_add = function(entry)
|
||||||
local last = undo.chain[#undo.chain]
|
if undo.active then
|
||||||
if last and undo.continue then
|
local last = undo.redo[#undo.redo]
|
||||||
table.insert(last, entry)
|
table.insert(last, entry)
|
||||||
else
|
else
|
||||||
_insert(undo.chain, { entry })
|
if not undo.redo_active then
|
||||||
|
undo.redo = { }
|
||||||
|
end
|
||||||
|
local last = undo.chain[#undo.chain]
|
||||||
|
if last and undo.continue then
|
||||||
|
table.insert(last, entry)
|
||||||
|
else
|
||||||
|
_insert(undo.chain, { entry })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
redo = function()
|
||||||
|
local last = _remove(undo.redo)
|
||||||
|
if last then
|
||||||
|
-- too many flags !
|
||||||
|
undo.redo_active = true
|
||||||
|
undo.continue = false
|
||||||
|
for i = #last, 1, -1 do
|
||||||
|
local u = last[i]
|
||||||
|
actions[u.action](_unpack(u.args))
|
||||||
|
undo.continue = true
|
||||||
|
end
|
||||||
|
undo.redo_active = false
|
||||||
|
else
|
||||||
|
actions.info('already at newest change')
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -675,6 +841,10 @@ actions = {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
peripheral = function()
|
||||||
|
page.peripheral:show()
|
||||||
|
end,
|
||||||
|
|
||||||
refresh = function()
|
refresh = function()
|
||||||
actions.dirty_all()
|
actions.dirty_all()
|
||||||
mark.continue = mark.active
|
mark.continue = mark.active
|
||||||
@@ -734,6 +904,14 @@ actions = {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
recent = function(force)
|
||||||
|
if not force and undo.chain[#undo.chain] ~= lastSave then
|
||||||
|
page.unsaved:show('recent')
|
||||||
|
else
|
||||||
|
page.recent:show()
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
file_new = function(force)
|
file_new = function(force)
|
||||||
if not force and undo.chain[#undo.chain] ~= lastSave then
|
if not force and undo.chain[#undo.chain] ~= lastSave then
|
||||||
page.unsaved:show('file_new')
|
page.unsaved:show('file_new')
|
||||||
@@ -749,7 +927,7 @@ actions = {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
load = function(path)
|
load = function(path)
|
||||||
if fs.exists(path) and fs.isDir(path) then
|
if not path or (fs.exists(path) and fs.isDir(path)) then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
fileInfo = getFileInfo(path)
|
fileInfo = getFileInfo(path)
|
||||||
@@ -760,7 +938,7 @@ actions = {
|
|||||||
lastSave = nil
|
lastSave = nil
|
||||||
dirty = { y = 1, ey = h }
|
dirty = { y = 1, ey = h }
|
||||||
mark = { }
|
mark = { }
|
||||||
undo = { chain = { } }
|
undo = { chain = { }, redo = { } }
|
||||||
|
|
||||||
tLines = Util.readLines(fileInfo.abspath) or { }
|
tLines = Util.readLines(fileInfo.abspath) or { }
|
||||||
if #tLines == 0 then
|
if #tLines == 0 then
|
||||||
@@ -843,6 +1021,10 @@ actions = {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
run = function()
|
run = function()
|
||||||
|
if not multishell then
|
||||||
|
actions.error('open available with multishell')
|
||||||
|
return
|
||||||
|
end
|
||||||
if undo.chain[#undo.chain] == lastSave then
|
if undo.chain[#undo.chain] == lastSave then
|
||||||
local nTask = shell.openTab(fileInfo.abspath)
|
local nTask = shell.openTab(fileInfo.abspath)
|
||||||
if nTask then
|
if nTask then
|
||||||
@@ -1186,21 +1368,17 @@ actions = {
|
|||||||
tLines[y] = tLines[y]:sub(1, x) .. remainder
|
tLines[y] = tLines[y]:sub(1, x) .. remainder
|
||||||
end
|
end
|
||||||
|
|
||||||
if not undo.active then
|
actions.undo_add(
|
||||||
actions.undo_add(
|
{ action = 'deleteText', args = { sx, sy, x, y } })
|
||||||
{ action = 'deleteText', args = { sx, sy, x, y, text } })
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
deleteText = function(sx, sy, ex, ey)
|
deleteText = function(sx, sy, ex, ey)
|
||||||
x = sx
|
x = sx
|
||||||
y = sy
|
y = sy
|
||||||
|
|
||||||
if not undo.active then
|
local text = actions.copyText(sx, sy, ex, ey)
|
||||||
local text = actions.copyText(sx, sy, ex, ey)
|
actions.undo_add(
|
||||||
actions.undo_add(
|
{ action = 'insertText', args = { sx, sy, text } })
|
||||||
{ action = 'insertText', args = { sx, sy, text } })
|
|
||||||
end
|
|
||||||
|
|
||||||
local front = tLines[sy]:sub(1, sx - 1)
|
local front = tLines[sy]:sub(1, sx - 1)
|
||||||
local back = tLines[ey]:sub(ex, #tLines[ey])
|
local back = tLines[ey]:sub(ex, #tLines[ey])
|
||||||
@@ -1252,9 +1430,7 @@ actions = {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
backspace = function()
|
backspace = function()
|
||||||
if mark.active then
|
if mark.active or actions.left() then
|
||||||
actions.delete()
|
|
||||||
elseif actions.left() then
|
|
||||||
actions.delete()
|
actions.delete()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
@@ -1369,7 +1545,7 @@ actions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
if not actions.load(args[1] and args[1] or 'untitled.txt') then
|
if not (actions.load(args[1]) or actions.load(config.filename) or actions.load('untitled.txt')) then
|
||||||
error('Error opening file')
|
error('Error opening file')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ local config = Config.load('saver', {
|
|||||||
timeout = 60,
|
timeout = 60,
|
||||||
})
|
})
|
||||||
|
|
||||||
local tab = UI.Tab {
|
return UI.Tab {
|
||||||
tabTitle = 'Screen Saver',
|
tabTitle = 'Screen Saver',
|
||||||
description = 'Screen saver',
|
description = 'Screen saver',
|
||||||
[1] = UI.Window {
|
[1] = UI.Window {
|
||||||
@@ -38,24 +38,21 @@ local tab = UI.Tab {
|
|||||||
text = 'Apply',
|
text = 'Apply',
|
||||||
event = 'update',
|
event = 'update',
|
||||||
},
|
},
|
||||||
}
|
eventHandler = function(self, event)
|
||||||
|
if event.type =='checkbox_change' then
|
||||||
|
config.enabled = not not event.checked
|
||||||
|
|
||||||
function tab:eventHandler(event)
|
elseif event.type == 'update' then
|
||||||
if event.type =='checkbox_change' then
|
if self.timeout.value then
|
||||||
config.enabled = not not event.checked
|
config.timeout = self.timeout.value
|
||||||
|
Config.update('saver', config)
|
||||||
|
|
||||||
elseif event.type == 'update' then
|
self:emit({ type = 'success_message', message = 'Settings updated' })
|
||||||
if self.timeout.value then
|
os.queueEvent('config_update', 'saver', config)
|
||||||
config.timeout = self.timeout.value
|
else
|
||||||
Config.update('saver', config)
|
self:emit({ type = 'error_message', message = 'Invalid timeout' })
|
||||||
|
end
|
||||||
self:emit({ type = 'success_message', message = 'Settings updated' })
|
|
||||||
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
|
}
|
||||||
|
|
||||||
return tab
|
|
||||||
|
|||||||
Reference in New Issue
Block a user