Skip to content

Commit 9e08f06

Browse files
committed
Extended Context Menu API
This extends the right-click context menu API to support interactions on the search box panel
1 parent d95b9d0 commit 9e08f06

16 files changed

Lines changed: 288 additions & 69 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu;
1+
package the.bytecode.club.bytecodeviewer.gui.contextmenu;
22

33
import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceTree;
4+
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
45

56
import javax.swing.*;
67
import javax.swing.tree.TreePath;
@@ -29,5 +30,5 @@
2930
*/
3031
public interface BuildContextMenuItem
3132
{
32-
void buildMenu(ResourceTree tree, TreePath selPath, JPopupMenu menu);
33+
void buildMenu(ResourceTree tree, TreePath selPath, LDCSearchTreeNodeResult result, JPopupMenu menu);
3334
}

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

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu;
1+
package the.bytecode.club.bytecodeviewer.gui.contextmenu;
22

33
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
4-
import the.bytecode.club.bytecodeviewer.Constants;
54
import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceTree;
6-
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.impl.*;
5+
import the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist.*;
6+
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
7+
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
78

89
import javax.swing.*;
910
import javax.swing.tree.DefaultMutableTreeNode;
1011
import javax.swing.tree.TreePath;
12+
import java.awt.event.ActionEvent;
1113
import java.util.ArrayList;
1214

1315
/***************************************************************************
@@ -39,50 +41,69 @@ public class ContextMenu
3941

4042
static
4143
{
44+
//resource list
4245
addContext(new Remove()); //TODO rename to delete and add support for resources & whole parent nodes (directories)
4346
addContext(new New());
4447
addContext(new Open());
4548
addContext(new QuickOpen());
4649
addContext(new QuickEdit());
4750
addContext(new Expand());
4851
addContext(new Collapse());
52+
53+
//search box
54+
addContext(new the.bytecode.club.bytecodeviewer.gui.contextmenu.searchbox.Open());
55+
addContext(new the.bytecode.club.bytecodeviewer.gui.contextmenu.searchbox.QuickOpen());
56+
addContext(new the.bytecode.club.bytecodeviewer.gui.contextmenu.searchbox.QuickEdit());
4957
}
5058

5159
public static void addContext(ContextMenuItem menuItem)
5260
{
5361
SINGLETON.contextMenuItems.add(menuItem);
5462
}
5563

56-
public static void buildMenu(ResourceTree tree, TreePath selPath, JPopupMenu menu)
64+
public static void buildMenu(ResourceTree tree, TreePath selPath, LDCSearchTreeNodeResult selectedNode, JPopupMenu menu)
5765
{
5866
menu.removeAll();
5967

60-
boolean isContainerSelected = selPath.getParentPath() != null && selPath.getParentPath().getParentPath() == null;
68+
boolean searchBoxPane = selectedNode != null;
69+
boolean isContainerSelected = !searchBoxPane && selPath.getParentPath() != null && selPath.getParentPath().getParentPath() == null;
70+
boolean isResourceSelected = false;
6171

6272
//TODO this is hacky - there is probably a better way to do this
63-
tree.setSelectionPath(selPath);
64-
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
65-
boolean isResourceSelected = !node.children().hasMoreElements();
73+
if(!searchBoxPane)
74+
{
75+
tree.setSelectionPath(selPath);
76+
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
77+
isResourceSelected = !node.children().hasMoreElements();
78+
}
6679

6780
for(ContextMenuItem item : SINGLETON.contextMenuItems)
6881
{
6982
switch(item.getMenuType())
7083
{
7184
case CONTAINER:
72-
if(!isContainerSelected)
85+
if(!isContainerSelected || searchBoxPane)
7386
continue;
7487
break;
7588
case RESOURCE:
76-
if(!isResourceSelected || isContainerSelected)
89+
if(!isResourceSelected || isContainerSelected || searchBoxPane)
7790
continue;
7891
break;
7992
case DIRECTORY:
80-
if(isResourceSelected)
93+
if(isResourceSelected || searchBoxPane)
94+
continue;
95+
break;
96+
case RESOURCE_LIST:
97+
if(searchBoxPane)
98+
continue;
99+
break;
100+
case SEARCH_BOX_RESULT:
101+
if(!searchBoxPane)
81102
continue;
82103
break;
83104
}
84105

85-
item.getBuildContextMenuItem().buildMenu(tree, selPath, menu);
106+
item.getBuildContextMenuItem().buildMenu(tree, selPath, selectedNode, menu);
86107
}
87108
}
88109
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu;
1+
package the.bytecode.club.bytecodeviewer.gui.contextmenu;
22

33
/***************************************************************************
44
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu;
1+
package the.bytecode.club.bytecodeviewer.gui.contextmenu;
22

33
/***************************************************************************
44
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
@@ -24,8 +24,9 @@
2424
*/
2525
public enum ContextMenuType
2626
{
27-
ALL,
27+
RESOURCE_LIST,
2828
RESOURCE,
2929
DIRECTORY,
3030
CONTAINER,
31+
SEARCH_BOX_RESULT,
3132
}

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/Collapse.java renamed to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Collapse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.impl;
1+
package the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist;
22

