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
This commit is contained in:
Reinhard Pointner 2017-10-17 14:07:19 +02:00
parent e3a1269de1
commit ddecb44e86
1 changed files with 17 additions and 11 deletions

View File

@ -31,7 +31,6 @@ import java.util.Optional;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.IntStream;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.Action; import javax.swing.Action;
@ -346,13 +345,15 @@ public class RenamePanel extends JComponent {
})); }));
// map 1..9 number keys to presets // map 1..9 number keys to presets
IntStream.rangeClosed(1, 9).forEach(i -> { for (int presetNumber = 1; presetNumber <= 9; presetNumber++) {
installAction(this, WHEN_IN_FOCUSED_WINDOW, getKeyStroke(Character.forDigit(i, 10), 0), newAction("Preset " + i, evt -> { int index = presetNumber - 1;
try {
Optional<Preset> preset = persistentPresets.values().stream().skip(i - 1).findFirst();
if (preset.isPresent()) { installAction(this, WHEN_IN_FOCUSED_WINDOW, getKeyStroke(Character.forDigit(presetNumber, 10), 0), newAction("Preset " + presetNumber, evt -> {
new ApplyPresetAction(preset.get()).actionPerformed(evt); try {
List<Preset> presets = getPresets();
if (index < presets.size()) {
new ApplyPresetAction(presets.get(index)).actionPerformed(evt);
} else { } else {
new ShowPresetsPopupAction().actionPerformed(evt); new ShowPresetsPopupAction().actionPerformed(evt);
} }
@ -360,7 +361,7 @@ public class RenamePanel extends JComponent {
debug.log(Level.WARNING, e, e::getMessage); debug.log(Level.WARNING, e, e::getMessage);
} }
})); }));
}); }
// copy debug information (paths and objects) // copy debug information (paths and objects)
installAction(this, WHEN_IN_FOCUSED_WINDOW, getKeyStroke(VK_F7, 0), newAction("Copy Debug Information", evt -> { 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() { private ActionPopup createPresetsPopup() {
ActionPopup actionPopup = new ActionPopup("Presets", ResourceManager.getIcon("action.script")); ActionPopup actionPopup = new ActionPopup("Presets", ResourceManager.getIcon("action.script"));
List<Preset> presets = new ArrayList<Preset>(persistentPresets.values()); List<Preset> presets = getPresets();
presets.sort(comparing(Preset::getName, new AlphanumComparator(Locale.getDefault())));
if (presets.size() > 0) { if (presets.size() > 0) {
for (Preset preset : presets) { for (Preset preset : presets) {
actionPopup.add(new ApplyPresetAction(preset)); actionPopup.add(new ApplyPresetAction(preset));
@ -635,6 +634,13 @@ public class RenamePanel extends JComponent {
} }
} }
private List<Preset> 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<Preset> presets = new ArrayList<Preset>(persistentPresets.values());
presets.sort(comparing(Preset::getName, new AlphanumComparator(Locale.getDefault())));
return presets;
}
private String getDebugInfo() throws Exception { private String getDebugInfo() throws Exception {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();