Skip to content

Commit

Permalink
Supply list of available profiles in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Apr 7, 2024
1 parent 49cd42e commit dcd87a0
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions client/src/main/java/com/soulfiremc/client/gui/SFMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,35 @@ public SFMenuBar(GUIManager guiManager, LogPanel logPanel, GUIFrame guiFrame) {
this.guiFrame = guiFrame;

var fileMenu = new JMenu("File");
var loadProfile = new JMenuItem("Load Profile");
loadProfile.addActionListener(
var loadProfile = new JMenu("Load Profile");
try {
Files.list(SFPathConstants.PROFILES_FOLDER)
.filter(Files::isRegularFile)
.filter(path -> path.toString().endsWith(".json"))
.forEach(
profile -> {
var profileItem = new JMenuItem(profile.getFileName().toString());
profileItem.addActionListener(
e -> {
try {
guiManager.clientSettingsManager().loadProfile(profile);
log.info("Loaded profile: {}", profile.getFileName());
} catch (IOException ex) {
log.warn("Failed to load profile: {}", profile.getFileName(), ex);
}
});
loadProfile.add(profileItem);
});
} catch (IOException e) {
throw new RuntimeException(e);
}

if (loadProfile.getItemCount() > 0) {
loadProfile.addSeparator();
}

var fromFile = new JMenuItem("From File");
fromFile.addActionListener(
e ->
JFXFileHelper.showOpenDialog(
SFPathConstants.PROFILES_FOLDER, Map.of("SoulFire profile", "json"))
Expand All @@ -100,6 +127,7 @@ public SFMenuBar(GUIManager guiManager, LogPanel logPanel, GUIFrame guiFrame) {
log.warn("Failed to load profile!", ex);
}
}));
loadProfile.add(fromFile);

fileMenu.add(loadProfile);
var saveProfile = new JMenuItem("Save Profile");
Expand Down

0 comments on commit dcd87a0

Please sign in to comment.