33
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
4-
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem;
5-
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType;
4+
import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem;
5+
import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType;
66
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
77

88
import javax.swing.*;
@@ -34,7 +34,7 @@ public class Collapse extends ContextMenuItem
3434
{
3535
public Collapse()
3636
{
37-
super(ContextMenuType.DIRECTORY, ((tree, selPath, menu) ->
37+
super(ContextMenuType.DIRECTORY, ((tree, selPath, result, menu) ->
3838
{
3939
menu.add(new AbstractAction(TranslatedStrings.COLLAPSE.toString())
4040
{

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/Expand.java renamed to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Expand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.impl;
1+
package the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist;
22

33
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
4-
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem;
5-
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType;
4+
import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem;
5+
import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType;
66
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
77

88
import javax.swing.*;
@@ -34,7 +34,7 @@ public class Expand extends ContextMenuItem
3434
{
3535
public Expand()
3636
{
37-
super(ContextMenuType.DIRECTORY, ((tree, selPath, menu) ->
37+
super(ContextMenuType.DIRECTORY, ((tree, selPath, result, menu) ->
3838
{
3939
menu.add(new AbstractAction(TranslatedStrings.EXPAND.toString())
4040
{

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/New.java renamed to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/New.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.impl;
1+
package the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist;
22

33
import org.apache.commons.io.FilenameUtils;
44
import org.objectweb.asm.tree.ClassNode;
55
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
66
import the.bytecode.club.bytecodeviewer.Constants;
77
import the.bytecode.club.bytecodeviewer.api.ASMUtil;
8-
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
9-
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem;
10-
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType;
8+
import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem;
9+
import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType;
1110
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
1211

1312
import javax.swing.*;
1413
import javax.swing.tree.DefaultMutableTreeNode;
15-
import javax.swing.tree.MutableTreeNode;
1614
import javax.swing.tree.TreeNode;
1715
import javax.swing.tree.TreePath;
1816
import java.util.Enumeration;
@@ -43,7 +41,7 @@ public class New extends ContextMenuItem
4341
{
4442
public New()
4543
{
46-
super(ContextMenuType.ALL, ((tree, selPath, menu) ->
44+
super(ContextMenuType.RESOURCE_LIST, ((tree, selPath, result, menu) ->
4745
{
4846
JMenu quickOpen = new JMenu(TranslatedStrings.NEW.toString());
4947
quickOpen.add(createMenu("Class", FileType.CLASS, selPath));

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/Open.java renamed to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Open.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.impl;
1+
package the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist;
22

33
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
4-
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem;
5-
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType;
4+
import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem;
5+
import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType;
66
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
77

88
import javax.swing.*;
@@ -34,7 +34,7 @@ public class Open extends ContextMenuItem
3434
{
3535
public Open()
3636
{
37-
super(ContextMenuType.RESOURCE, ((tree, selPath, menu) ->
37+
super(ContextMenuType.RESOURCE, ((tree, selPath, result, menu) ->
3838
{
3939
menu.add(new AbstractAction(TranslatedStrings.OPEN_UNSTYLED.toString())
4040
{

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/QuickEdit.java renamed to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/QuickEdit.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.impl;
1+
package the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist;
22

33
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
44
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
5-
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem;
6-
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType;
5+
import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem;
6+
import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType;
77
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
88

99
import javax.swing.*;
@@ -34,7 +34,7 @@ public class QuickEdit extends ContextMenuItem
3434
{
3535
public QuickEdit()
3636
{
37-
super(ContextMenuType.RESOURCE, ((tree, selPath, menu) ->
37+
super(ContextMenuType.RESOURCE, ((tree, selPath, result, menu) ->
3838
{
3939
JMenu quickOpen = new JMenu("Quick Edit");
4040
quickOpen.add(createMenu(TranslatedStrings.KRAKATAU.toString(), ()->

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/QuickOpen.java renamed to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/QuickOpen.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.impl;
1+
package the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist;
22

33
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
44
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
5-
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem;
6-
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType;
5+
import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem;
6+
import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType;
77
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
88

99
import javax.swing.*;
@@ -34,7 +34,7 @@ public class QuickOpen extends ContextMenuItem
3434
{
3535
public QuickOpen()
3636
{
37-
super(ContextMenuType.RESOURCE, ((tree, selPath, menu) ->
37+
super(ContextMenuType.RESOURCE, ((tree, selPath, result, menu) ->
3838
{
3939
JMenu quickOpen = new JMenu(TranslatedStrings.QUICK_OPEN.toString());
4040
quickOpen.add(createMenu(TranslatedStrings.PROCYON.toString(), ()->BytecodeViewer.viewer.resourcePane.quickDecompile(Decompiler.PROCYON_DECOMPILER, selPath, false)));

0 commit comments

Comments
 (0)