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

"Select Resource Pack" allow multi-selection #217

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow multiple file selection in resource pack selector
  • Loading branch information
Tiefseetauchner committed Mar 12, 2023
commit 270da4078510df534ad9cd9755cc496e31fb09d3
17 changes: 12 additions & 5 deletions src/org/jmc/gui/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;

Expand Down Expand Up @@ -300,19 +302,24 @@ public boolean importData(TransferSupport support) {
btnPackAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser jfc = new JFileChooser(MainWindow.settings.getLastExportPath());
// Only files currently supported, remove when support for directories added
//jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
jfc.setMultiSelectionEnabled(true);
jfc.addChoosableFileFilter(new FileFilter() {
@Override public String getDescription() {return "Extracted pack.mcmeta";}
@Override public boolean accept(File f) {return f.isDirectory() || f.getName().equals("pack.mcmeta");}
});
jfc.setFileFilter(new FileNameExtensionFilter("Zip & Jar files", "zip", "ZIP", "Zip", "jar", "JAR", "Jar"));
jfc.setCurrentDirectory(Filesystem.getMinecraftDir());
jfc.showDialog(Settings.this, Messages.getString("TexsplitDialog.SEL_RP"));
File path = jfc.getSelectedFile();
if (path == null) {
return;
}
listPacks.getModel().add(0, path);

File[] selectedFiles = jfc.getSelectedFiles();

List<File> selectedFilesList = Arrays.asList(selectedFiles);
selectedFilesList.removeIf(Objects::isNull);

listPacks.getModel().addAll(selectedFilesList);

listPacks.setSelectedIndex(0);
saveSettings();
updateResourcePacks(true);
Expand Down