diff --git a/README.md b/README.md index 2998e4f..750d3f5 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,9 @@ pick_folder(path="") save_file(path=""; filterlist="") ``` -The documentation of every one of these can be consulted in help mode in the REPL -(press `?` to change to help mode, `backspace` to exit), although their names -are really descriptive. +The documentation of every one of these can be consulted in help mode in the +REPL (press `?` to change to help mode, `backspace` to exit), although their +names are really descriptive. ### Path selection @@ -44,10 +44,9 @@ open, by default `path` is set to `""` and the default open point is operating system dependent. The `path` argument accepts `AbstractPath`s from -[FilePathsBase.jl](https://github.com/rofinn/FilePathsBase.jl). It always -returns `String`s given that there is not sensible way to tell the user if the -selection was cancelled with the default behaviour of FilePathsBase.jl (an -empty string is interpreted as the current directory). +[FilePathsBase.jl](https://github.com/rofinn/FilePathsBase.jl). When +a `<:AbstractPath` has been passed it returns `nothing` on cancellations for +every one of the functions. ### File filter lists @@ -73,7 +72,7 @@ julia> pick_file() "/home/suave/primes.c" julia> pick_file(home()) # from FilePathsBase -"/home/suave/donut.c" +p"/home/suave/donut.c" julia> pick_file() "" # cancelled selection diff --git a/src/NativeFileDialog.jl b/src/NativeFileDialog.jl index b1dc2b3..f0fde7e 100644 --- a/src/NativeFileDialog.jl +++ b/src/NativeFileDialog.jl @@ -67,7 +67,13 @@ function pick_file(path = ""; filterlist = "") return out end -pick_file(path::AbstractPath; filterlist = "") = pick_file(string(path); filterlist) +function pick_file(path::AbstractPath; filterlist = "") + outpath = pick_file(string(path); filterlist) + if isempty(outpath) + return nothing + end + Path(outpath) +end """ pick_multi_file(path=""; filterlist="") @@ -108,8 +114,13 @@ function pick_multi_file(path = ""; filterlist = "") return out end -pick_multi_file(path::AbstractPath; filterlist = "") = - pick_multi_file(string(path); filterlist) +function pick_multi_file(path::AbstractPath; filterlist = "") + outpathset = pick_multi_file(string(path); filterlist) + if isempty(outpathset) + return nothing + end + Path.(outpathset) +end """ save_file(path=""; filterlist="") @@ -150,7 +161,13 @@ function save_file(path = ""; filterlist = "") return out end -save_file(path::AbstractPath; filterlist = "") = save_file(string(path); filterlist) +function save_file(path::AbstractPath; filterlist = "") + outpath = save_file(string(path); filterlist) + if isempty(outpath) + return nothing + end + Path(outpath) +end """ pick_folder(path="") @@ -190,6 +207,12 @@ function pick_folder(path = "") return out end -pick_folder(path::AbstractPath) = pick_folder(string(path)) +function pick_folder(path::AbstractPath) + outpath = pick_folder(string(path)) + if isempty(outpath) + return nothing + end + Path(outpath) +end end