Skip to content

Commit

Permalink
Fix rename playlist dialog, initializing with file name
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Feb 13, 2023
1 parent 63c42fc commit d97ad8b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 65 deletions.
10 changes: 2 additions & 8 deletions src/main/java/listfix/io/FileTreeNodeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,10 @@ public static PlaylistTreeNode addNodes(PlaylistTreeNode curTop, File[] files)
continue;
}

String curPath = playlistDir.getPath();
TreeNodeFile file = new TreeNodeFile(curPath);
PlaylistTreeNode curDir = new PlaylistTreeNode(file);
PlaylistTreeNode curDir = new PlaylistTreeNode(playlistDir);
curTop.add(curDir);

// if we're creating the root node here, use a regular file to get the full path to show.
curDir.setUserObject(new File(curPath));

File[] inodes = playlistDir.listFiles(new PlaylistFileFilter());

final File[] inodes = playlistDir.listFiles(new PlaylistFileFilter());
if (inodes != null && inodes.length > 0)
{
addNodes(curDir, inodes);
Expand Down
47 changes: 0 additions & 47 deletions src/main/java/listfix/io/TreeNodeFile.java

This file was deleted.

24 changes: 14 additions & 10 deletions src/main/java/listfix/view/GUIScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import javax.swing.event.TreeModelListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.plaf.FontUIResource;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreePath;
Expand Down Expand Up @@ -1339,9 +1338,7 @@ private void deleteTreeSelectedPlaylists()
private void renameTreeSelectedNode()
{
int[] selRows = _playlistDirectoryTree.getSelectionRows();
DefaultMutableTreeNode curNode;
DefaultTreeModel treeModel = (DefaultTreeModel) _playlistDirectoryTree.getModel();
TreeNodeFile nodeFile;
if (selRows != null && selRows.length > 0)
{
if (JOptionPane.showConfirmDialog(this, new JTransparentTextArea("Are you sure you want to rename the selected files and folders?"), "Rename Selected Files & Folders?", JOptionPane.ERROR_MESSAGE) == JOptionPane.YES_OPTION)
Expand All @@ -1353,16 +1350,23 @@ private void renameTreeSelectedNode()
}
for (TreePath selPath : selPaths)
{
curNode = (DefaultMutableTreeNode) selPath.getLastPathComponent();
nodeFile = (TreeNodeFile) curNode.getUserObject();
PlaylistTreeNode curNode = (PlaylistTreeNode) selPath.getLastPathComponent();
File nodeFile = curNode.getUserObject();
String str = curNode.toString();
String reply = JOptionPane.showInputDialog(this, new JTransparentTextArea("Rename " + str), "." + FileUtils.getFileExtension(nodeFile.getName()));
String reply = JOptionPane.showInputDialog(this, new JTransparentTextArea("Rename " + str), nodeFile.toPath().getFileName().toString());
if (reply != null && !"".equals(reply))
{
TreeNodeFile destFile = new TreeNodeFile(nodeFile.getParent() + Constants.FS + reply);
nodeFile.renameTo(destFile);
curNode.setUserObject(destFile);
treeModel.nodeChanged(curNode);
final File destFile = new File(nodeFile.getParent(), reply);
_logger.info(String.format("Rename playlist \"%s\" to \"%s\"", nodeFile, reply));
if (nodeFile.renameTo(destFile)) {
curNode.setUserObject(destFile);
treeModel.nodeChanged(curNode);
// ToDo: update tab
}
else
{
_logger.warn("Renaming playlist failed");
}
}
}
}
Expand Down

0 comments on commit d97ad8b

Please sign in to comment.