1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 00:38:52 -05:00

Fix F2 mode issues

This commit is contained in:
Reinhard Pointner 2016-03-28 20:45:46 +00:00
parent d74347591b
commit 874c6ff4eb
2 changed files with 31 additions and 23 deletions

View File

@ -6,7 +6,6 @@ import static javax.swing.KeyStroke.*;
import static javax.swing.SwingUtilities.*;
import static net.filebot.Logging.*;
import static net.filebot.Settings.*;
import static net.filebot.media.XattrMetaInfo.*;
import static net.filebot.util.ExceptionUtilities.*;
import static net.filebot.util.ui.LoadingOverlayPane.*;
import static net.filebot.util.ui.SwingUI.*;
@ -326,29 +325,26 @@ public class RenamePanel extends JComponent {
public void actionPerformed(ActionEvent evt) {
try {
if (namesList.getModel().isEmpty()) {
try {
getWindow(evt.getSource()).setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
withWaitCursor(evt.getSource(), () -> {
// try to read xattr from all files
Map<File, Object> xattr = WebServices.XattrMetaData.getMetaData(renameModel.files());
List<File> files = new ArrayList<File>(renameModel.files());
List<Object> objects = new ArrayList<Object>(files.size());
List<File> objectsTail = new ArrayList<File>();
for (File file : files) {
Object metaObject = xattr.getMetaInfo(file);
if (metaObject != null) {
objects.add(metaObject); // upper list is based on xattr metadata
} else {
objectsTail.add(file); // lower list is just the fallback file object
}
}
objects.addAll(objectsTail);
// upper list is based on xattr metadata
List<File> files = new ArrayList<File>(xattr.keySet());
List<Object> objects = new ArrayList<Object>(xattr.values());
// lower list is just the fallback file object
renameModel.files().stream().filter(f -> !xattr.containsKey(f)).forEach(f -> {
files.add(f);
objects.add(f);
});
renameModel.clear();
renameModel.addAll(objects, files);
} finally {
getWindow(evt.getSource()).setCursor(Cursor.getDefaultCursor());
}
});
} else {
int index = namesList.getListComponent().getSelectedIndex();
if (index >= 0) {
File file = (File) filesList.getListComponent().getModel().getElementAt(index);
String generatedName = namesList.getListComponent().getModel().getElementAt(index).toString();
@ -357,6 +353,7 @@ public class RenamePanel extends JComponent {
renameModel.matches().set(index, new Match<Object, File>(forcedName, file));
}
}
}
} catch (Exception e) {
debug.log(Level.WARNING, e.getMessage(), e);
}

View File

@ -5,6 +5,7 @@ import static javax.swing.JOptionPane.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics2D;
@ -261,6 +262,16 @@ public final class SwingUI {
return timer;
}
public static void withWaitCursor(Object source, BackgroundRunnable runnable) throws Exception {
Window window = getWindow(source);
try {
window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
runnable.run();
} finally {
window.setCursor(Cursor.getDefaultCursor());
}
}
public static JButton newButton(String name, Icon icon, Consumer<ActionEvent> action) {
return new JButton(new LambdaAction(name, icon, action));
}