Skip to content

Commit

Permalink
improve compatibilitye with FilePaths.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
Suavesito-Olimpiada committed Nov 30, 2021
1 parent ec7824b commit 5e78e60
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
33 changes: 28 additions & 5 deletions src/NativeFileDialog.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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="")
Expand Down Expand Up @@ -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="")
Expand Down Expand Up @@ -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="")
Expand Down Expand Up @@ -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

2 comments on commit 5e78e60

@Suavesito-Olimpiada
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: "Tag with name v0.1.0 already exists and points to a different commit"

Please sign in to comment.