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

Scripting: FilePicker for multiple files #3558

Open
eishiya opened this issue Jan 24, 2023 · 3 comments
Open

Scripting: FilePicker for multiple files #3558

eishiya opened this issue Jan 24, 2023 · 3 comments
Labels
feature It's a feature, not a bug.

Comments

@eishiya
Copy link
Contributor

eishiya commented Jan 24, 2023

The FileEdit returned by Dialog.addFilePicker() only allows selecting one file at a time. This means that if I want to prompt users for any number of files, I have to either let them add files one after the other using one filepicker, or give them a button to add as many FilePickers as they want, neither of these is convenient for the user.

It would be much more convenient for the user if I could give them a file dialog that lets them select multiple files. It would simplify the script, as well.

Example scriptable use cases that require an unknown number of files to be selected:

  • Generate tilesets with the same settings from any number of tilesheet images (this was requested on Discord)
  • Add multiple Image Layers quickly
  • Merge multiple map files into one map (or into a World with custom auto-placement, if/when Worlds become exposed to scripting)

Tangential request: being able to select directories, not just files. This would be more convenient than selecting all the files in a directory, and combined with multi-file select, this would allow selecting all the files in several directories. It would also be more intuitive for scripts that want an output directory than the current approach of picking some file in that directory.

@eishiya eishiya added the feature It's a feature, not a bug. label Jan 24, 2023
@eishiya
Copy link
Contributor Author

eishiya commented Dec 5, 2023

Since I opened this issue, #3777 has added documentation for FilePicker.isDorectory, so it turns out getting to pick (single) directories was available all along. #3782 added tiled.promptOpenFiles among other prompts, which can be used to create a homebrew multi-file picker with a convenient interface for users - a label to show the chosen files, and a button that calls the relevant prompt function.

However, I'm keeping this issue open because I think a multi-file file picker widget would still be nice to have.

@bjorn
Copy link
Member

bjorn commented Dec 6, 2023

Hmm, I think the issue is that the widget is specifically designed to show a single file path, which can also be edited, in its built-in line edit. In all other places where this widget is used, selecting multiple files makes no sense.

What should happen when the user is allowed to select multiple files?

  • Should the line edit display them as comma-separated? What about manual edits? Then we would need comma separated list parsing, probably including some quoting mechanism to handle the case where a file path includes a comma (not sure if allowed on Windows, but it's valid in Linux).

  • Alternatively, a list view could be used to show the list of selected files, with buttons to allow removing items from that list.

  • The file picker in a browser with multiple attribute resolves the issue by simple not having a user-editable field or list at all, and displaying "N files" next to the dialog instead of the file name in case of multiple selected files. This could be a simple solution here as well.

@eishiya
Copy link
Contributor Author

eishiya commented Dec 6, 2023

I think "N files" would be fine, I imagine that's something people are used to. And rolling a custom label+button is an option for people who want something fancier.
It could be neat to show their extension in case they all share the same one, e.g. if you select A.png and B.png, it'll say "2 PNG files", but if you select A.png and C.jpg, it'll just say "2 files". But, I am not aware of any software that does this.
When only file is selected, then the filename should be shown, read-only, similar to browsers.

(FYI, commas are valid in filenames on Windows too.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature It's a feature, not a bug.
Projects
None yet
Development

No branches or pull requests

2 participants