godot icon indicating copy to clipboard operation
godot copied to clipboard

Make `FileDialog` filtering case insensitive

Open DevilboxGames opened this issue 2 years ago • 9 comments

When using FileDialog to save files on non-case-sensitive file systems (Windows and often macOS), a file may have an uppercase file extension ( file.TXT ) but the filter is set as lowercase ( *.txt ; Text Files ). The FileDialog will list the file but selecting it to overwrite will not detect that the file matches the filter and append the lowercase extension after the existing uppercase file extension and would result in the selected file being file.TXT.txt

As most other operating systems can be case sensitive, my suggestion is to add a CaseSensitivity enum with the values of True, False and OS Default to the FileDialog for toggling between using f.match(str) and f.matchn(str) in the checks which would allow it to either be explicit based on the developer intent or implicit based on the standard of the operating system.

filedialog-case-sensitivity

Currently if OS Default is used then the code uses a case-sensitive check if the OS is not Windows or macOS. Is there a better approach for this? Are there any other supported OS's are not case-sensitive by default?

Attached is an MRP similar to the one provided in the issue, with the addition of an OptionButton for changing between the CaseSensitivity setting when running the project. FileDialogCaseSensitivity.zip

Fixes #85788

DevilboxGames avatar Dec 05 '23 15:12 DevilboxGames

You also need to register these enums in _bind_methods, see the other ones

AThousandShips avatar Dec 05 '23 15:12 AThousandShips

You also need to document these methods, use --doctool, see here

AThousandShips avatar Dec 05 '23 16:12 AThousandShips

You also need to document these methods, use --doctool, see here

I've updated the doc xml now, is this correct? ~~The --doctool tool didn't generate any additional entries in it for the enum or methods.~~ my mistake, I must have run it against the wrong exe, it fixed up the incorrect default when I re-ran it.

Documentation isn't my forte so the wording might need tweaking.

DevilboxGames avatar Dec 05 '23 18:12 DevilboxGames

I noticed a merge conflict, so I've rebased and resolved it.

DevilboxGames avatar Feb 05 '24 09:02 DevilboxGames

It looks like one of the tests failed due to a ubuntu keyserver issue. Could a maintainer request a rerun of the failed test?

I appologise if the ping is innapropriate, but Yuri also requested requested @bruvzg to re-review the PR in December. Is there anything else which needs to be done before it can be approved for merging?

DevilboxGames avatar Feb 15 '24 15:02 DevilboxGames

Tested locally on Linux (on a case-sensitive filesystem), I'm a bit confused about the behavior. The only behavior that seems desirable to me here is the one where case sensitive is set to False:

https://github.com/godotengine/godot/assets/180032/78d912ea-1b03-4c26-bcb4-f364bfacbac9

Otherwise, you get a double extension appended. Is there a point for keeping case sensitive True (and OS Default on case-sensitive filesystems)?

Also, the file filter is always case-insensitive regardless of this option, but I guess that's expected.

Calinou avatar Feb 15 '24 19:02 Calinou

That behaviour looks as expected. Having the option for true and OS Default is so it doesn't break anything which might be reliant on a case sensitive file picking for whatever reason. I agree, having it set to false is the desirable option in all the use cases I could think of but I didn't feel comfortable making that assumption for everyone, hence having the option and defaulting to match the OS's case sensitivity.

The file filter was case insensitive for listing the files in the dialog originally, it was just the functionality of the detecting the extension on the selected filename and appending if it was missing which wasn't case insensitive, which resulted in the doubling of the file extension.

I could remove the setting and just make this always be case insensitive, or I could have it default to false and leave the option for the rare situtation it might be wanted? I'm open to whichever option is most suitable.

DevilboxGames avatar Feb 15 '24 23:02 DevilboxGames

IMO this makes sense. The change only affects extension checking and I don't see why would you care about extension casing and make a double extension, like currently happens on mismatch.

The same change should be done in EditorFileDialog.

KoBeWi avatar Sep 28 '24 20:09 KoBeWi

IMO this makes sense. The change only affects extension checking and I don't see why would you care about extension casing and make a double extension, like currently happens on mismatch.

The same change should be done in EditorFileDialog.

Good shout, I've added the change to EditorFileDialog too, I also noticed FileDialog::_native_dialog_cb needed the change too so I've dropped it in there.

DevilboxGames avatar Oct 07 '24 13:10 DevilboxGames

Needs to be squashed into 1 commit.

KoBeWi avatar Oct 07 '24 14:10 KoBeWi

Commits squashed 👍

DevilboxGames avatar Oct 07 '24 14:10 DevilboxGames

Thanks! And congrats for your first merged Godot contribution :tada:

akien-mga avatar Nov 29 '24 22:11 akien-mga