From b2a7c24ae7e43dcf18af5a860ca2fcc2145bc2fb Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 25 Jul 2016 01:42:43 +0800 Subject: [PATCH] Do not preserve AutoCompleteMatcher state (input/selection memory) between tasks (i.e. restore pre FileBot 4.7 behaviour) --- source/net/filebot/ui/rename/RenamePanel.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index 89e19a5c..c8ede9f3 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.concurrent.CancellationException; +import java.util.function.Supplier; import java.util.logging.Level; import javax.swing.AbstractAction; @@ -417,7 +418,7 @@ public class RenamePanel extends JComponent { // create actions for match popup episode list completion for (EpisodeListProvider db : WebServices.getEpisodeListProviders()) { - actionPopup.add(new AutoCompleteAction(db.getName(), db.getIcon(), new EpisodeListMatcher(db, db == WebServices.AniDB))); + actionPopup.add(new AutoCompleteAction(db.getName(), db.getIcon(), () -> new EpisodeListMatcher(db, db == WebServices.AniDB))); } actionPopup.addSeparator(); @@ -425,18 +426,18 @@ public class RenamePanel extends JComponent { // create action for movie name completion for (MovieIdentificationService it : WebServices.getMovieIdentificationServices()) { - actionPopup.add(new AutoCompleteAction(it.getName(), it.getIcon(), new MovieMatcher(it))); + actionPopup.add(new AutoCompleteAction(it.getName(), it.getIcon(), () -> new MovieMatcher(it))); } actionPopup.addSeparator(); actionPopup.addDescription(new JLabel("Music Mode:")); for (MusicIdentificationService it : WebServices.getMusicIdentificationServices()) { - actionPopup.add(new AutoCompleteAction(it.getName(), it.getIcon(), new MusicMatcher(it))); + actionPopup.add(new AutoCompleteAction(it.getName(), it.getIcon(), () -> new MusicMatcher(it))); } actionPopup.addSeparator(); actionPopup.addDescription(new JLabel("Smart Mode:")); - actionPopup.add(new AutoCompleteAction("Autodetect", ResourceManager.getIcon("action.auto"), new AutoDetectMatcher())); + actionPopup.add(new AutoCompleteAction("Autodetect", ResourceManager.getIcon("action.auto"), AutoDetectMatcher::new)); actionPopup.addSeparator(); actionPopup.addDescription(new JLabel("Options:")); @@ -651,7 +652,7 @@ public class RenamePanel extends JComponent { private Preset preset; public ApplyPresetAction(Preset preset) { - super(preset.getName(), ResourceManager.getIcon("script.go"), preset.getAutoCompleteMatcher()); + super(preset.getName(), ResourceManager.getIcon("script.go"), preset::getAutoCompleteMatcher); this.preset = preset; } @@ -767,10 +768,12 @@ public class RenamePanel extends JComponent { protected class AutoCompleteAction extends AbstractAction { - protected final AutoCompleteMatcher matcher; + protected final Supplier matcher; - public AutoCompleteAction(String name, Icon icon, AutoCompleteMatcher matcher) { + public AutoCompleteAction(String name, Icon icon, Supplier matcher) { super(name, icon); + + // create matcher when required this.matcher = matcher; // disable action while episode list matcher is working @@ -801,7 +804,7 @@ public class RenamePanel extends JComponent { } @Override - public void actionPerformed(final ActionEvent evt) { + public void actionPerformed(ActionEvent evt) { // clear names list renameModel.values().clear(); @@ -821,7 +824,7 @@ public class RenamePanel extends JComponent { @Override protected List> doInBackground() throws Exception { - List> matches = matcher.match(remainingFiles, strict, order, locale, autodetection, getWindow(RenamePanel.this)); + List> matches = matcher.get().match(remainingFiles, strict, order, locale, autodetection, getWindow(RenamePanel.this)); // remove matched files for (Match match : matches) {