Skip to content

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

Merged
skylot merged 2 commits intoskylot:masterfrom
xxr0ss:fix_file_chooser
May 19, 2024
Merged

fix(gui): support filtering files with multiple extensions in file dialog#2185
skylot merged 2 commits intoskylot:masterfrom
xxr0ss:fix_file_chooser

Conversation

@xxr0ss
Copy link
Copy Markdown
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
Copy Markdown
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
@xxr0ss
Copy link
Copy Markdown
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