Merge pull request #353 from hajdam/master

Delete operation
This commit is contained in:
Konloch 2021-09-15 14:57:53 -07:00 committed by GitHub
commit 47a99c4e90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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()); //TODO add support for resources & whole parent nodes (directories)
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",