Skip to content

FileDialog.SetOnClosed not always working #4651

Closed
@codesoap

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    unverifiedA bug that has been reported but not verified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions