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.text.Format;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.MissingResourceException;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
@ -140,6 +141,20 @@ public class FormatDialog extends JDialog {
|
||||||
return Settings.forPackage(FormatDialog.class).node("format.recent." + key()).asList();
|
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() {
|
public String getDefaultFormatExpression() {
|
||||||
return getSampleExpressions().iterator().next();
|
return getSampleExpressions().iterator().next();
|
||||||
}
|
}
|
||||||
|
@ -405,18 +420,13 @@ public class FormatDialog extends JDialog {
|
||||||
// restore sample from user preferences
|
// restore sample from user preferences
|
||||||
String sample = mode.persistentSample().getValue();
|
String sample = mode.persistentSample().getValue();
|
||||||
info = MetaAttributes.toObject(sample);
|
info = MetaAttributes.toObject(sample);
|
||||||
|
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
try {
|
// restore sample from application properties
|
||||||
// restore sample from application properties
|
info = mode.getDefaultSampleObject();
|
||||||
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 media file
|
// restore media file
|
||||||
|
|
|
@ -135,7 +135,7 @@ public class Preset {
|
||||||
public static final PlainFileMatcher PLAIN_FILE_MATCHER = new PlainFileMatcher();
|
public static final PlainFileMatcher PLAIN_FILE_MATCHER = new PlainFileMatcher();
|
||||||
|
|
||||||
public static Datasource[] getSupportedServices() {
|
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));
|
services = Stream.concat(services, Stream.of(XATTR_FILE_MATCHER, PLAIN_FILE_MATCHER));
|
||||||
return services.toArray(Datasource[]::new);
|
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 -> {
|
private final Action editFormatExpression = newAction("Open Format Editor", ResourceManager.getIcon("action.format"), evt -> {
|
||||||
FormatDialog.Mode mode = FormatDialog.Mode.getMode((Datasource) providerCombo.getSelectedItem());
|
FormatDialog.Mode mode = FormatDialog.Mode.getMode((Datasource) providerCombo.getSelectedItem());
|
||||||
MediaBindingBean lockOnBinding = null;
|
|
||||||
|
Object sample = mode.getDefaultSampleObject();
|
||||||
|
File file = null;
|
||||||
|
|
||||||
if (mode == FormatDialog.Mode.File) {
|
if (mode == FormatDialog.Mode.File) {
|
||||||
List<File> files = UserFiles.showLoadDialogSelectFiles(false, false, null, new ExtensionFileFilter(ExtensionFileFilter.WILDCARD), "Select Sample File", evt);
|
List<File> files = UserFiles.showLoadDialogSelectFiles(false, false, null, new ExtensionFileFilter(ExtensionFileFilter.WILDCARD), "Select Sample File", evt);
|
||||||
if (files.isEmpty()) {
|
if (files.isEmpty()) {
|
||||||
return;
|
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.setFormatCode(formatEditor.getText());
|
||||||
dialog.setLocation(getOffsetLocation(dialog.getOwner()));
|
dialog.setLocation(getOffsetLocation(dialog.getOwner()));
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
|
|
Loading…
Reference in New Issue