From dd211196b0a3e4c9913462c015e7b6ed64052adb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laurent?= <francois.laurent@posteo.net> Date: Sun, 25 Jun 2023 13:05:45 +0200 Subject: [PATCH] fixes 120 --- src/files.jl | 23 ++++++++++++++++++----- src/wgl.jl | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/files.jl b/src/files.jl index 3b56b45..5401ee2 100644 --- a/src/files.jl +++ b/src/files.jl @@ -258,6 +258,7 @@ function savetofile(controller, file; datafile=nothing, merge=false) tmpfile′= basename(tmpfile) try savetofile(controller, tmpfile′; datafile=datafile) + @info "Merging file $tmpfile′ into $(file)" merge′(filepath, tmpfile′, getmanualtag(controller), file) finally rm(tmpfile; force=true) @@ -438,29 +439,41 @@ struct OutputFile merge end +OutputFile() = OutputFile( + Observable{Union{Nothing, String}}("{yyyymmdd_HHMMSS}.label"), + Observable{Bool}(false), +) + +function reset!(outputfile::OutputFile) + outputfile.name[] = nothing +end + function getoutputfile(controller) hub = gethub(controller) outputfile = nothing try outputfile = hub[:outputfile] catch - hub[:outputfile] = outputfile = OutputFile( - Observable{Union{Nothing, String}}("{yyyymmdd_HHMMSS}.label"), - Observable{Bool}(false)) + hub[:outputfile] = outputfile = OutputFile() on(outputfile.name) do file + dir = cwd(controller) if isnothing(file) outputfile.name.val = "{yyyymmdd_HHMMSS}.label" - elseif isfile(file) + elseif isfile(joinpath(dir, file)) twooptiondialog(hub, outputfile.merge, "File already exists", "Do you want to save the manual editions only (merge), or entirely overwrite the file?", "Merge", "Overwrite") else savetofile(hub, file) + reset!(outputfile) end end on(outputfile.merge) do merge - isnothing(merge) || savetofile(hub, outputfile.name[]; merge=merge) + if !isnothing(merge) + savetofile(hub, outputfile.name[]; merge=merge) + reset!(outputfile) + end end end return outputfile diff --git a/src/wgl.jl b/src/wgl.jl index af0ca77..c9cad2c 100644 --- a/src/wgl.jl +++ b/src/wgl.jl @@ -1200,7 +1200,7 @@ function twooptiondialog(controller, answer, title, message, button1, button2) document.getElementById('two-option-dialog-button2').innerHTML = $button2; """) tod.visible[] = true - # TODO: remove previous listener + Observables.clear(tod.answer) on(tod.answer) do ans tod.visible[] = false answer[] = ans -- GitLab