From 6e01a9660f456411ea6cd4f3dd985600f329869a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laurent?= <francois.laurent@posteo.net> Date: Wed, 29 Jan 2025 13:27:48 +0100 Subject: [PATCH] feat: file uploads --- src/editor.jl | 8 +++++++- src/files.jl | 6 ++++-- src/plots.jl | 3 ++- src/wgl.jl | 5 +++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/editor.jl b/src/editor.jl index abf8b40..f60d995 100644 --- a/src/editor.jl +++ b/src/editor.jl @@ -35,6 +35,8 @@ function larvaeditor(path=nothing; backend_directory::AbstractString=projectdir, manualtag::Union{Nothing, String, Symbol}="edited", title="LarvaTagger", + root_directory=nothing, + enable_uploads=false, kwargs...) # to (re-)load a file, the app is reloaded with the filepath as sole information @@ -47,6 +49,10 @@ function larvaeditor(path=nothing; # used for method dispatch (here `Session` is taken to represent Bonito) controller[:frontend] = Session + if !isnothing(root_directory) + controller[:workingdirectory] = workingdir(controller, root_directory) + end + tryopenfile(controller, input) editor = EditorView(larvaviewer(controller; @@ -56,7 +62,7 @@ function larvaeditor(path=nothing; larvafilter(controller), tagfilter(controller; manualtag=manualtag), metadataeditor(controller), - filemenu(controller), + filemenu(controller; upload_button=enable_uploads), backendmenu(controller, backend_directory), loadanimation(controller), twooptiondialog(controller)) diff --git a/src/files.jl b/src/files.jl index 397c781..aa2e3d1 100644 --- a/src/files.jl +++ b/src/files.jl @@ -7,7 +7,9 @@ struct WorkingDirectory content::Observable{Vector{String}} end -WorkingDirectory(controller, root::String, path::String="") = WorkingDirectory(controller, root, Validator(path), Observable(String[])) +function WorkingDirectory(controller, root::String, path::String="") + WorkingDirectory(controller, root, Validator(path), Observable(String[])) +end function workingdir(controller, root::String, path::String=""; secure::Bool=true) if secure @@ -107,7 +109,7 @@ function tryopenfile(controller, path; reload::Bool=false) @info "Cannot load file" file=path return elseif haskey(hub, :input) - hub[:input][] = isabspath(path) ? relpath(path) : path + hub[:input][] = path end # tag_lut fallback_color = theme[:LarvaPlot][:fallback_color] diff --git a/src/plots.jl b/src/plots.jl index 4a76a07..19cfa30 100644 --- a/src/plots.jl +++ b/src/plots.jl @@ -562,7 +562,8 @@ function DecoratedLarvae(larvae::Vector{DecoratedLarva}) @assert hovering_active[] i = current_larva[] if i == j - @warn "moving too fast? - please file an issue at https://gitlab.pasteur.fr/nyx/larvatagger.jl/-/issues" + @warn "Moving too fast?" + return end if 0 < i i_decorated = larvae[i].decorated diff --git a/src/wgl.jl b/src/wgl.jl index 9bdb2a7..f20f9a2 100644 --- a/src/wgl.jl +++ b/src/wgl.jl @@ -902,10 +902,10 @@ struct FileMenu browser::FileBrowser end -function filemenu(controller; kwargs...) +function filemenu(controller; upload_button=false, kwargs...) wd = getworkingdir(controller) dir = joinpath(wd.root, wd.path[]) - browser = FileBrowser(dir; root=wd.root, upload_button=false) + browser = FileBrowser(dir; root=wd.root, upload_button=upload_button) on(FileBrowsers.selectedfile(browser)) do file tryopenfile(controller, file; reload=true) end @@ -920,6 +920,7 @@ function filemenu(controller; kwargs...) on(FilePickers.uploadedfile(browser)) do fileinfo filepath = joinpath(workingdir[], fileinfo["name"]) saveinputfile(filepath, fileinfo["content"]) + notify(workingdir) end end return FileMenu(gethub(controller), browser) -- GitLab