refactor out file-choosing functionality of osOpenFileInDir

This commit is contained in:
2021-12-26 22:31:57 -07:00
parent 7db77ab658
commit b6c1677d7f
2 changed files with 11 additions and 8 deletions

View File

@@ -81,6 +81,16 @@
(awaitLet [,v (quickPickMap ,options)]
,@body)))
(function :Void chooseFileInDir [:String->Void openFile :Bool allowNew &opt :String dir]
(withValueOrInputBox dir
(awaitLet [dirOrFile (quickPick (sys.FileSystem.readDirectory dir))]
(let [dirOrFile (joinPath dir dirOrFile)]
(cond
((sys.FileSystem.isDirectory dirOrFile)
(chooseFileInDir openFile allowNew dirOrFile))
(true
(openFile dirOrFile)))))))
// This has to be a macro so it can return from tryLoadConfig
(defMacro trySpawnSync [command args options onError]
`(let [command ,command

View File

@@ -24,11 +24,4 @@
(registerCommand "desired name with [a]ny [b]indings" ->[&opt _] (osOpenFileInDir "path/to/dir"))
*/
(function :Void osOpenFileInDir [&opt :String dir]
(withValueOrInputBox dir
(awaitLet [dirOrFile (quickPick (sys.FileSystem.readDirectory dir))]
(let [dirOrFile (joinPath dir dirOrFile)]
(cond
((sys.FileSystem.isDirectory dirOrFile)
(osOpenFileInDir dirOrFile))
(true
(osOpenFile dirOrFile)))))))
(chooseFileInDir osOpenFile false dir))