-
Notifications
You must be signed in to change notification settings - Fork 143
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
Expose cancel state of FileDialog #1005
Expose cancel state of FileDialog #1005
Conversation
b192f9e
to
e61c959
Compare
bb3a30a
to
6aff4a7
Compare
The FileDialog implementations do currently not provide any way to identify that the dialog was canceled. The dialogs return a null string in case no file was selected, but is not possible to identify whether this was intended (via a cancel action) or if there was some unexpected error (such as too long file paths on Windows). This change introduces a `wasCanceled()` method to the FileDialog implementations for all three operating systems. The dialogs evaluate the operating system's response code for the system's dialog control and store it to be retrieved by the added method.
6aff4a7
to
3857a6b
Compare
@HeikoKlare just a though but if there is an ERROR I would expect it to be throwing an exception instead of silently ignore, it seems not so useful to have check for cancel just to tell the user that "something" went wrong.... |
Maybe my description is a bit misleading: the |
At least the GTK impl also throws error NO_MORE_HANDLES so it seems not completely true that it always returns But even then, instead of a new
or as an alternative have a
so one can get more information if open failed versus canceled. Also note that there is also a DirectoryDialog :-) |
That's right. So we have to distinguish two kinds of errors here:
That's a really good idea and definitely far better than the proposal in this PR. I will provide a PR with a proposal to discuss how that should like.
Thanks! I missed that (because our product only requires cancel state identification for the FileDialog). I will address that in the PR proposing an alternative solution (as metnioned above). |
The FileDialog implementations do currently not provide any way to identify that the dialog was canceled. The dialogs return a null string in case no file was selected, but is not possible to identify whether this was intended (via a cancel action) or if there was some unexpected error (such as too long file paths on Windows).
This change introduces a
wasCanceled()
method to the FileDialog implementations for all three operating systems. The dialogs evaluate the operating system's response code for the system's dialog control and store it to be retrieved by the added method.A "better" solution would be to let the
open()
method somehow return a cancel operation as a its result, but such a solution would require an API change, while the proposed one only adds a method and thus keeps the API stable.I have already tested the extension on all three operating system by both canceling and properly selecting a file in a dialog via the following simple snippet: