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

Allow use of native system file picker dialog on Android, iOS and web #1123

Open
gingerbeardman opened this issue Jun 26, 2020 · 27 comments
Open

Comments

@gingerbeardman
Copy link

gingerbeardman commented Jun 26, 2020

Describe the project you are working on:

Describe the problem or limitation you are having in your project:

  1. godot file picker does not allow filesystem access from godot in web browser
  2. godot file picker does not allow filesystem access in sandboxed macOS apps
  3. godot file picker does not offer capabilities and conveniences of the system file picker

Describe the feature / enhancement and how it helps to overcome the problem or limitation:

regarding the above issues, allowing use of system file picker:

  • is required for 1
  • would alleviate 2

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

similar to these existing libraries, but cross platform and in core:

If this enhancement will not be used often, can it be worked around with a few lines of script?:

Sadly not, core provides no mechanism for accessing native file pickers.

See godotengine/godot#13177 for more history

The ongoing effort of creating a better file picker godotengine/godot#36053 will still not help this issue.

Is there a reason why this should be core and not an add-on in the asset library?:

  • it is required for sandboxed macOS apps, so core requirement is the only real solution
@OverloadedOrama
Copy link
Contributor

This is also necessary for the HTML5 platform, as you can't access the native file system of the device with the FileDialog when running a game/app on browser.

@gingerbeardman
Copy link
Author

@OverloadedOrama I've added that to the above proposal, thanks!

@umarcor
Copy link

umarcor commented Aug 31, 2020

FTR, in Orama-Interactive/Pixelorama they work around it with Pukkah/HTML5-File-Exchange-for-Godot.

@creikey
Copy link

creikey commented Sep 12, 2020

For those interested in implementing this it seems like this is a good resource for implementing it on windows: https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ifiledialog

@creikey
Copy link

creikey commented Sep 12, 2020

Although I see no reason why https://github.com/mlabbe/nativefiledialog cannot be pulled into third party

@Calinou
Copy link
Member

Calinou commented Jan 3, 2021

portable-file-dialogs could be used to implement native file dialogs and desktop notifications.

@Tadaboody
Copy link

Tadaboody commented Jan 4, 2021

portable-file-dialogs could be used to implement native file dialogs and desktop notifications.

This looks great! Just note that it doesn't support web yet:
From the readme:

Experimental support for Emscripten is on its way

I think using it and helping them with a web implementation is the right way to go

@98teg
Copy link

98teg commented Mar 30, 2021

This may be solved by this PR, although I still think native file dialogs would be a great addition.

@bruvzg
Copy link
Member

bruvzg commented Jun 29, 2021

This may be solved by this PR, although I still think native file dialogs would be a great addition.

I have replaced it with the full native dialog implementation - godotengine/godot#47499

portable-file-dialogs could be used to implement native file dialogs and desktop notifications.

It won't work with the sandboxed macOS apps, since it is relaying on customs scripts, which the sandboxed app won't be able to execute, and even if it was, it won't share permissions with the main app and preserve it across the sessions.

@andrea-calligaris
Copy link

andrea-calligaris commented Jan 4, 2022

Other than mine, I can imagine a lot of GUI projects currently stuck because of this.
If you are making a mobile app, in most cases you require the user to load a file, e.g. to restore a backup of user's data; but even in games, allowing the user to load a "skin.png" file or stuff like that is pretty common.
And right now it's simply impossible because FileDialog is ultra-bugged, and even more bugged in mobile.

@Zami77
Copy link

Zami77 commented Mar 20, 2022

Throwing my 2 cents in that I'd like to see this core as well. Currently running into this issue for a UI I developed that involves uploading a file to be scanned by a backend. Works great on windows export, unfortunately not possible on the HTML5 build.

@spindlebink
Copy link

spindlebink commented Apr 28, 2022

I took a stab at this and it looks like portable-file-dialogs relies pretty exclusively on the C++ stdlib. I remember reading a while back that Godot stays away from std--is that still the case?

Edit: A quick find shows me a lot of internal stuff relies on std:: so I'm going to assume it's alright I suppose.

Edit 2: After a couple hours of re-learning C++ I've got a working prototype going. This is my first-ish time working with the Godot codebase, so I'd appreciate a look.

var dialog = NativeFileDialog.new()
print(dialog.is_supported()) # whether native dialogs are supported on this system
dialog.set_window_title("Pick a file, any file")
dialog.set_file_mode(NativeFileDialog.NATIVE_FILE_MODE_OPEN_FILE)
dialog.popup()

# has_result() returns false as long as the window's still up
await dialog.has_result

var result = dialog.get_result() # when there is no result, `get_result()` blocks until the window leaves
print(result) # file path

Some notes:

  1. You can't popup() a dialog more than once. I got tired of trying to figure out why. Edit: as of this morning I done went and fixed it
  2. PFD doesn't provide a convenient way to do callbacks (and thus a potential Godot signal), but I'm sure there's a way to add a signal some other way. I'll need someone more familiar with how Godot C++ works to weigh in.
  3. PFD also supports filters and a couple of other goodies. I just haven't hooked them up yet. Edit: as of this morning I have, and they work identically to filters in FileDialog
  4. I would also appreciate design suggestions. I attempted to model the class after the FileDialog class, but there are definitely some fundamental differences that keep it from being 1:1. Edit: as of this morning I'm quite pleased with the feature parity between NativeFileDialog and FileDialog, and I think the current design works as an abstraction layer

@Calinou
Copy link
Member

Calinou commented Apr 28, 2022

I took a stab at this and it looks like portable-file-dialogs relies pretty exclusively on the C++ stdlib. I remember reading a while back that Godot stays away from std--is that still the case?

Using stdlib is OK in third-party libraries. In fact, it's sometimes used in core Godot as well (e.g. for threading primitives). Other than that, we avoid using stdlib containers within Godot core.

The only restriction is that third-party libraries need to be buildable with C++ exceptions disabled, as some platforms don't support them well (or at all).

@spindlebink
Copy link

Awesome. I'll double check for no exceptions when I'm back at dev.

I did have a couple of wrapping-up questions if you've got the time--

  • Is there a guide somewhere for editor-specific stuff in a class? I still need to add an icon, editor description, tooltips, etc. and I'd like to get that done while still developing the initial version, since it's often less likely to be completed later on.
  • Do you have a suggestion for a way to add an emitted signal to this class? The library only provides checking for whether the window has closed, so my first instinct would be just to add a check during _process and emit a window_dismissed (or similar) signal when it detects the change. Still, that feels a little inelegant, and if I'm missing a better way (maybe a C++-side await equivalent or a structure for it?) that'd be good to get info on.

@98teg
Copy link

98teg commented Apr 28, 2022

@spindlebink Hi! I have been recently working on an addon for this same feature. It's almost finished, just missing Windows and Mac executables and documentation, if you want to check it out https://github.com/98teg/NativeDialogs

@Calinou
Copy link
Member

Calinou commented Apr 28, 2022

Is there a guide somewhere for editor-specific stuff in a class? I still need to add an icon, editor description, tooltips, etc. and I'd like to get that done while still developing the initial version, since it's often less likely to be completed later on.

See Editor icons and Editor style guide in the documentation.

Adding tooltips to properties is done by exposing them to the scripting API, then updating the class reference.

Do you have a suggestion for a way to add an emitted signal to this class? The library only provides checking for whether the window has closed, so my first instinct would be just to add a check during _process and emit a window_dismissed (or similar) signal when it detects the change. Still, that feels a little inelegant, and if I'm missing a better way (maybe a C++-side await equivalent or a structure for it?) that'd be good to get info on.

I'm not sure if it can be done any other way than with _process, as C++ does not have a built-in equivalent of await or yield.

@98teg
Copy link

98teg commented Apr 28, 2022

I'm not sure if it can be done any other way than with _process, as C++ does not have a built-in equivalent of await or yield.

That's the way I handle it and it works fine.

@spindlebink
Copy link

I have been recently working on an addon for this same feature. It's almost finished, just missing Windows and Mac executables and documentation, if you want to check it out https://github.com/98teg/NativeDialogs

Looks awesome, I like that you've bound to the other dialog types as well. Probably won't be implementing anything but files for an initial version but possibly we could pull in some stuff from yours for an eventual update. I do think having this stuff in core is a great idea although I wish I'd found your library before doing stuff from scratch.

I'm not sure if it can be done any other way than with _process

That's the way I handle it and it works fine.

Sweet, that's easily doable then. I'll have a new version ready by this evening.

@octetdev2
Copy link

Tangental but native color pickers are useful too as they lets you color pick anything on screen, rather than just the things Godot draws.

@98teg
Copy link

98teg commented May 23, 2022

The plugin I mentioned earlier is now finished and available at the asset library. I hope you find it useful while this functionality gets added to Godot.

@9gay
Copy link

9gay commented Sep 8, 2022

if you use xdg-desktop-portal you're gonna break netbsd and openbsd support (well, it's possible for them to port portal, but without flatpak it doesn't make sense)

when it comes to linux and bsd it's complicated to tell what is native, if you use kde, lxqt, deepin or lumina then you surely get qt file picker, in all other cases you unfortunately (if you use raw window manager but you like qt more than gtk) get gtk file picker

considering people use raw window managers to save resources, tcl/tk is a good option, because it's extremely easy to implement support for it and it uses native file picker on windows and macos, but implements its own on linux and bsd, you don't even need to use it as a C library (although it's designed to be embedded that way) because you can just use it from command line (assuming it is installed in PATH) echo 'wm withdraw .; puts [tk_getOpenFile]; exit' | wish (other methods are tk_getSaveFile and tk_chooseDirectory) and it returns either empty string if user pressed cancel or path to file/directory if user pressed open/save/ok

@ionutrogojan
Copy link

Is this still being considered? I'm thinking of building an application with Godot and I would really like the native file dialog.

@Calinou
Copy link
Member

Calinou commented Apr 10, 2023

Is this still being considered? I'm thinking of building an application with Godot and I would really like the native file dialog.

There's a pull request implementing this feature for macOS: godotengine/godot#47499

For other platforms, godotengine/godot#60603 can be used but it doesn't handle sandbox mode on macOS.

@Anutrix
Copy link

Anutrix commented Oct 13, 2023

Afaik, native file selection dialog support is implemented for Windows, Linux and macOS.
What's status on Android, Web and iOS?

@bruvzg
Copy link
Member

bruvzg commented Oct 16, 2023

Afaik, native file selection dialog support is implemented for Windows, Linux and macOS.

It is implemented on Windows, Linux and macOS, but only for projects and for file system access, Godot Editor currently does no use them. Some of the editor file dialogs have custom controls added. Native dialogs can display extra options on all supported platforms, and it should be sufficient for the editor needs (I'm working on adding support for it).

What's status on Android, Web and iOS?

Not implemented on iOS, Android, native file selectors can be implemented, and probably will be much more convenient for users due to limited file system access. Web does not have any access to the real file system.

@OverloadedOrama
Copy link
Contributor

OverloadedOrama commented Oct 17, 2023

Web does not have any access to the real file system.

It's already possible to call custom JavaScript code that brings up native file dialogs that have access to the device's file system, see https://github.com/Pukkah/HTML5-File-Exchange-for-Godot. Would something like this not be possible to be implemented in Godot as built-in methods?

@KoBeWi
Copy link
Member

KoBeWi commented May 14, 2024

Native file dialogs are now supported for all desktop platforms via FileDialog's use_native_dialog property.

@Calinou Calinou changed the title Allow use of native system file picker dialog Allow use of native system file picker dialog on Android, iOS and web May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests