diff --git a/src/files.jl b/src/files.jl index 3b56b4505e539113554483ddb62ef47d464b213f..5401ee2b6a7985f09c7528e1e2cdf6d9c80cb011 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 af0ca77abc00aa0918ad5df84f56ed4734cd903f..c9cad2c70a4623d433ca57ff2afb8b4ac616f8d9 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