editor path issues
This commit is contained in:
@@ -21,7 +21,7 @@ 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 config = Config.load('editor')
|
||||||
|
|
||||||
local x, y = 1, 1
|
local x, y = 1, 1
|
||||||
local w, h = term.getSize()
|
local w, h = term.getSize()
|
||||||
@@ -241,7 +241,7 @@ local page = UI.Page {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
show = function(self)
|
show = function(self)
|
||||||
self.filename:setValue(fileInfo.abspath)
|
self.filename:setValue(fileInfo.path)
|
||||||
self.filename:setPosition(#self.filename.value)
|
self.filename:setPosition(#self.filename.value)
|
||||||
UI.MiniSlideOut.show(self)
|
UI.MiniSlideOut.show(self)
|
||||||
end,
|
end,
|
||||||
@@ -289,7 +289,7 @@ local page = UI.Page {
|
|||||||
modal = true,
|
modal = true,
|
||||||
enable = function() end,
|
enable = function() end,
|
||||||
show = function(self)
|
show = function(self)
|
||||||
UI.FileSelect.enable(self, fs.getDir(fileInfo.abspath))
|
UI.FileSelect.enable(self, fs.getDir(fileInfo.path))
|
||||||
self:focusFirst()
|
self:focusFirst()
|
||||||
self:draw()
|
self:draw()
|
||||||
self:addTransition('expandUp', { easing = 'outBounce', ticks = 12 })
|
self:addTransition('expandUp', { easing = 'outBounce', ticks = 12 })
|
||||||
@@ -305,7 +305,6 @@ local page = UI.Page {
|
|||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
recent = UI.SlideOut {
|
recent = UI.SlideOut {
|
||||||
transitionHint = 'expandUp',
|
|
||||||
grid = UI.Grid {
|
grid = UI.Grid {
|
||||||
x = 2, y = 2, ey = -4, ex = -2,
|
x = 2, y = 2, ey = -4, ex = -2,
|
||||||
columns = {
|
columns = {
|
||||||
@@ -402,7 +401,7 @@ local page = UI.Page {
|
|||||||
name = f,
|
name = f,
|
||||||
dir = dir,
|
dir = dir,
|
||||||
lname = f:lower(),
|
lname = f:lower(),
|
||||||
fullName = '/' .. fullName,
|
fullName = fullName,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -565,12 +564,10 @@ local page = UI.Page {
|
|||||||
y = 2,
|
y = 2,
|
||||||
backgroundColor = colors.black,
|
backgroundColor = colors.black,
|
||||||
transitionHint = 'slideRight',
|
transitionHint = 'slideRight',
|
||||||
|
cursorBlink = true,
|
||||||
focus = function(self)
|
focus = function(self)
|
||||||
if self.focused then
|
if self.focused then
|
||||||
self:setCursorPos(x - scrollX, y - scrollY)
|
self:setCursorPos(x - scrollX, y - scrollY)
|
||||||
self:setCursorBlink(true)
|
|
||||||
else
|
|
||||||
self:setCursorBlink(false)
|
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
resize = function(self)
|
resize = function(self)
|
||||||
@@ -639,32 +636,26 @@ local page = UI.Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local function getFileInfo(path)
|
local function getFileInfo(path)
|
||||||
local abspath = shell.resolve(path)
|
path = fs.combine('/', path)
|
||||||
|
|
||||||
local fi = {
|
local fi = {
|
||||||
abspath = abspath,
|
|
||||||
path = path,
|
path = path,
|
||||||
isNew = not fs.exists(abspath),
|
isNew = not fs.exists(path),
|
||||||
dirExists = fs.exists(fs.getDir(abspath)),
|
dirExists = fs.exists(fs.getDir(path)),
|
||||||
modified = false,
|
isReadOnly = fs.isReadOnly(path),
|
||||||
}
|
}
|
||||||
if fi.isDir then
|
|
||||||
fi.isReadOnly = true
|
|
||||||
else
|
|
||||||
fi.isReadOnly = fs.isReadOnly(fi.abspath)
|
|
||||||
end
|
|
||||||
|
|
||||||
if abspath ~= config.filename then
|
if path ~= config.filename then
|
||||||
config.filename = abspath
|
config.filename = path
|
||||||
config.recent = config.recent or { }
|
config.recent = config.recent or { }
|
||||||
|
|
||||||
Array.removeByValue(config.recent, '/' .. abspath)
|
Array.removeByValue(config.recent, path)
|
||||||
table.insert(config.recent, 1, '/' .. abspath)
|
table.insert(config.recent, 1, path)
|
||||||
while #config.recent > 10 do
|
while #config.recent > 10 do
|
||||||
table.remove(config.recent)
|
table.remove(config.recent)
|
||||||
end
|
end
|
||||||
|
|
||||||
Config.update('edit', config)
|
Config.update('editor', config)
|
||||||
end
|
end
|
||||||
|
|
||||||
if multishell then
|
if multishell then
|
||||||
@@ -940,7 +931,7 @@ actions = {
|
|||||||
mark = { }
|
mark = { }
|
||||||
undo = { chain = { }, redo = { } }
|
undo = { chain = { }, redo = { } }
|
||||||
|
|
||||||
tLines = Util.readLines(fileInfo.abspath) or { }
|
tLines = Util.readLines(fileInfo.path) or { }
|
||||||
if #tLines == 0 then
|
if #tLines == 0 then
|
||||||
_insert(tLines, '')
|
_insert(tLines, '')
|
||||||
end
|
end
|
||||||
@@ -976,17 +967,17 @@ actions = {
|
|||||||
end
|
end
|
||||||
elseif fileInfo.isReadOnly then
|
elseif fileInfo.isReadOnly then
|
||||||
actions.info('"%s" [readonly] %dL, %dC',
|
actions.info('"%s" [readonly] %dL, %dC',
|
||||||
name, #tLines, fs.getSize(fileInfo.abspath))
|
name, #tLines, fs.getSize(fileInfo.path))
|
||||||
else
|
else
|
||||||
actions.info('"%s" %dL, %dC',
|
actions.info('"%s" %dL, %dC',
|
||||||
name, #tLines, fs.getSize(fileInfo.abspath))
|
name, #tLines, fs.getSize(fileInfo.path))
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
|
||||||
save = function(filename)
|
save = function(filename)
|
||||||
filename = filename or fileInfo.abspath
|
filename = filename or fileInfo.path
|
||||||
if fs.isReadOnly(filename) then
|
if fs.isReadOnly(filename) then
|
||||||
actions.error("access denied")
|
actions.error("access denied")
|
||||||
else
|
else
|
||||||
@@ -1000,7 +991,7 @@ actions = {
|
|||||||
lastSave = undo.chain[#undo.chain]
|
lastSave = undo.chain[#undo.chain]
|
||||||
fileInfo = getFileInfo(filename)
|
fileInfo = getFileInfo(filename)
|
||||||
actions.info('"%s" %dL, %dC written',
|
actions.info('"%s" %dL, %dC written',
|
||||||
fileInfo.path, #tLines, fs.getSize(fileInfo.abspath))
|
fileInfo.path, #tLines, fs.getSize(fileInfo.path))
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
actions.error(m)
|
actions.error(m)
|
||||||
@@ -1026,19 +1017,19 @@ actions = {
|
|||||||
return
|
return
|
||||||
end
|
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.path)
|
||||||
if nTask then
|
if nTask then
|
||||||
shell.switchTab(nTask)
|
shell.switchTab(nTask)
|
||||||
else
|
else
|
||||||
actions.error("error starting Task")
|
actions.error("error starting Task")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local fn, msg = load(_concat(tLines, '\n'), fileInfo.abspath)
|
local fn, msg = load(_concat(tLines, '\n'), fileInfo.path)
|
||||||
if fn then
|
if fn then
|
||||||
multishell.openTab({
|
multishell.openTab({
|
||||||
fn = fn,
|
fn = fn,
|
||||||
focused = true,
|
focused = true,
|
||||||
title = fs.getName(fileInfo.abspath),
|
title = fs.getName(fileInfo.path),
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
local ln = msg:match(':(%d+):')
|
local ln = msg:match(':(%d+):')
|
||||||
@@ -1053,7 +1044,7 @@ actions = {
|
|||||||
status = function()
|
status = function()
|
||||||
local modified = undo.chain[#undo.chain] == lastSave and '' or '[Modified] '
|
local modified = undo.chain[#undo.chain] == lastSave and '' or '[Modified] '
|
||||||
actions.info('"%s" %s%d lines --%d%%--',
|
actions.info('"%s" %s%d lines --%d%%--',
|
||||||
fileInfo.abspath, modified, #tLines,
|
fileInfo.path, modified, #tLines,
|
||||||
math.floor((y - 1) / (#tLines - 1) * 100))
|
math.floor((y - 1) / (#tLines - 1) * 100))
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -1229,10 +1220,10 @@ actions = {
|
|||||||
local screenY = y - scrollY
|
local screenY = y - scrollY
|
||||||
|
|
||||||
if screenX < 1 then
|
if screenX < 1 then
|
||||||
scrollX = x - 1
|
scrollX = math.max(0, x - 4)
|
||||||
actions.dirty_all()
|
actions.dirty_all()
|
||||||
elseif screenX > w then
|
elseif screenX > w then
|
||||||
scrollX = x - w
|
scrollX = x - w + 3
|
||||||
actions.dirty_all()
|
actions.dirty_all()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1545,7 +1536,8 @@ actions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
if not (actions.load(args[1]) or actions.load(config.filename) or actions.load('untitled.txt')) then
|
local filename = args[1] and shell.resolve(args[1])
|
||||||
|
if not (actions.load(filename) or actions.load(config.filename) or actions.load('untitled.txt')) then
|
||||||
error('Error opening file')
|
error('Error opening file')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -134,15 +134,17 @@ end
|
|||||||
recTerm = multishell.term
|
recTerm = multishell.term
|
||||||
|
|
||||||
for key, func in pairs(oldTerm) do
|
for key, func in pairs(oldTerm) do
|
||||||
recTerm[key] = function(...)
|
if type(func) == 'function' then
|
||||||
local result = { func(...) }
|
recTerm[key] = function(...)
|
||||||
|
local result = { func(...) }
|
||||||
|
|
||||||
if callCount == 0 then
|
if callCount == 0 then
|
||||||
os.queueEvent('capture_frame')
|
os.queueEvent('capture_frame')
|
||||||
|
end
|
||||||
|
callCount = callCount + 1
|
||||||
|
curCalls[callCount] = { key, ... }
|
||||||
|
return unpack(result)
|
||||||
end
|
end
|
||||||
callCount = callCount + 1
|
|
||||||
curCalls[callCount] = { key, ... }
|
|
||||||
return unpack(result)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user