add load functionality (but note that saving is still hardcoded right now)
This commit is contained in:
@@ -364,9 +364,9 @@ struct
|
|||||||
(model, fileMsg)
|
(model, fileMsg)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun useTriangles (model, triangles) =
|
fun useTrianglesInNormalMode (model, triangles) =
|
||||||
let
|
let
|
||||||
val model = AppWith.useTriangles (model, triangles)
|
val model = AppWith.useTrianglesAndSetNormalMode (model, triangles)
|
||||||
val drawVec = Triangles.toVector model
|
val drawVec = Triangles.toVector model
|
||||||
val drawMsg = DRAW_TRIANGLES_AND_RESET_DOTS drawVec
|
val drawMsg = DRAW_TRIANGLES_AND_RESET_DOTS drawVec
|
||||||
val drawMsg = [DRAW drawMsg]
|
val drawMsg = [DRAW drawMsg]
|
||||||
@@ -413,7 +413,7 @@ struct
|
|||||||
| ARROW_DOWN => moveArrowDown model
|
| ARROW_DOWN => moveArrowDown model
|
||||||
| KEY_ENTER => enterOrSpaceCoordinates model
|
| KEY_ENTER => enterOrSpaceCoordinates model
|
||||||
| KEY_SPACE => enterOrSpaceCoordinates model
|
| KEY_SPACE => enterOrSpaceCoordinates model
|
||||||
| USE_TRIANGLES triangles => useTriangles (model, triangles)
|
| USE_TRIANGLES triangles => useTrianglesInNormalMode (model, triangles)
|
||||||
| TRIANGLES_LOAD_ERROR => trianglesLoadError model
|
| TRIANGLES_LOAD_ERROR => trianglesLoadError model
|
||||||
| FILE_BROWSER_AND_PATH {fileBrowser, path} =>
|
| FILE_BROWSER_AND_PATH {fileBrowser, path} =>
|
||||||
handleFileBrowserAndPathInNormalMode (model, fileBrowser, path)
|
handleFileBrowserAndPathInNormalMode (model, fileBrowser, path)
|
||||||
@@ -538,6 +538,25 @@ struct
|
|||||||
redrawFileBrowser model
|
redrawFileBrowser model
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun selectCurrentFileItem model =
|
||||||
|
let
|
||||||
|
val {fileBrowser, fileBrowserIdx, openFilePath, ...} = model
|
||||||
|
in
|
||||||
|
if Vector.length fileBrowser > 0 then
|
||||||
|
let
|
||||||
|
val path =
|
||||||
|
case Vector.sub (fileBrowser, fileBrowserIdx) of
|
||||||
|
IS_FILE str => str
|
||||||
|
| IS_FOLDER str => str
|
||||||
|
val path = String.concat [openFilePath, "/", path]
|
||||||
|
val fileMsg = SELECT_PATH path
|
||||||
|
in
|
||||||
|
(model, [FILE fileMsg])
|
||||||
|
end
|
||||||
|
else
|
||||||
|
(model, [])
|
||||||
|
end
|
||||||
|
|
||||||
fun updateBrowseMode (model: app_type, inputMsg) =
|
fun updateBrowseMode (model: app_type, inputMsg) =
|
||||||
case inputMsg of
|
case inputMsg of
|
||||||
ARROW_UP => browseModeArrowUp model
|
ARROW_UP => browseModeArrowUp model
|
||||||
@@ -545,12 +564,13 @@ struct
|
|||||||
| TRIANGLES_LOAD_ERROR => trianglesLoadError model
|
| TRIANGLES_LOAD_ERROR => trianglesLoadError model
|
||||||
(* todo:
|
(* todo:
|
||||||
| ARROW_LEFT =>
|
| ARROW_LEFT =>
|
||||||
| ARROW_RIGHT =>
|
|
||||||
| KEY_ENTER =>
|
|
||||||
| KEY_SPACE =>
|
|
||||||
*)
|
*)
|
||||||
|
| ARROW_RIGHT => selectCurrentFileItem model
|
||||||
|
| KEY_ENTER => selectCurrentFileItem model
|
||||||
|
| KEY_SPACE => selectCurrentFileItem model
|
||||||
| FILE_BROWSER_AND_PATH {fileBrowser, path} =>
|
| FILE_BROWSER_AND_PATH {fileBrowser, path} =>
|
||||||
handleFileBrowserAndPathInBrowseMode (model, fileBrowser, path)
|
handleFileBrowserAndPathInBrowseMode (model, fileBrowser, path)
|
||||||
|
| USE_TRIANGLES triangles => useTrianglesInNormalMode (model, triangles)
|
||||||
| _ => (model, [])
|
| _ => (model, [])
|
||||||
|
|
||||||
fun update (model: app_type, inputMsg) =
|
fun update (model: app_type, inputMsg) =
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ sig
|
|||||||
* int
|
* int
|
||||||
-> AppType.app_type
|
-> AppType.app_type
|
||||||
|
|
||||||
val useTriangles: AppType.app_type * AppType.triangle list -> AppType.app_type
|
val useTrianglesAndSetNormalMode: AppType.app_type * AppType.triangle list
|
||||||
|
-> AppType.app_type
|
||||||
end
|
end
|
||||||
|
|
||||||
structure AppWith :> APP_WITH =
|
structure AppWith :> APP_WITH =
|
||||||
@@ -559,10 +560,10 @@ struct
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
fun useTriangles (app: app_type, triangles) =
|
fun useTrianglesAndSetNormalMode (app: app_type, triangles) =
|
||||||
let
|
let
|
||||||
val
|
val
|
||||||
{ mode
|
{ mode = _
|
||||||
, xClickPoints
|
, xClickPoints
|
||||||
, yClickPoints
|
, yClickPoints
|
||||||
, numClickPoints
|
, numClickPoints
|
||||||
@@ -584,7 +585,7 @@ struct
|
|||||||
|
|
||||||
val triangleStage = NO_TRIANGLE
|
val triangleStage = NO_TRIANGLE
|
||||||
in
|
in
|
||||||
{ mode = mode
|
{ mode = AppType.NORMAL_MODE
|
||||||
, triangleStage = triangleStage
|
, triangleStage = triangleStage
|
||||||
, triangles = triangles
|
, triangles = triangles
|
||||||
, undo = []
|
, undo = []
|
||||||
|
|||||||
@@ -117,9 +117,9 @@ struct
|
|||||||
end
|
end
|
||||||
| NONE => let val triangles = List.rev acc in OK triangles end
|
| NONE => let val triangles = List.rev acc in OK triangles end
|
||||||
|
|
||||||
fun loadTriangles inputMailbox =
|
fun loadTriangles (path, inputMailbox) =
|
||||||
let
|
let
|
||||||
val io = TextIO.openIn filename
|
val io = TextIO.openIn path
|
||||||
val triangles = parse (io, [])
|
val triangles = parse (io, [])
|
||||||
val _ = TextIO.closeIn io
|
val _ = TextIO.closeIn io
|
||||||
|
|
||||||
@@ -168,36 +168,45 @@ struct
|
|||||||
()
|
()
|
||||||
end
|
end
|
||||||
|
|
||||||
fun getDirList (dir, acc) =
|
fun getDirList (dir, acc, rootPath) =
|
||||||
case OS.FileSys.readDir dir of
|
case OS.FileSys.readDir dir of
|
||||||
SOME path =>
|
SOME path =>
|
||||||
if OS.FileSys.isDir path then
|
let
|
||||||
getDirList (dir, AppType.IS_FOLDER path :: acc)
|
val folderPath = String.concat [rootPath, "/", path]
|
||||||
else if OS.FileSys.isLink path then
|
in
|
||||||
getDirList (dir, acc)
|
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
|
else
|
||||||
getDirList (dir, AppType.IS_FILE path :: acc)
|
getDirList (dir, AppType.IS_FILE path :: acc, rootPath)
|
||||||
|
end
|
||||||
| NONE => let val acc = List.rev acc in Vector.fromList acc end
|
| NONE => let val acc = List.rev acc in Vector.fromList acc end
|
||||||
|
|
||||||
fun loadFiles (path, inputMailbox) =
|
fun loadFiles (path, inputMailbox) =
|
||||||
let
|
let
|
||||||
val path = if String.size path = 0 then OS.FileSys.getDir () else path
|
val path = if String.size path = 0 then OS.FileSys.getDir () else path
|
||||||
val dir = OS.FileSys.openDir path
|
val dir = OS.FileSys.openDir path
|
||||||
val dirList = getDirList (dir, [])
|
val dirList = getDirList (dir, [], path)
|
||||||
val _ = OS.FileSys.closeDir dir
|
val _ = OS.FileSys.closeDir dir
|
||||||
val inputMsg = FILE_BROWSER_AND_PATH {fileBrowser = dirList, path = path}
|
val inputMsg = FILE_BROWSER_AND_PATH {fileBrowser = dirList, path = path}
|
||||||
in
|
in
|
||||||
Mailbox.send (inputMailbox, inputMsg)
|
Mailbox.send (inputMailbox, inputMsg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun selectPath (path, inputMailbox) =
|
||||||
|
if OS.FileSys.isDir path then loadFiles (path, inputMailbox)
|
||||||
|
else loadTriangles (path, inputMailbox)
|
||||||
|
|
||||||
fun run (fileMailbox, inputMailbox) =
|
fun run (fileMailbox, inputMailbox) =
|
||||||
let
|
let
|
||||||
val _ =
|
val _ =
|
||||||
case Mailbox.recv fileMailbox of
|
case Mailbox.recv fileMailbox of
|
||||||
SAVE_TRIANGLES triangles => saveTriangles triangles
|
SAVE_TRIANGLES triangles => saveTriangles triangles
|
||||||
| LOAD_TRIANGLES => loadTriangles inputMailbox
|
| LOAD_TRIANGLES => loadTriangles (filename, inputMailbox)
|
||||||
| EXPORT_TRIANGLES triangles => exportTriangles triangles
|
| EXPORT_TRIANGLES triangles => exportTriangles triangles
|
||||||
| LOAD_FILES path => loadFiles (path, inputMailbox)
|
| LOAD_FILES path => loadFiles (path, inputMailbox)
|
||||||
|
| SELECT_PATH path => selectPath (path, inputMailbox)
|
||||||
in
|
in
|
||||||
run (fileMailbox, inputMailbox)
|
run (fileMailbox, inputMailbox)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ sig
|
|||||||
| LOAD_TRIANGLES
|
| LOAD_TRIANGLES
|
||||||
| EXPORT_TRIANGLES of AppType.triangle list
|
| EXPORT_TRIANGLES of AppType.triangle list
|
||||||
| LOAD_FILES of string
|
| LOAD_FILES of string
|
||||||
|
| SELECT_PATH of string
|
||||||
end
|
end
|
||||||
|
|
||||||
structure FileMessage :> FILE_MESSAGE =
|
structure FileMessage :> FILE_MESSAGE =
|
||||||
@@ -14,4 +15,5 @@ struct
|
|||||||
| LOAD_TRIANGLES
|
| LOAD_TRIANGLES
|
||||||
| EXPORT_TRIANGLES of AppType.triangle list
|
| EXPORT_TRIANGLES of AppType.triangle list
|
||||||
| LOAD_FILES of string
|
| LOAD_FILES of string
|
||||||
|
| SELECT_PATH of string
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user