1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-04 08:25:03 -05:00

* allow cancellation of all background tasks via clicking [X] on the window

This commit is contained in:
Reinhard Pointner 2014-11-14 14:30:38 +00:00
parent 8925277105
commit 54da732674
4 changed files with 27 additions and 8 deletions

View File

@ -29,11 +29,11 @@ import net.miginfocom.swing.MigLayout;
public class SelectDialog<T> extends JDialog {
private final JLabel headerLabel = new JLabel();
private JLabel headerLabel = new JLabel();
private final JList list;
private JList list;
private boolean valueSelected = false;
private Action selectedAction = null;
public SelectDialog(Component parent, Collection<? extends T> options) {
super(getWindow(parent), "Select", ModalityType.DOCUMENT_MODAL);
@ -86,9 +86,13 @@ public class SelectDialog<T> extends JDialog {
return headerLabel;
}
public Action getSelectedAction() {
return selectedAction;
}
@SuppressWarnings("unchecked")
public T getSelectedValue() {
if (!valueSelected)
if (selectedAction != selectAction)
return null;
return (T) list.getSelectedValue();
@ -111,7 +115,7 @@ public class SelectDialog<T> extends JDialog {
@Override
public void actionPerformed(ActionEvent e) {
valueSelected = true;
selectedAction = this;
close();
}
};
@ -120,7 +124,7 @@ public class SelectDialog<T> extends JDialog {
@Override
public void actionPerformed(ActionEvent e) {
valueSelected = false;
selectedAction = this;
close();
}
};

View File

@ -27,6 +27,7 @@ import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@ -101,6 +102,10 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
prefs.put("dialog.select.w", Integer.toString(selectDialog.getWidth()));
prefs.put("dialog.select.h", Integer.toString(selectDialog.getHeight()));
if (selectDialog.getSelectedAction() == null) {
throw new CancellationException("Cancelled by user");
}
// selected value or null if the dialog was canceled by the user
return selectDialog.getSelectedValue();
}

View File

@ -29,6 +29,7 @@ import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@ -433,10 +434,14 @@ class MovieHashMatcher implements AutoCompleteMatcher {
prefs.put("dialog.select.h", Integer.toString(selectDialog.getHeight()));
// remember if we should auto-repeat the chosen action in the future
if (checkBox.isSelected()) {
if (checkBox.isSelected() || selectDialog.getSelectedAction() == null) {
memory.put("repeat", selectDialog.getSelectedValue() != null ? "select" : "ignore");
}
if (selectDialog.getSelectedAction() == null) {
throw new CancellationException("Cancelled by user");
}
// selected value or null if the dialog was canceled by the user
return selectDialog.getSelectedValue();
}

View File

@ -26,6 +26,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -699,7 +700,11 @@ public class RenamePanel extends JComponent {
// add remaining file entries
renameModel.files().addAll(remainingFiles);
} catch (Exception e) {
UILogger.log(Level.WARNING, String.format("%s: %s", getRootCause(e).getClass().getSimpleName(), getRootCauseMessage(e)), e);
if (findCause(e, CancellationException.class) != null) {
Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, getRootCause(e).toString());
} else {
UILogger.log(Level.WARNING, String.format("%s: %s", getRootCause(e).getClass().getSimpleName(), getRootCauseMessage(e)), e);
}
} finally {
// auto-match finished
namesList.firePropertyChange(LOADING_PROPERTY, true, false);