Skip to content

Commit 5e78e60

Browse files
improve compatibilitye with FilePaths.jl
1 parent ec7824b commit 5e78e60

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ pick_folder(path="")
3333
save_file(path=""; filterlist="")
3434
```
3535

36-
The documentation of every one of these can be consulted in help mode in the REPL
37-
(press `?` to change to help mode, `backspace` to exit), although their names
38-
are really descriptive.
36+
The documentation of every one of these can be consulted in help mode in the
37+
REPL (press `?` to change to help mode, `backspace` to exit), although their
38+
names are really descriptive.
3939

4040
### Path selection
4141

@@ -44,10 +44,9 @@ open, by default `path` is set to `""` and the default open point is operating
4444
system dependent.
4545

4646
The `path` argument accepts `AbstractPath`s from
47-
[FilePathsBase.jl](https://github.com/rofinn/FilePathsBase.jl). It always
48-
returns `String`s given that there is not sensible way to tell the user if the
49-
selection was cancelled with the default behaviour of FilePathsBase.jl (an
50-
empty string is interpreted as the current directory).
47+
[FilePathsBase.jl](https://github.com/rofinn/FilePathsBase.jl). When
48+
a `<:AbstractPath` has been passed it returns `nothing` on cancellations for
49+
every one of the functions.
5150

5251
### File filter lists
5352

@@ -73,7 +72,7 @@ julia> pick_file()
7372
"/home/suave/primes.c"
7473

7574
julia> pick_file(home()) # from FilePathsBase
76-
"/home/suave/donut.c"
75+
p"/home/suave/donut.c"
7776

7877
julia> pick_file()
7978
"" # cancelled selection

src/NativeFileDialog.jl

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ function pick_file(path = ""; filterlist = "")
6767
return out
6868
end
6969

70-
pick_file(path::AbstractPath; filterlist = "") = pick_file(string(path); filterlist)
70+
function pick_file(path::AbstractPath; filterlist = "")
71+
outpath = pick_file(string(path); filterlist)
72+
if isempty(outpath)
73+
return nothing
74+
end
75+
Path(outpath)
76+
end
7177

7278
"""
7379
pick_multi_file(path=""; filterlist="")
@@ -108,8 +114,13 @@ function pick_multi_file(path = ""; filterlist = "")
108114
return out
109115
end
110116

111-
pick_multi_file(path::AbstractPath; filterlist = "") =
112-
pick_multi_file(string(path); filterlist)
117+
function pick_multi_file(path::AbstractPath; filterlist = "")
118+
outpathset = pick_multi_file(string(path); filterlist)
119+
if isempty(outpathset)
120+
return nothing
121+
end
122+
Path.(outpathset)
123+
end
113124

114125
"""
115126
save_file(path=""; filterlist="")
@@ -150,7 +161,13 @@ function save_file(path = ""; filterlist = "")
150161
return out
151162
end
152163

153-
save_file(path::AbstractPath; filterlist = "") = save_file(string(path); filterlist)
164+
function save_file(path::AbstractPath; filterlist = "")
165+
outpath = save_file(string(path); filterlist)
166+
if isempty(outpath)
167+
return nothing
168+
end
169+
Path(outpath)
170+
end
154171

155172
"""
156173
pick_folder(path="")
@@ -190,6 +207,12 @@ function pick_folder(path = "")
190207
return out
191208
end
192209

193-
pick_folder(path::AbstractPath) = pick_folder(string(path))
210+
function pick_folder(path::AbstractPath)
211+
outpath = pick_folder(string(path))
212+
if isempty(outpath)
213+
return nothing
214+
end
215+
Path(outpath)
216+
end
194217

195218
end

0 commit comments

Comments
 (0)