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

fix(gui): support filtering files with multiple extensions in file dialog #2185

Merged
merged 2 commits into from
May 19, 2024

Conversation

xxr0ss
Copy link
Contributor

@xxr0ss xxr0ss commented May 17, 2024

Fixes #2184

After this commit:
image

The origional filter uses the last segment split by . from file name to match files, so extensions like .jadx.kts won't be accepted

public final class FileNameExtensionFilter extends FileFilter {
    // ...
    public boolean accept(File f) {
        if (f != null) {
            if (f.isDirectory()) {
                return true;
            }
            // NOTE: we tested implementations using Maps, binary search
            // on a sorted list and this implementation. All implementations
            // provided roughly the same speed, most likely because of
            // overhead associated with java.io.File. Therefor we've stuck
            // with the simple lightweight approach.
            String fileName = f.getName();
            int i = fileName.lastIndexOf('.');
            if (i > 0 && i < fileName.length() - 1) {
                String desiredExtension = fileName.substring(i+1).
                        toLowerCase(Locale.ENGLISH);
                for (String extension : lowerCaseExtensions) {
                    if (desiredExtension.equals(extension)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    // ...

Copy link
Owner

@skylot skylot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why you use delegate of FileNameExtensionFilter, because it just uses provided description internally.
Everything else looks good, thanks 👍

@skylot skylot merged commit 82e2104 into skylot:master May 19, 2024
5 checks passed
@xxr0ss
Copy link
Contributor Author

xxr0ss commented May 19, 2024

Not sure why you use delegate of FileNameExtensionFilter, because it just uses provided description internally. Everything else looks good, thanks 👍

Hmm... the code I put in description is exactly part of the FileNameExtensionFilter, which doesn't work as expected.
Other parts of it just works fine, I don't want to accidentally break them. FileNameExtensionFilter is a final class so I have to delegate it instead of inheriting it.

thanks for merging : )

@xxr0ss xxr0ss deleted the fix_file_chooser branch May 19, 2024 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[gui] File Chooser doesn't show .jadx.kts files
2 participants