Skip to content

Commit 47a99c4

Browse files
authored
Merge pull request #353 from hajdam/master
Delete operation
2 parents 68e828a + 63a683c commit 47a99c4

7 files changed

Lines changed: 44 additions & 16 deletions

File tree

src/main/java/the/bytecode/club/bytecodeviewer/gui/components/FileChooser.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,17 @@ public FileChooser(boolean skipFileFilter, File file, String title, String descr
4343
{
4444
Set<String> extensionSet = new HashSet<>(Arrays.asList(extensions));
4545

46+
setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
4647
try {
47-
if(file.isDirectory())
48-
setCurrentDirectory(file);
49-
else
50-
setSelectedFile(file);
48+
setSelectedFile(file);
5149
} catch (Exception ignored) { }
5250

5351
setDialogTitle(title);
54-
setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
5552
setFileHidingEnabled(false);
5653
setAcceptAllFileFilterUsed(false);
5754
if(!skipFileFilter)
5855
{
59-
setFileFilter(new FileFilter()
56+
addChoosableFileFilter(new FileFilter()
6057
{
6158
@Override
6259
public boolean accept(File f)

src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/ContextMenu.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist.Open;
1212
import the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist.QuickEdit;
1313
import the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist.QuickOpen;
14-
import the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist.Remove;
14+
import the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist.Delete;
1515
import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceTree;
1616
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
1717

@@ -45,7 +45,7 @@ public class ContextMenu
4545
static
4646
{
4747
//resource list
48-
addContext(new Remove()); //TODO rename to delete and add support for resources & whole parent nodes (directories)
48+
addContext(new Delete()); //TODO add support for resources & whole parent nodes (directories)
4949
addContext(new New());
5050
addContext(new Open());
5151
addContext(new QuickOpen());

src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Remove.java renamed to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Delete.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@
2929
* @author Konloch
3030
* @since 7/26/2021
3131
*/
32-
public class Remove extends ContextMenuItem
32+
public class Delete extends ContextMenuItem
3333
{
34-
public Remove()
34+
public Delete()
3535
{
3636
super(ContextMenuType.CONTAINER, ((tree, selPath, result, menu) ->
3737
{
38-
menu.add(new AbstractAction(TranslatedStrings.REMOVE.toString())
38+
menu.add(new AbstractAction(TranslatedStrings.DELETE.toString())
3939
{
4040
@Override
4141
public void actionPerformed(ActionEvent e)
4242
{
43-
BytecodeViewer.viewer.resourcePane.expandAll(tree, selPath, false);
43+
BytecodeViewer.viewer.resourcePane.removeNode(tree, selPath);
4444
}
4545
});
4646
}));

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListPane.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import javax.swing.JScrollPane;
2020
import javax.swing.JTextField;
2121
import javax.swing.JTree;
22+
import javax.swing.tree.MutableTreeNode;
2223
import javax.swing.tree.TreeNode;
2324
import javax.swing.tree.TreePath;
2425
import me.konloch.kontainer.io.DiskWriter;
@@ -261,6 +262,36 @@ public void expandAll(final JTree tree, final TreePath parent,
261262
tree.collapsePath(parent);
262263
}
263264
}
265+
266+
@SuppressWarnings("rawtypes")
267+
public void removeNode(final JTree tree, final TreePath nodePath) {
268+
MutableTreeNode node = findNodeByPath(nodePath);
269+
if (node == null)
270+
return;
271+
272+
node.removeFromParent();
273+
tree.repaint();
274+
tree.updateUI();
275+
}
276+
277+
@SuppressWarnings("rawtypes")
278+
private MutableTreeNode findNodeByPath(TreePath path) {
279+
MutableTreeNode node = treeRoot;
280+
for (int pathStep = 1; pathStep < path.getPathCount(); pathStep++) {
281+
TreeNode pathNode = (TreeNode) path.getPathComponent(pathStep);
282+
int childIndex = node.getIndex(pathNode);
283+
if (childIndex < 0) {
284+
return null;
285+
}
286+
node = (MutableTreeNode) node.getChildAt(childIndex);
287+
288+
if (node == null) {
289+
return null;
290+
}
291+
}
292+
293+
return node;
294+
}
264295

265296
public void resetWorkspace()
266297
{

src/main/java/the/bytecode/club/bytecodeviewer/translation/TranslatedStrings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public enum TranslatedStrings
6262

6363
OPEN_UNSTYLED,
6464
QUICK_OPEN,
65-
REMOVE,
65+
DELETE,
6666
NEW,
6767
EXPAND,
6868
COLLAPSE,

src/main/java/the/bytecode/club/bytecodeviewer/util/DialogUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ public static File fileChooser(String title, String description, File directory,
9999
extensions);
100100

101101
if(filter != null)
102-
fc.setFileFilter(filter);
102+
fc.addChoosableFileFilter(filter);
103103
else
104-
fc.setFileFilter(new FileFilter()
104+
fc.addChoosableFileFilter(new FileFilter()
105105
{
106106
@Override
107107
public boolean accept(File f)

src/main/resources/translations/english.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"OPEN": "Open...",
88
"OPEN_UNSTYLED": "Open",
99
"QUICK_OPEN": "Quick Open",
10-
"REMOVE": "Remove",
10+
"DELETE": "Delete",
1111
"NEW": "New",
1212
"EXPAND": "Expand",
1313
"COLLAPSE": "Collapse",

0 commit comments

Comments
 (0)