From 874c6ff4ebb05ced9ac699a6fad5b4fc003f9258 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 28 Mar 2016 20:45:46 +0000 Subject: [PATCH] Fix F2 mode issues --- source/net/filebot/ui/rename/RenamePanel.java | 43 +++++++++---------- source/net/filebot/util/ui/SwingUI.java | 11 +++++ 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index a3602579..490ff415 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -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,35 +325,33 @@ 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 xattr = WebServices.XattrMetaData.getMetaData(renameModel.files()); - List files = new ArrayList(renameModel.files()); - List objects = new ArrayList(files.size()); - List objectsTail = new ArrayList(); - 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 files = new ArrayList(xattr.keySet()); + List objects = new ArrayList(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(); - File file = (File) filesList.getListComponent().getModel().getElementAt(index); - String generatedName = namesList.getListComponent().getModel().getElementAt(index).toString(); + if (index >= 0) { + File file = (File) filesList.getListComponent().getModel().getElementAt(index); + String generatedName = namesList.getListComponent().getModel().getElementAt(index).toString(); - String forcedName = showInputDialog("Enter Name:", generatedName, "Enter Name", RenamePanel.this); - if (forcedName != null && forcedName.length() > 0) { - renameModel.matches().set(index, new Match(forcedName, file)); + String forcedName = showInputDialog("Enter Name:", generatedName, "Enter Name", RenamePanel.this); + if (forcedName != null && forcedName.length() > 0) { + renameModel.matches().set(index, new Match(forcedName, file)); + } } } } catch (Exception e) { diff --git a/source/net/filebot/util/ui/SwingUI.java b/source/net/filebot/util/ui/SwingUI.java index 089b02d8..3b695e0e 100644 --- a/source/net/filebot/util/ui/SwingUI.java +++ b/source/net/filebot/util/ui/SwingUI.java @@ -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 action) { return new JButton(new LambdaAction(name, icon, action)); }