add load functionality (but note that saving is still hardcoded right now)
This commit is contained in:
@@ -117,9 +117,9 @@ struct
|
||||
end
|
||||
| NONE => let val triangles = List.rev acc in OK triangles end
|
||||
|
||||
fun loadTriangles inputMailbox =
|
||||
fun loadTriangles (path, inputMailbox) =
|
||||
let
|
||||
val io = TextIO.openIn filename
|
||||
val io = TextIO.openIn path
|
||||
val triangles = parse (io, [])
|
||||
val _ = TextIO.closeIn io
|
||||
|
||||
@@ -168,36 +168,45 @@ struct
|
||||
()
|
||||
end
|
||||
|
||||
fun getDirList (dir, acc) =
|
||||
fun getDirList (dir, acc, rootPath) =
|
||||
case OS.FileSys.readDir dir of
|
||||
SOME path =>
|
||||
if OS.FileSys.isDir path then
|
||||
getDirList (dir, AppType.IS_FOLDER path :: acc)
|
||||
else if OS.FileSys.isLink path then
|
||||
getDirList (dir, acc)
|
||||
else
|
||||
getDirList (dir, AppType.IS_FILE path :: acc)
|
||||
let
|
||||
val folderPath = String.concat [rootPath, "/", path]
|
||||
in
|
||||
if OS.FileSys.isDir folderPath then
|
||||
getDirList (dir, AppType.IS_FOLDER path :: acc, rootPath)
|
||||
else if OS.FileSys.isLink folderPath then
|
||||
getDirList (dir, acc, rootPath)
|
||||
else
|
||||
getDirList (dir, AppType.IS_FILE path :: acc, rootPath)
|
||||
end
|
||||
| NONE => let val acc = List.rev acc in Vector.fromList acc end
|
||||
|
||||
fun loadFiles (path, inputMailbox) =
|
||||
let
|
||||
val path = if String.size path = 0 then OS.FileSys.getDir () else path
|
||||
val dir = OS.FileSys.openDir path
|
||||
val dirList = getDirList (dir, [])
|
||||
val dirList = getDirList (dir, [], path)
|
||||
val _ = OS.FileSys.closeDir dir
|
||||
val inputMsg = FILE_BROWSER_AND_PATH {fileBrowser = dirList, path = path}
|
||||
in
|
||||
Mailbox.send (inputMailbox, inputMsg)
|
||||
end
|
||||
|
||||
fun selectPath (path, inputMailbox) =
|
||||
if OS.FileSys.isDir path then loadFiles (path, inputMailbox)
|
||||
else loadTriangles (path, inputMailbox)
|
||||
|
||||
fun run (fileMailbox, inputMailbox) =
|
||||
let
|
||||
val _ =
|
||||
case Mailbox.recv fileMailbox of
|
||||
SAVE_TRIANGLES triangles => saveTriangles triangles
|
||||
| LOAD_TRIANGLES => loadTriangles inputMailbox
|
||||
| LOAD_TRIANGLES => loadTriangles (filename, inputMailbox)
|
||||
| EXPORT_TRIANGLES triangles => exportTriangles triangles
|
||||
| LOAD_FILES path => loadFiles (path, inputMailbox)
|
||||
| SELECT_PATH path => selectPath (path, inputMailbox)
|
||||
in
|
||||
run (fileMailbox, inputMailbox)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user