-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gui): support filtering files with multiple extensions in file di…
…alog (PR #2185) * fix(gui): support filtering files with multiple extensions in file dialog * lint
- Loading branch information
Showing
2 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
jadx-gui/src/main/java/jadx/gui/ui/filedialog/FileNameMultiExtensionFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package jadx.gui.ui.filedialog; | ||
|
||
import java.io.File; | ||
|
||
import javax.swing.filechooser.FileFilter; | ||
import javax.swing.filechooser.FileNameExtensionFilter; | ||
|
||
/** | ||
* Custom file filter for filtering files with multiple extensions. | ||
* It overcomes the limitation of {@link FileNameExtensionFilter}, | ||
* which treats only the last file extension split by dots as the | ||
* file extension, and does not support multiple extensions such as | ||
* {@code .jadx.kts}. | ||
*/ | ||
class FileNameMultiExtensionFilter extends FileFilter { | ||
private final FileNameExtensionFilter delegate; | ||
private final String[] extensions; | ||
|
||
public FileNameMultiExtensionFilter(String description, String... extensions) { | ||
this.delegate = new FileNameExtensionFilter(description, extensions[0]); | ||
this.extensions = extensions; | ||
} | ||
|
||
@Override | ||
public boolean accept(File file) { | ||
if (file.isDirectory()) { | ||
return true; | ||
} | ||
String fileName = file.getName(); | ||
for (String extension : extensions) { | ||
if (fileName.endsWith(extension)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return delegate.getDescription(); | ||
} | ||
} |