Skip to content

hl.UI.chooseFile multiple select support#10788

Open
nspitko wants to merge 3 commits intoHaxeFoundation:developmentfrom
nspitko:hl-multiple-file-select
Open

hl.UI.chooseFile multiple select support#10788
nspitko wants to merge 3 commits intoHaxeFoundation:developmentfrom
nspitko:hl-multiple-file-select

Conversation

@nspitko
Copy link
Copy Markdown

@nspitko nspitko commented Aug 31, 2022

This is the haxe side change for HaxeFoundation/hashlink#559

This moves a bit of code around, and adds a new function hl.UI.chooseFileMultiple, which is a version of chooseFile that is always a load, and returns a path plus array of files.

The return format was chosen largely due to how the windows API works, so I'm not married to it if someone wants a different return format. I also would prefer a @:structInit class here (especially in hl) but I wanted to maintain consistency with the existing code.

Relevant API docs: https://docs.microsoft.com/en-us/windows/win32/api/commdlg/ns-commdlg-openfilenamea

Essentially this function takes the result from the hl-side chooseFile wrapper and breaks it up into a consistent haxe return. The code is fairly straightforward; we need to dig out each string in the return value, looking for the end marker (two nulls). We then handle the special case for a single file by breaking it out to keep the haxe side API consistent.

If this commit is accepted before the hashlink pull, the function will still function correctly, but not allow multiple file selections in the ui dialogue (making it basically useless, but not crashy/dangerous)

Use ucs2Length instead of trying to sniff out nulls with a byte walk.
@skial skial mentioned this pull request Aug 31, 2022
1 task
@Simn Simn added this to the Release 4.3 milestone Mar 25, 2023
@Simn Simn added the platform-hl Everything related to HashLink label Mar 25, 2023
@kLabz kLabz modified the milestones: Release 4.3, Later Aug 29, 2023
@yuxiaomao
Copy link
Copy Markdown
Contributor

I don't really like changes on existing HL side API (return type in this case), it might break some Haxe+HL combination.
Maybe have another UI function at HL side (ui_choose_files / ui_choose_file_multiple, with return either a Ref path or Dynobj path, and NativeArray<Bytes> for files) and hide single/multiple files implementation details in C code?

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

Labels

platform-hl Everything related to HashLink

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants