Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileDialog.SetOnClosed not always working #4651

Closed
2 tasks done
codesoap opened this issue Feb 18, 2024 · 2 comments
Closed
2 tasks done

FileDialog.SetOnClosed not always working #4651

codesoap opened this issue Feb 18, 2024 · 2 comments
Labels
unverified A bug that has been reported but not verified

Comments

@codesoap
Copy link
Contributor

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

If SetOnClosed is called on a FileDialog before Show is called, the callback will not be called when the dialog is closed.

How to reproduce

Run the example code, close the file dialog and see that foo is not printed to standard output.

Screenshots

No response

Example code

package main

import "fyne.io/fyne/v2"
import "fyne.io/fyne/v2/app"
import "fyne.io/fyne/v2/dialog"

func main() {
	a := app.New()
	w := a.NewWindow("test")

	fd := dialog.NewFileOpen(func(rc fyne.URIReadCloser, err error) {}, w)
	fd.SetOnClosed(func() { println("foo") })
	fd.Show()

	w.ShowAndRun()
}

Fyne version

2.4.4

Go compiler version

1.22.0

Operating system and version

MX Linux, I believe version 21; it's basically Debian

Additional Information

It works, if SetOnClosed is called after Show:

package main

import "fyne.io/fyne/v2"
import "fyne.io/fyne/v2/app"
import "fyne.io/fyne/v2/dialog"

func main() {
	a := app.New()
	w := a.NewWindow("test")

	fd := dialog.NewFileOpen(func(rc fyne.URIReadCloser, err error) {}, w)
	fd.Show()
	fd.SetOnClosed(func() { println("foo") })

	w.ShowAndRun()
}

The problem seems to be that f.dialog == nil is checked in SetOnClosed, but f.dialog is only set once Show is called.

My initial impulse was to just remove the early return in SetOnClosed, but I suppose it's there for a reason (which I don't see right now), so I didn''t open a PR.

@codesoap codesoap added the unverified A bug that has been reported but not verified label Feb 18, 2024
@codesoap
Copy link
Contributor Author

It just occurred to me, that the check should probably be run within the callback, so I created #4652 .

@codesoap
Copy link
Contributor Author

Closing, because #4652 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unverified A bug that has been reported but not verified
Projects
None yet
Development

No branches or pull requests

1 participant