FileKit
FileKit copied to clipboard
[win] Support modal dialogs (hwndOwner)
Hi there, very useful library!
It would be great to be able to open the picker dialogs modally on Windows. This is important to tie the lifecycle and visibility of the picker window to its parent window, e.g. so that closing the parent window closes the picker. I think this should probably be the default behaviour.
It looks like this could be achieved by passing an optional window handle into Picker.pickFile, and then passing that down into WindowsFileChooser so it ends up as hwndOwner?
This could tie in neatly with the Compose library as an integration with FrameWindowScope, e.g. fun FrameWindowScope.rememberFilePickerLauncher(...) that opens modally by default?
Thank you again for submitting an issue! You're right, it's an interesting feature to add.
I quickly sketch this PR https://github.com/vinceglb/PickerKotlin/issues/18
Here are the main modifications:
- The addition of PickerPlatformSettings that enables the possibility to add platform specific settings like
parentWindowon JVM. For now,PickerPlatformSettingsis empty on every other targets. PickerPlatformSettingsis a new nullable parameter ofpickFile,pickDirectory,saveFile,rememberFilePickerLauncher,rememberDirectoryPickerLauncherandrememberFileSaverLauncher.- Addition of new utility methods for Compose JVM target:
FrameWindowScope.remember*Launcherthat enables the behavior by default.
Does this solve your problem?
Your sketch looks fantastic! Absolutely solves my problem.
Apologies, I realised that my suggestion to work with FrameWindowScope might not have been a good one, since there are other window scopes, e.g. DialogWindowScope (or just plain old WindowScope). I'd consider hanging off of WindowScope?
Personally (and this is subjective), I think opening modally should be the default behaviour. Every native app I've tried on windows launches its open/save panels modally. Plus, opening modally is a less complicated user experience to handle, since you don't need to handle user interactions in the parent window while picking files.
PS: I haven't tested this library on macOS, but I imagine a similar option could be specified there, e.g. to invoke NSOpenPanel.beginSheetModalForWindow
Yes you're right, using WindowScope is better here. I just replace Frame and FrameWindowScope by Window and WindowScope.
I tested on macOS and it seems to open modally by default.
About your second point, I'm not sure how to handle the default behavior. How does the library get the parentWindow if the developer does not pass the argument? If the argument parentWindow is null, does the library create its own parentWindow? (I'm not sure if it is possible?). Is it interesting to be able to deactivate the default behavior?
Do you have a suggestion for implementing this default behavior?