Lock the format editor to movie/episode/music/file mode depending on your selected datasource
This commit is contained in:
parent
d7a297a759
commit
c0f7dc742e
|
@ -21,6 +21,7 @@ import java.io.File;
|
|||
import java.text.Format;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
@ -140,6 +141,20 @@ public class FormatDialog extends JDialog {
|
|||
return Settings.forPackage(FormatDialog.class).node("format.recent." + key()).asList();
|
||||
}
|
||||
|
||||
public Object getDefaultSampleObject() {
|
||||
try {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(FormatDialog.class.getName());
|
||||
String json = bundle.getString(key() + ".sample");
|
||||
return MetaAttributes.toObject(json);
|
||||
} catch (MissingResourceException e) {
|
||||
// ignore
|
||||
} catch (Exception e) {
|
||||
debug.log(Level.SEVERE, "Illegal Sample", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getDefaultFormatExpression() {
|
||||
return getSampleExpressions().iterator().next();
|
||||
}
|
||||
|
@ -405,18 +420,13 @@ public class FormatDialog extends JDialog {
|
|||
// restore sample from user preferences
|
||||
String sample = mode.persistentSample().getValue();
|
||||
info = MetaAttributes.toObject(sample);
|
||||
|
||||
if (info == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
// restore sample from application properties
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(getClass().getName());
|
||||
String sample = bundle.getString(mode.key() + ".sample");
|
||||
info = MetaAttributes.toObject(sample);
|
||||
} catch (Exception illegalSample) {
|
||||
debug.log(Level.SEVERE, "Illegal Sample", e);
|
||||
}
|
||||
// restore sample from application properties
|
||||
info = mode.getDefaultSampleObject();
|
||||
}
|
||||
|
||||
// restore media file
|
||||
|
|
|
@ -135,7 +135,7 @@ public class Preset {
|
|||
public static final PlainFileMatcher PLAIN_FILE_MATCHER = new PlainFileMatcher();
|
||||
|
||||
public static Datasource[] getSupportedServices() {
|
||||
Stream<Datasource> services = Stream.of(getMovieIdentificationServices(), getEpisodeListProviders(), getMusicIdentificationServices()).flatMap(Stream::of);
|
||||
Stream<Datasource> services = Stream.of(getEpisodeListProviders(), getMovieIdentificationServices(), getMusicIdentificationServices()).flatMap(Stream::of);
|
||||
services = Stream.concat(services, Stream.of(XATTR_FILE_MATCHER, PLAIN_FILE_MATCHER));
|
||||
return services.toArray(Datasource[]::new);
|
||||
}
|
||||
|
|
|
@ -302,16 +302,19 @@ public class PresetEditor extends JDialog {
|
|||
|
||||
private final Action editFormatExpression = newAction("Open Format Editor", ResourceManager.getIcon("action.format"), evt -> {
|
||||
FormatDialog.Mode mode = FormatDialog.Mode.getMode((Datasource) providerCombo.getSelectedItem());
|
||||
MediaBindingBean lockOnBinding = null;
|
||||
|
||||
Object sample = mode.getDefaultSampleObject();
|
||||
File file = null;
|
||||
|
||||
if (mode == FormatDialog.Mode.File) {
|
||||
List<File> files = UserFiles.showLoadDialogSelectFiles(false, false, null, new ExtensionFileFilter(ExtensionFileFilter.WILDCARD), "Select Sample File", evt);
|
||||
if (files.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
lockOnBinding = new MediaBindingBean(files.get(0), files.get(0));
|
||||
sample = file = files.get(0);
|
||||
}
|
||||
|
||||
FormatDialog dialog = new FormatDialog(getWindow(evt.getSource()), mode, lockOnBinding);
|
||||
FormatDialog dialog = new FormatDialog(getWindow(evt.getSource()), mode, new MediaBindingBean(sample, file, singletonMap(file, sample)));
|
||||
dialog.setFormatCode(formatEditor.getText());
|
||||
dialog.setLocation(getOffsetLocation(dialog.getOwner()));
|
||||
dialog.setVisible(true);
|
||||
|
|
Loading…
Reference in New Issue