From 943c6db8653f39e0f612e33f74c606c21b4a091b Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 10 Aug 2014 08:35:53 +0000 Subject: [PATCH] * refactor revealFiles --- source/net/filebot/UserFiles.java | 22 ++++++++++++------- source/net/filebot/mac/DropToUnlock.java | 8 +------ source/net/filebot/ui/analyze/FileTree.java | 11 +--------- source/net/filebot/ui/rename/RenamePanel.java | 3 +-- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/source/net/filebot/UserFiles.java b/source/net/filebot/UserFiles.java index df0481e1..8f912cb5 100644 --- a/source/net/filebot/UserFiles.java +++ b/source/net/filebot/UserFiles.java @@ -10,6 +10,7 @@ import java.awt.Dialog; import java.awt.FileDialog; import java.awt.Frame; import java.io.File; +import java.util.Collection; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; @@ -23,15 +24,20 @@ import net.filebot.util.FileUtilities.ExtensionFileFilter; public class UserFiles { - public static void revealFile(File file) { - try { - if (isMacApp()) { - MacAppUtilities.revealInFinder(file); - } else { - Desktop.getDesktop().open(file.getParentFile()); + public static void revealFiles(Collection files) { + if (isMacApp()) { + for (File it : files) { + MacAppUtilities.revealInFinder(it); } - } catch (Exception e) { - Logger.getLogger(UserFiles.class.getName()).log(Level.WARNING, e.toString()); + } else { + // if we can't reveal the file in folder, just reveal the parent folder + files.stream().map(it -> it.getParentFile()).distinct().forEach(it -> { + try { + Desktop.getDesktop().open(it); + } catch (Exception e) { + Logger.getLogger(UserFiles.class.getName()).log(Level.WARNING, e.toString()); + } + }); } } diff --git a/source/net/filebot/mac/DropToUnlock.java b/source/net/filebot/mac/DropToUnlock.java index aab806ac..3624ce5d 100644 --- a/source/net/filebot/mac/DropToUnlock.java +++ b/source/net/filebot/mac/DropToUnlock.java @@ -158,13 +158,7 @@ public class DropToUnlock extends JList { // open required folders for easy drag and drop (a few milliseconds after the dialog has become visible) invokeLater(500, () -> { - try { - for (File it : model) { - revealFile(it); - } - } catch (Exception e) { - Logger.getLogger(DropToUnlock.class.getName()).log(Level.WARNING, e.toString()); - } + revealFiles(model); }); // show and wait for user input diff --git a/source/net/filebot/ui/analyze/FileTree.java b/source/net/filebot/ui/analyze/FileTree.java index 49add7f7..0fcb9a7f 100644 --- a/source/net/filebot/ui/analyze/FileTree.java +++ b/source/net/filebot/ui/analyze/FileTree.java @@ -1,7 +1,6 @@ package net.filebot.ui.analyze; import static java.util.Collections.*; -import static net.filebot.ui.NotificationLogging.*; import java.awt.Font; import java.awt.event.ActionEvent; @@ -15,7 +14,6 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import java.util.logging.Level; import javax.swing.AbstractAction; import javax.swing.Action; @@ -29,7 +27,6 @@ import javax.swing.tree.TreeSelectionModel; import net.filebot.ResourceManager; import net.filebot.UserFiles; -import net.filebot.util.ExceptionUtilities; import net.filebot.util.FilterIterator; import net.filebot.util.TreeIterator; @@ -118,13 +115,7 @@ public class FileTree extends JTree { } public void actionPerformed(ActionEvent event) { - try { - for (Object file : (Collection) getValue("files")) { - UserFiles.revealFile((File) file); - } - } catch (Exception e) { - UILogger.log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e); - } + UserFiles.revealFiles((Collection) getValue("files")); } } diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index a198ee7e..b06a84f4 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -247,8 +247,7 @@ public class RenamePanel extends JComponent { try { JList list = (JList) evt.getSource(); if (list.getSelectedIndex() >= 0) { - File item = (File) list.getSelectedValue(); - UserFiles.revealFile(item); + UserFiles.revealFiles((List) list.getSelectedValuesList()); } } catch (Exception e) { Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.getMessage());