Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be able to drag playlist folders into Playlists-Directories panel #113

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 50 additions & 22 deletions src/main/java/listfix/view/GUIScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>null</code>.
* @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<File> fileList = (List<File>) 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;
}

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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();
}

// <editor-fold defaultstate="collapsed" desc="Generated Code">
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem _aboutMenuItem;
Expand Down