Delete operation

This commit is contained in:
hajdam 2021-09-11 14:24:57 +02:00
parent c264e365cb
commit 94f983f005
7 changed files with 44 additions and 16 deletions

View File

@ -43,20 +43,17 @@ public class FileChooser extends JFileChooser
{
Set<String> extensionSet = new HashSet<>(Arrays.asList(extensions));
setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
try {
if(file.isDirectory())
setCurrentDirectory(file);
else
setSelectedFile(file);
setSelectedFile(file);
} catch (Exception ignored) { }
setDialogTitle(title);
setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
setFileHidingEnabled(false);
setAcceptAllFileFilterUsed(false);
if(!skipFileFilter)
{
setFileFilter(new FileFilter()
addChoosableFileFilter(new FileFilter()
{
@Override
public boolean accept(File f)

View File

@ -11,7 +11,7 @@ import the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist.New;
import the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist.Open;
import the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist.QuickEdit;
import the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist.QuickOpen;
import the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist.Remove;
import the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist.Delete;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceTree;
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
@ -45,7 +45,7 @@ public class ContextMenu
static
{
//resource list
addContext(new Remove()); //TODO rename to delete and add support for resources & whole parent nodes (directories)
addContext(new Delete());
addContext(new New());
addContext(new Open());
addContext(new QuickOpen());

View File

@ -29,18 +29,18 @@ import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
* @author Konloch
* @since 7/26/2021
*/
public class Remove extends ContextMenuItem
public class Delete extends ContextMenuItem
{
public Remove()
public Delete()
{
super(ContextMenuType.CONTAINER, ((tree, selPath, result, menu) ->
{
menu.add(new AbstractAction(TranslatedStrings.REMOVE.toString())
menu.add(new AbstractAction(TranslatedStrings.DELETE.toString())
{
@Override
public void actionPerformed(ActionEvent e)
{
BytecodeViewer.viewer.resourcePane.expandAll(tree, selPath, false);
BytecodeViewer.viewer.resourcePane.removeNode(tree, selPath);
}
});
}));

View File

@ -19,6 +19,7 @@ import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import me.konloch.kontainer.io.DiskWriter;
@ -261,6 +262,36 @@ public class ResourceListPane extends TranslatedVisibleComponent implements File
tree.collapsePath(parent);
}
}
@SuppressWarnings("rawtypes")
public void removeNode(final JTree tree, final TreePath nodePath) {
MutableTreeNode node = findNodeByPath(nodePath);
if (node == null)
return;
node.removeFromParent();
tree.repaint();
tree.updateUI();
}
@SuppressWarnings("rawtypes")
private MutableTreeNode findNodeByPath(TreePath path) {
MutableTreeNode node = treeRoot;
for (int pathStep = 1; pathStep < path.getPathCount(); pathStep++) {
TreeNode pathNode = (TreeNode) path.getPathComponent(pathStep);
int childIndex = node.getIndex(pathNode);
if (childIndex < 0) {
return null;
}
node = (MutableTreeNode) node.getChildAt(childIndex);
if (node == null) {
return null;
}
}
return node;
}
public void resetWorkspace()
{

View File

@ -62,7 +62,7 @@ public enum TranslatedStrings
OPEN_UNSTYLED,
QUICK_OPEN,
REMOVE,
DELETE,
NEW,
EXPAND,
COLLAPSE,

View File

@ -99,9 +99,9 @@ public class DialogUtils
extensions);
if(filter != null)
fc.setFileFilter(filter);
fc.addChoosableFileFilter(filter);
else
fc.setFileFilter(new FileFilter()
fc.addChoosableFileFilter(new FileFilter()
{
@Override
public boolean accept(File f)

View File

@ -7,7 +7,7 @@
"OPEN": "Open...",
"OPEN_UNSTYLED": "Open",
"QUICK_OPEN": "Quick Open",
"REMOVE": "Remove",
"DELETE": "Delete",
"NEW": "New",
"EXPAND": "Expand",
"COLLAPSE": "Collapse",