From ddecb44e86bb22a92a737ebdee2c99e6921ad233 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 17 Oct 2017 14:07:19 +0200 Subject: [PATCH] Ensure Preset order on all platforms (e.g. Windows Registry Preferences are sorted alphabetically, but the same is not guaranteed for other platforms) @see https://www.filebot.net/forums/viewtopic.php?f=6&t=5391&p=30625#p30623 --- source/net/filebot/ui/rename/RenamePanel.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index f75be0fc..01e417e8 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -31,7 +31,6 @@ import java.util.Optional; import java.util.concurrent.CancellationException; import java.util.function.Supplier; import java.util.logging.Level; -import java.util.stream.IntStream; import javax.swing.AbstractAction; import javax.swing.Action; @@ -346,13 +345,15 @@ public class RenamePanel extends JComponent { })); // map 1..9 number keys to presets - IntStream.rangeClosed(1, 9).forEach(i -> { - installAction(this, WHEN_IN_FOCUSED_WINDOW, getKeyStroke(Character.forDigit(i, 10), 0), newAction("Preset " + i, evt -> { - try { - Optional preset = persistentPresets.values().stream().skip(i - 1).findFirst(); + for (int presetNumber = 1; presetNumber <= 9; presetNumber++) { + int index = presetNumber - 1; - if (preset.isPresent()) { - new ApplyPresetAction(preset.get()).actionPerformed(evt); + installAction(this, WHEN_IN_FOCUSED_WINDOW, getKeyStroke(Character.forDigit(presetNumber, 10), 0), newAction("Preset " + presetNumber, evt -> { + try { + List presets = getPresets(); + + if (index < presets.size()) { + new ApplyPresetAction(presets.get(index)).actionPerformed(evt); } else { new ShowPresetsPopupAction().actionPerformed(evt); } @@ -360,7 +361,7 @@ public class RenamePanel extends JComponent { debug.log(Level.WARNING, e, e::getMessage); } })); - }); + } // copy debug information (paths and objects) installAction(this, WHEN_IN_FOCUSED_WINDOW, getKeyStroke(VK_F7, 0), newAction("Copy Debug Information", evt -> { @@ -383,9 +384,7 @@ public class RenamePanel extends JComponent { private ActionPopup createPresetsPopup() { ActionPopup actionPopup = new ActionPopup("Presets", ResourceManager.getIcon("action.script")); - List presets = new ArrayList(persistentPresets.values()); - presets.sort(comparing(Preset::getName, new AlphanumComparator(Locale.getDefault()))); - + List presets = getPresets(); if (presets.size() > 0) { for (Preset preset : presets) { actionPopup.add(new ApplyPresetAction(preset)); @@ -635,6 +634,13 @@ public class RenamePanel extends JComponent { } } + private List getPresets() { + // load Presets and ensure Preset order on all platforms (e.g. Windows Registry Preferences are sorted alphabetically, but the same is not guaranteed for other platforms) + List presets = new ArrayList(persistentPresets.values()); + presets.sort(comparing(Preset::getName, new AlphanumComparator(Locale.getDefault()))); + return presets; + } + private String getDebugInfo() throws Exception { StringBuilder sb = new StringBuilder();