JuliaGraphics / NativeFileDialog.jl

mlabbe/nativefiledialog julia wrapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compatibility with FilePathsBase

alecloudenback opened this issue · comments

I haven't done much heavy lifting with file paths yet, but if I did I understand having a typed file system would be beneficial for reducing errors and improving cross-system compatbility. I'm not sure exactly what it would look like, but compatibility with FilePaths.jl could be useful.

E.g. the following doesn't work:

julia> using FilePathsBase, NativeFileDialog

julia> pick_file(;path=home(), filterlist="")

results in:

julia> pick_file(;path=home(), filterlist="")
ERROR: MethodError: no method matching pointer(::PosixPath)
Closest candidates are:
  pointer(::SuiteSparse.CHOLMOD.Dense{Tv}) where Tv at /Users/sabae/src/julia/usr/share/julia/stdlib/v1.7/SuiteSparse/src/cholmod.jl:358
  pointer(::Random.UnsafeView) at /Users/sabae/src/julia/usr/share/julia/stdlib/v1.7/Random/src/RNGs.jl:501
  pointer(::PermutedDimsArray, ::Integer) at permuteddimsarray.jl:61
  ...
Stacktrace:
 [1] pick_file(; path::PosixPath, filterlist::String)
   @ NativeFileDialog ~/.julia/packages/NativeFileDialog/RzsbC/src/NativeFileDialog.jl:52
 [2] top-level scope
   @ REPL[15]:1

This looks like a great idea. I'll be adding compatibility with FilePaths.jl (but if anyone beat me to it there will be no tears). ;)

Done!

But I'll need to notice that all the function will still return Strings given that String[] and "" are the values to signal the user that the selection was cancelled. FilePathsBase interpret "" as p"." which is the current working directory contrary to throw an error.

I prefer to be able o signal the user that the operation was cancelled instead of returning a (in my perspective) wrong value for the selection. In any case I do think it is not terrible this decision as all that one need to do (after checking for a valid outpt) is a Path.(selection).

An alternative could be to return a Union{AbstractPath,Nothing} and use nothing to signal that the operation was cancelled.

That sounds like a good idea. :)

Done on this commit.