1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-16 14:25:02 -05:00

* make things more idiot-proof

This commit is contained in:
Reinhard Pointner 2013-09-30 04:46:33 +00:00
parent 20aef4e385
commit e29b07c186
3 changed files with 73 additions and 87 deletions

View File

@ -1,7 +1,5 @@
package net.sourceforge.filebot.ui.rename; package net.sourceforge.filebot.ui.rename;
import static java.util.Collections.*; import static java.util.Collections.*;
import static javax.swing.JOptionPane.*; import static javax.swing.JOptionPane.*;
import static net.sourceforge.filebot.Settings.*; import static net.sourceforge.filebot.Settings.*;
@ -52,32 +50,29 @@ import net.sourceforge.tuned.ui.ProgressDialog;
import net.sourceforge.tuned.ui.ProgressDialog.Cancellable; import net.sourceforge.tuned.ui.ProgressDialog.Cancellable;
import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter; import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter;
class RenameAction extends AbstractAction { class RenameAction extends AbstractAction {
public static final String RENAME_ACTION = "RENAME_ACTION"; public static final String RENAME_ACTION = "RENAME_ACTION";
private final RenameModel model; private final RenameModel model;
public RenameAction(RenameModel model) { public RenameAction(RenameModel model) {
this.model = model; this.model = model;
resetValues(); resetValues();
} }
public void resetValues() { public void resetValues() {
putValue(RENAME_ACTION, StandardRenameAction.MOVE); putValue(RENAME_ACTION, StandardRenameAction.MOVE);
putValue(NAME, "Rename"); putValue(NAME, "Rename");
putValue(SMALL_ICON, ResourceManager.getIcon("action.rename")); putValue(SMALL_ICON, ResourceManager.getIcon("action.rename"));
} }
@Override @Override
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
Window window = getWindow(evt.getSource()); Window window = getWindow(evt.getSource());
try { try {
if (model.getRenameMap().isEmpty()) { if (model.getRenameMap().isEmpty()) {
UILogger.info("Nothing to rename. Please add some files and create matches first.");
return; return;
} }
@ -138,7 +133,6 @@ class RenameAction extends AbstractAction {
window.setCursor(Cursor.getDefaultCursor()); window.setCursor(Cursor.getDefaultCursor());
} }
public boolean isNativeActionSupported(StandardRenameAction action) { public boolean isNativeActionSupported(StandardRenameAction action) {
try { try {
return NativeRenameAction.isSupported() && NativeRenameAction.valueOf(action.name()) != null; return NativeRenameAction.isSupported() && NativeRenameAction.valueOf(action.name()) != null;
@ -147,7 +141,6 @@ class RenameAction extends AbstractAction {
} }
} }
private Map<File, File> checkRenamePlan(List<Entry<File, File>> renamePlan, Window parent) { private Map<File, File> checkRenamePlan(List<Entry<File, File>> renamePlan, Window parent) {
// build rename map and perform some sanity checks // build rename map and perform some sanity checks
Map<File, File> renameMap = new HashMap<File, File>(); Map<File, File> renameMap = new HashMap<File, File>();
@ -207,7 +200,6 @@ class RenameAction extends AbstractAction {
return renameMap; return renameMap;
} }
private List<Entry<File, File>> validate(Map<File, String> renameMap, Window parent) { private List<Entry<File, File>> validate(Map<File, String> renameMap, Window parent) {
final List<Entry<File, File>> source = new ArrayList<Entry<File, File>>(renameMap.size()); final List<Entry<File, File>> source = new ArrayList<Entry<File, File>>(renameMap.size());
@ -222,13 +214,11 @@ class RenameAction extends AbstractAction {
return source.get(index).getValue(); return source.get(index).getValue();
} }
@Override @Override
public File set(int index, File name) { public File set(int index, File name) {
return source.get(index).setValue(name); return source.get(index).setValue(name);
} }
@Override @Override
public int size() { public int size() {
return source.size(); return source.size();
@ -244,7 +234,6 @@ class RenameAction extends AbstractAction {
return emptyList(); return emptyList();
} }
protected ProgressDialog createProgressDialog(Window parent, final RenameJob job) { protected ProgressDialog createProgressDialog(Window parent, final RenameJob job) {
final ProgressDialog dialog = new ProgressDialog(parent, job); final ProgressDialog dialog = new ProgressDialog(parent, job);
@ -267,7 +256,6 @@ class RenameAction extends AbstractAction {
} }
} }
@Override @Override
protected void done(PropertyChangeEvent evt) { protected void done(PropertyChangeEvent evt) {
dialog.close(); dialog.close();
@ -277,7 +265,6 @@ class RenameAction extends AbstractAction {
return dialog; return dialog;
} }
protected class RenameJob extends SwingWorker<Map<File, File>, Void> implements Cancellable { protected class RenameJob extends SwingWorker<Map<File, File>, Void> implements Cancellable {
protected final net.sourceforge.filebot.RenameAction action; protected final net.sourceforge.filebot.RenameAction action;
@ -287,14 +274,12 @@ class RenameAction extends AbstractAction {
protected final Semaphore postprocess = new Semaphore(0); protected final Semaphore postprocess = new Semaphore(0);
public RenameJob(Map<File, File> renameMap, net.sourceforge.filebot.RenameAction action) { public RenameJob(Map<File, File> renameMap, net.sourceforge.filebot.RenameAction action) {
this.action = action; this.action = action;
this.renameMap = synchronizedMap(renameMap); this.renameMap = synchronizedMap(renameMap);
this.renameLog = synchronizedMap(new LinkedHashMap<File, File>()); this.renameLog = synchronizedMap(new LinkedHashMap<File, File>());
} }
@Override @Override
protected Map<File, File> doInBackground() throws Exception { protected Map<File, File> doInBackground() throws Exception {
try { try {
@ -322,7 +307,6 @@ class RenameAction extends AbstractAction {
return renameLog; return renameLog;
} }
@Override @Override
protected void done() { protected void done() {
try { try {
@ -360,21 +344,18 @@ class RenameAction extends AbstractAction {
} }
} }
@Override @Override
public boolean cancel() { public boolean cancel() {
return cancel(true); return cancel(true);
} }
} }
protected class NativeRenameJob extends RenameJob implements Cancellable { protected class NativeRenameJob extends RenameJob implements Cancellable {
public NativeRenameJob(Map<File, File> renameMap, NativeRenameAction action) { public NativeRenameJob(Map<File, File> renameMap, NativeRenameAction action) {
super(renameMap, action); super(renameMap, action);
} }
@Override @Override
protected Map<File, File> doInBackground() throws Exception { protected Map<File, File> doInBackground() throws Exception {
NativeRenameAction shell = (NativeRenameAction) action; NativeRenameAction shell = (NativeRenameAction) action;
@ -409,7 +390,6 @@ class RenameAction extends AbstractAction {
return renameLog; return renameLog;
} }
@Override @Override
public boolean cancel() { public boolean cancel() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();

View File

@ -53,6 +53,7 @@ import net.sourceforge.filebot.WebServices;
import net.sourceforge.filebot.similarity.Match; import net.sourceforge.filebot.similarity.Match;
import net.sourceforge.filebot.ui.Language; import net.sourceforge.filebot.ui.Language;
import net.sourceforge.filebot.ui.rename.RenameModel.FormattedFuture; import net.sourceforge.filebot.ui.rename.RenameModel.FormattedFuture;
import net.sourceforge.filebot.ui.transfer.LoadAction;
import net.sourceforge.filebot.web.AudioTrack; import net.sourceforge.filebot.web.AudioTrack;
import net.sourceforge.filebot.web.AudioTrackFormat; import net.sourceforge.filebot.web.AudioTrackFormat;
import net.sourceforge.filebot.web.Episode; import net.sourceforge.filebot.web.Episode;
@ -183,7 +184,12 @@ public class RenamePanel extends JComponent {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// show popup on actionPerformed only when names list is empty // show popup on actionPerformed only when names list is empty
if (renameModel.size() > 0 && !renameModel.hasComplement(0)) { if (renameModel.size() == 0) {
new LoadAction(filesList.getTransferablePolicy()).actionPerformed(e);
if (renameModel.size() > 0) {
fetchPopupAction.actionPerformed(e);
}
} else if (renameModel.size() > 0 && !renameModel.hasComplement(0)) {
fetchPopupAction.actionPerformed(e); fetchPopupAction.actionPerformed(e);
} }
} }

View File

@ -103,7 +103,7 @@
<div> <div>
<ul> <ul>
<li><a href="http://www.filebot.net/forums/">Forums</a></li> <li><a href="http://www.filebot.net/forums/">Forums</a></li>
<li><a href="http://www.filebot.net/forums/viewtopic.php?f=3&amp;t=7">FAQ</a></li> <li><a href="http://www.filebot.net/forums/viewtopic.php?f=3&amp;t=7#p7">Manual</a></li>
<li><a href="http://www.filebot.net/#download">Download</a></li> <li><a href="http://www.filebot.net/#download">Download</a></li>
</ul> </ul>
</div> </div>