diff --git a/src/main/java/listfix/view/GUIScreen.java b/src/main/java/listfix/view/GUIScreen.java
index e74d2fb4..dc3940e1 100644
--- a/src/main/java/listfix/view/GUIScreen.java
+++ b/src/main/java/listfix/view/GUIScreen.java
@@ -355,14 +355,38 @@ private TransferHandler createPlaylistTreeTransferHandler()
return new TransferHandler()
{
@Override
- public boolean canImport(TransferHandler.TransferSupport info)
+ public boolean canImport(JComponent comp, DataFlavor[] transferFlavors)
{
- return false;
+ return Arrays.stream(transferFlavors).anyMatch(DataFlavor.javaFileListFlavor :: equals);
}
+ /**
+ * Causes a transfer to occur from a clipboard or a drag and drop operation.
+ * @param support the object containing the details of the transfer, not null
.
+ * @return true if the data was inserted into the component, false otherwise
+ */
@Override
- public boolean importData(TransferHandler.TransferSupport info)
+ public boolean importData(TransferHandler.TransferSupport support)
{
+ final Transferable transferable = support.getTransferable();
+ if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
+ {
+ try
+ {
+ List fileList = (List) transferable.getTransferData(DataFlavor.javaFileListFlavor);
+ return fileList.stream()
+ .filter(File :: isDirectory)
+ .map(folder -> {
+ GUIScreen.this.addPlaylist(folder);
+ return true;
+ })
+ .reduce(false, (t, v) -> true);
+ }
+ catch (Exception e)
+ {
+ _logger.error("Dragging onto playlists directory failed", e);
+ }
+ }
return false;
}
@@ -2453,25 +2477,7 @@ private void _btnAddPlaylistsDirActionPerformed(java.awt.event.ActionEvent evt)/
int response = _jMediaDirChooser.showOpenDialog(this);
if (response == JFileChooser.APPROVE_OPTION)
{
- String path = _jMediaDirChooser.getSelectedFile().getPath();
- if (new File(path).exists())
- {
- _logger.info(String.format("Add playlist directory to configuration: %s", path));
- this.getApplicationConfig().getPlaylistDirectories().add(path);
- }
- else
- {
- JOptionPane.showMessageDialog(this, new JTransparentTextArea("The directory you selected/entered does not exist."));
- }
- try
- {
- this._listFixController.getApplicationConfiguration().write();
- }
- catch (IOException e)
- {
- throw new RuntimeException("Failed to write application configuration", e);
- }
- this.updatePlaylistDirectoryPanel();
+ this.addPlaylist(_jMediaDirChooser.getSelectedFile().getAbsoluteFile());
}
}//GEN-LAST:event__btnSetPlaylistsDirActionPerformed
@@ -2807,6 +2813,28 @@ public static void main(String[] args) throws IOException, InterruptedException,
}
}
+ private void addPlaylist(File playlistFile)
+ {
+ if (playlistFile.exists())
+ {
+ _logger.info(String.format("Add playlist directory to configuration: %s", playlistFile));
+ this.getApplicationConfig().getPlaylistDirectories().add(playlistFile.getAbsolutePath());
+ }
+ else
+ {
+ JOptionPane.showMessageDialog(this, new JTransparentTextArea("The directory you selected/entered does not exist."));
+ }
+ try
+ {
+ this._listFixController.getApplicationConfiguration().write();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Failed to write application configuration", e);
+ }
+ this.updatePlaylistDirectoryPanel();
+ }
+
//
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem _aboutMenuItem;