Skip to content

Commit

Permalink
InfinityAmp: Store/restore last selected playlist entry across sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
Argent77 committed Dec 3, 2024
1 parent 47e9ea1 commit 9cfb3f1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/org/infinity/gui/InfinityAmpPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public class InfinityAmpPlus extends ChildFrame implements Closeable {
private static final String PREFS_AVAILABLE_ENTRY_BASE = "AvailableEntry";
private static final String PREFS_PLAYLIST_INDEX_COUNT = "PlaylistIndexCount";
private static final String PREFS_PLAYLIST_INDEX_BASE = "PlaylistIndex";
private static final String PREFS_PLAYLIST_SELECTED_INDEX = "PlaylistSelectedIndex";
private static final String PREFS_FILTER_SOUND_COUNT = "FilterSoundCount";
private static final String PREFS_FILTER_SOUND_BASE = "FilterSound";
private static final String PREFS_FILTER_SOUND_ENABLED = "FilterSoundEnabled";
Expand Down Expand Up @@ -1521,6 +1522,16 @@ private void loadPreferences() {
playListModel.add(availableListModel.get(index));
}
}

// restoring selected playlist entry
if (!playListModel.isEmpty()) {
final int playListIndex =
Math.max(0, Math.min(playListModel.size() - 1, prefs.getInt(PREFS_PLAYLIST_SELECTED_INDEX, 0)));
SwingUtilities.invokeLater(() -> {
playList.setSelectedIndex(playListIndex);
playList.ensureIndexIsVisible(playListIndex);
});
}
}

/** Saves the current configuration to the preferences. */
Expand Down Expand Up @@ -1571,6 +1582,10 @@ private void savePreferences() {
}
prefs.putInt(PREFS_PLAYLIST_INDEX_COUNT, numPlayList);

// storing selected playlist entry
final int playListIndex = playList.getSelectedIndex();
prefs.putInt(PREFS_PLAYLIST_SELECTED_INDEX, playListIndex);

// clearing old sound exclusion filter
final int oldNumSounds = prefs.getInt(PREFS_FILTER_SOUND_COUNT, 0);
for (int i = 0; i < oldNumSounds ; i++) {
Expand Down

0 comments on commit 9cfb3f1

Please sign in to comment.