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:
parent
e3a1269de1
commit
ddecb44e86
|
@ -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> 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<Preset> 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<Preset> presets = new ArrayList<Preset>(persistentPresets.values());
|
||||
presets.sort(comparing(Preset::getName, new AlphanumComparator(Locale.getDefault())));
|
||||
|
||||
List<Preset> 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<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 {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
|
|
Loading…
Reference in New Issue