From 9cfb3f13daa264f7e71bfc36a32d0f9e440dc916 Mon Sep 17 00:00:00 2001 From: Argent77 <4519923+Argent77@users.noreply.github.com> Date: Tue, 3 Dec 2024 20:32:07 +0100 Subject: [PATCH] InfinityAmp: Store/restore last selected playlist entry across sessions --- src/org/infinity/gui/InfinityAmpPlus.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/org/infinity/gui/InfinityAmpPlus.java b/src/org/infinity/gui/InfinityAmpPlus.java index 1dad2a4b0..063d1f13a 100644 --- a/src/org/infinity/gui/InfinityAmpPlus.java +++ b/src/org/infinity/gui/InfinityAmpPlus.java @@ -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"; @@ -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. */ @@ -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++) {