1
0
mirror of https://github.com/20kdc/OC-KittenOS.git synced 2024-11-23 02:48:06 +11:00

r8: Yet another release for a single feature request

This isn't getting pushed until AmandaC's tested it.
I'm not sure this is such a good idea, anyway ; if it's for load/save
 workflow improvements, wouldn't it be better to have a file access method
 that allows for file re-opening?
That said, there's a limit to *that* before you just have to say,
 "Just use /data/".
This commit is contained in:
20kdc 2018-12-23 23:51:30 +00:00
parent 375995c2d3
commit 0d9583fcff
11 changed files with 80 additions and 67 deletions

View File

@ -3,7 +3,7 @@
return {
["neo"] = {
desc = "KittenOS NEO Kernel & Base Libs",
v = 5,
v = 8,
deps = {
},
dirs = {
@ -67,7 +67,7 @@ return {
},
["neo-icecap"] = {
desc = "KittenOS NEO / Icecap",
v = 7,
v = 8,
deps = {
"neo"
},
@ -125,7 +125,7 @@ return {
},
["neo-logo"] = {
desc = "KittenOS NEO Logo (data)",
v = 6,
v = 8,
deps = {
},
dirs = {

View File

@ -24,7 +24,7 @@ return {
},
["neo-docs"] = {
desc = "KittenOS NEO system documentation",
v = 5,
v = 8,
deps = {
"zzz-license-pd"
},

View File

@ -109,17 +109,20 @@ donkonitDFProvider(function (pkg, pid, sendSig)
end
end
return {
showFileDialogAsync = function (forWrite)
showFileDialogAsync = function (forWrite, defName)
if not rawequal(forWrite, nil) then
require("sys-filewrap").ensureMode(forWrite)
end
if not rawequal(defName, nil) then
defName = tostring(defName)
end
-- Not hooked into the event API, so can't safely interfere
-- Thus, this is async and uses a return event.
local tag = {}
neo.scheduleTimer(0)
table.insert(todo, function ()
-- sys-filedialog is yet another "library to control memory usage".
local closer = require("sys-filedialog")(event, nexus, function (res) openHandles[tag] = nil sendSig("filedialog", tag, res) end, neo.requireAccess("c.filesystem", "file managers"), pkg, forWrite)
local closer = require("sys-filedialog")(event, nexus, function (res) openHandles[tag] = nil sendSig("filedialog", tag, res) end, neo.requireAccess("c.filesystem", "file managers"), pkg, forWrite, defName)
openHandles[tag] = closer
end)
return tag

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -25,7 +25,7 @@ newNeoux = function (event, neo)
end
end)
local neoux = {}
neoux.fileDialog = function (forWrite, callback)
neoux.fileDialog = function (forWrite, callback, dfn)
local sync = false
local rtt = nil
if not callback then
@ -35,7 +35,7 @@ newNeoux = function (event, neo)
rtt = rt
end
end
local tag = neo.requireAccess("x.neo.pub.base", "filedialog").showFileDialogAsync(forWrite)
local tag = neo.requireAccess("x.neo.pub.base", "filedialog").showFileDialogAsync(forWrite, dfn)
local f
f = function (_, fd, tg, re)
if fd == "filedialog" then

View File

@ -2,7 +2,7 @@
-- No warranty is provided, implied or otherwise.
-- just don't bother with proper indent here
return function (event, nexus, retFunc, fs, pkg, mode)
return function (event, nexus, retFunc, fs, pkg, mode, defName)
local fmt = require("fmttext")
local class = "manage"
@ -141,7 +141,7 @@ end
nexus.create(w, h, class .. " " .. pkg, function (w, ev, a, b, c)
if not wnd then
wnd = w
prepareNode(require("sys-filevfs")(fs, mode))
prepareNode(require("sys-filevfs")(fs, mode, defName))
end
if ev == "key" then
key2(a, b, c)

View File

@ -16,12 +16,12 @@ end
local getFsNode, getRoot
local setupCopyNode
function setupCopyNode(parent, myRoot, op, complete, impliedName)
function setupCopyNode(parent, myRoot, op, complete)
local function handleResult(aRes, res)
if aRes then
return complete(res, true)
else
return nil, setupCopyNode(parent, res, op, complete, impliedName)
return nil, setupCopyNode(parent, res, op, complete)
end
end
return {
@ -32,11 +32,6 @@ function setupCopyNode(parent, myRoot, op, complete, impliedName)
complete(nil, false)
return false, parent
end})
if impliedName and myRoot.unknownAvailable then
table.insert(l, {"Implied: " .. impliedName, function ()
return handleResult(myRoot.selectUnknown(impliedName))
end})
end
for _, v in ipairs(myRoot.list()) do
table.insert(l, {v[1], function ()
return handleResult(v[2]())
@ -54,7 +49,7 @@ local function setupCopyVirtualEnvironment(fs, parent, fwrap, impliedName)
if not fwrap then
return false, dialog("Could not open source", parent)
end
local myRoot = getRoot(fs, true)
local myRoot = getRoot(fs, true, impliedName)
-- Setup wrapping node
return setupCopyNode(parent, myRoot, "Copy", function (fwrap2, intent)
if not fwrap2 then
@ -72,14 +67,22 @@ local function setupCopyVirtualEnvironment(fs, parent, fwrap, impliedName)
fwrap.close()
fwrap2.close()
return false, dialog("Completed copy.", parent)
end, impliedName)
end)
end
function getFsNode(fs, parent, fsc, path, mode)
function getFsNode(fs, parent, fsc, path, mode, impliedName)
local va = fsc.address:sub(1, 4)
local fscrw = not fsc.isReadOnly()
local dir = path:sub(#path, #path) == "/"
local confirmedDel = false
local t
local function selectUnknown(text)
-- Relies on text being nil if used in leaf node
local rt, re = require("sys-filewrap").create(fsc, path .. (text or ""), mode)
if not rt then
return false, dialog("Open Error: " .. tostring(re), parent)
end
return true, rt
end
t = {
name = ((dir and "DIR: ") or "FILE: ") .. va .. path,
list = function ()
@ -94,18 +97,9 @@ function getFsNode(fs, parent, fsc, path, mode)
if fsc.isDirectory(fp) then
nm = "D: " .. v
end
n[k + 1] = {nm, function () return nil, getFsNode(fs, t, fsc, fp, mode) end}
n[k + 1] = {nm, function () return nil, getFsNode(fs, t, fsc, fp, mode, impliedName) end}
end
end
if not dir then
table.insert(n, {"Copy", function ()
local rt, re = require("sys-filewrap").create(fsc, path, false)
if not rt then
return false, dialog("Open Error: " .. tostring(re), parent)
end
return nil, setupCopyVirtualEnvironment(fs, parent, rt, path:match("[^/]*$") or "")
end})
end
if fscrw then
if dir then
table.insert(n, {"Mk. Directory", function ()
@ -156,37 +150,38 @@ function getFsNode(fs, parent, fsc, path, mode)
end})
end
end
if (fscrw or mode == false) and mode ~= nil then
local tx = "Open"
if mode == true then
tx = "Save"
elseif mode == "append" then
tx = "Append"
end
if fscrw or mode == false then
table.insert(n, {tx, function ()
local rt, re = require("sys-filewrap").create(fsc, path, mode)
if not rt then
return false, dialog("Open Error: " .. tostring(re), parent)
end
return true, rt
end})
if not dir then
table.insert(n, {"Copy", function ()
local rt, re = require("sys-filewrap").create(fsc, path, false)
if not rt then
return false, dialog("Open Error: " .. tostring(re), parent)
end
return nil, setupCopyVirtualEnvironment(fs, parent, rt, path:match("[^/]*$") or "")
end})
if (fscrw or mode == false) and (mode ~= nil) then
local tx = "Open"
if mode == true then
tx = "Save (Overwrite)"
elseif mode == "append" then
tx = "Append"
end
if fscrw or mode == false then
table.insert(n, {tx, selectUnknown})
end
end
elseif impliedName then
table.insert(n, {"Implied: " .. impliedName, function ()
return selectUnknown(impliedName)
end})
end
return n
end,
unknownAvailable = dir and (mode ~= nil) and ((mode == false) or fscrw),
selectUnknown = function (text)
local rt, re = require("sys-filewrap").create(fsc, path .. text, mode)
if not rt then
return false, dialog("Open Error: " .. tostring(re), parent)
end
return true, rt
end
selectUnknown = selectUnknown
}
return t
end
function getRoot(fs, mode)
function getRoot(fs, mode, defName)
local t
t = {
name = "DRVS:",
@ -210,7 +205,7 @@ function getRoot(fs, mode)
id = "RW " .. amount .. "% " .. mb .. "M " .. id
end
table.insert(l, {fsi.address:sub(1, 4) .. " " .. id, function ()
return nil, getFsNode(fs, t, fsi, "/", mode)
return nil, getFsNode(fs, t, fsi, "/", mode, defName)
end})
end
return l

View File

@ -34,8 +34,12 @@ while blk ~= "" do
break
end
local pm = p - 1
bestData = string.char(128 + lm, math.floor(pm / 256), pm % 256)
bestRes = pfx
local thirdByte = pm % 256
-- anti ']'-corruption helper
if thirdByte ~= 93 then
bestData = string.char(128 + lm, math.floor(pm / 256), thirdByte)
bestRes = pfx
end
end
-- ok, encode!
io.write(bestData)

View File

@ -15,10 +15,12 @@ The mode you give to it can be one of
true: Write "wb"
"append": Append "ab"
May have some readability
propertiues - just in
properties - just in
case, I've added 'read',
but don't get your hopes
up...
"access": Like read, but can be
re-opened for write.
It returns two things - a table, that
being the file object, and the
@ -37,7 +39,9 @@ The possible functions are:
[aw] write(data): Writes to the
file.
[arw] read(data): Reads from the
file.
file. data is the byte count.
However, "*a" is valid here.
Other string-based options are not.
NOTE: Some of these may not actually
work. They're just there as more or

View File

@ -33,16 +33,19 @@ The most reliable reference on the
Main functions:
fileDialog(mode[, callback]):
neoux.fileDialog(mode, [callback],
[dfn]):
Creates a file dialog, returning a
file wrapper (see ul-fwrap) on
success, or nil on failure.
If a callback is given, then nil is
If callback isn't nil, then nil is
always returned immediately, and
the callback is called when the
dialog has shown.
the callback is called with the
result when the dialog is closed.
mode is the mode used for the file,
so see ul-fwrap for values.
dfn is, if not nil, the default
'implied' filename (as with Copy).
neoux.create(w, h, title, callback):
Creates a window,

View File

@ -57,11 +57,15 @@ Paths for the IO parts of this API
the standard KittenOS NEO path
safety rules in the kernel.
showFileDialogAsync(mode): Shows a
filedialog with a given filemode,
or nil for "none". Returns a new,
empty table as a "tag", and emits a
"filedialog" event on completion.
showFileDialogAsync(mode, dfn):
Shows a filedialog with a given
filemode, or nil for "none".
Returns a new, empty table as a
"tag", and emits a "filedialog"
event on completion.
dfn meanwhile adds an 'Implied'
button for reasonable default file
names.
myApi: A string such as "svc.abc"
for the program svc-abc, used for