* lazy-load rhino script engine in RenamePanel (startup will be 0.5s faster)
This commit is contained in:
parent
d71a70316a
commit
cd1ea72c88
|
@ -15,16 +15,16 @@ import net.sourceforge.filebot.web.EpisodeFormat;
|
|||
|
||||
class EpisodeExpressionFormatter implements MatchFormatter {
|
||||
|
||||
private final ExpressionFormat format;
|
||||
private final String expression;
|
||||
|
||||
private ExpressionFormat format;
|
||||
|
||||
|
||||
public EpisodeExpressionFormatter(ExpressionFormat format) {
|
||||
this.format = format;
|
||||
}
|
||||
public EpisodeExpressionFormatter(String expression) {
|
||||
if (expression == null || expression.isEmpty())
|
||||
throw new IllegalArgumentException("Expression must not be null or empty");
|
||||
|
||||
|
||||
public ExpressionFormat getFormat() {
|
||||
return format;
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,6 +46,11 @@ class EpisodeExpressionFormatter implements MatchFormatter {
|
|||
Episode episode = (Episode) match.getValue();
|
||||
File mediaFile = (File) match.getCandidate();
|
||||
|
||||
// lazy initialize script engine
|
||||
if (format == null) {
|
||||
format = new ExpressionFormat(expression);
|
||||
}
|
||||
|
||||
String result = format.format(new EpisodeBindingBean(episode, mediaFile)).trim();
|
||||
|
||||
// if result is empty, check for script exceptions
|
||||
|
|
|
@ -31,7 +31,6 @@ import ca.odell.glazedlists.swing.EventSelectionModel;
|
|||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sourceforge.filebot.ResourceManager;
|
||||
import net.sourceforge.filebot.Settings;
|
||||
import net.sourceforge.filebot.format.ExpressionFormat;
|
||||
import net.sourceforge.filebot.similarity.Match;
|
||||
import net.sourceforge.filebot.ui.panel.rename.RenameModel.FormattedFuture;
|
||||
import net.sourceforge.filebot.web.AnidbClient;
|
||||
|
@ -78,8 +77,7 @@ public class RenamePanel extends JComponent {
|
|||
|
||||
try {
|
||||
// restore custom episode formatter
|
||||
ExpressionFormat format = new ExpressionFormat(persistentFormatExpression.getValue());
|
||||
renameModel.useFormatter(Episode.class, new EpisodeExpressionFormatter(format));
|
||||
renameModel.useFormatter(Episode.class, new EpisodeExpressionFormatter(persistentFormatExpression.getValue()));
|
||||
} catch (Exception e) {
|
||||
// illegal format, ignore
|
||||
}
|
||||
|
@ -157,9 +155,8 @@ public class RenamePanel extends JComponent {
|
|||
|
||||
switch (dialog.getSelectedOption()) {
|
||||
case APPROVE:
|
||||
EpisodeExpressionFormatter formatter = new EpisodeExpressionFormatter(dialog.getSelectedFormat());
|
||||
renameModel.useFormatter(Episode.class, formatter);
|
||||
persistentFormatExpression.setValue(formatter.getFormat().getExpression());
|
||||
renameModel.useFormatter(Episode.class, new EpisodeExpressionFormatter(dialog.getSelectedFormat().getExpression()));
|
||||
persistentFormatExpression.setValue(dialog.getSelectedFormat().getExpression());
|
||||
break;
|
||||
case USE_DEFAULT:
|
||||
renameModel.useFormatter(Episode.class, null);
|
||||
|
|
Loading…
Reference in New Issue