|
1 | | -package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu; |
| 1 | +package the.bytecode.club.bytecodeviewer.gui.contextmenu; |
2 | 2 |
|
3 | 3 | import the.bytecode.club.bytecodeviewer.BytecodeViewer; |
4 | | -import the.bytecode.club.bytecodeviewer.Constants; |
5 | 4 | 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; |
7 | 8 |
|
8 | 9 | import javax.swing.*; |
9 | 10 | import javax.swing.tree.DefaultMutableTreeNode; |
10 | 11 | import javax.swing.tree.TreePath; |
| 12 | +import java.awt.event.ActionEvent; |
11 | 13 | import java.util.ArrayList; |
12 | 14 |
|
13 | 15 | /*************************************************************************** |
@@ -39,50 +41,69 @@ public class ContextMenu |
39 | 41 |
|
40 | 42 | static |
41 | 43 | { |
| 44 | + //resource list |
42 | 45 | addContext(new Remove()); //TODO rename to delete and add support for resources & whole parent nodes (directories) |
43 | 46 | addContext(new New()); |
44 | 47 | addContext(new Open()); |
45 | 48 | addContext(new QuickOpen()); |
46 | 49 | addContext(new QuickEdit()); |
47 | 50 | addContext(new Expand()); |
48 | 51 | 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()); |
49 | 57 | } |
50 | 58 |
|
51 | 59 | public static void addContext(ContextMenuItem menuItem) |
52 | 60 | { |
53 | 61 | SINGLETON.contextMenuItems.add(menuItem); |
54 | 62 | } |
55 | 63 |
|
56 | | - public static void buildMenu(ResourceTree tree, TreePath selPath, JPopupMenu menu) |
| 64 | + public static void buildMenu(ResourceTree tree, TreePath selPath, LDCSearchTreeNodeResult selectedNode, JPopupMenu menu) |
57 | 65 | { |
58 | 66 | menu.removeAll(); |
59 | 67 |
|
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; |
61 | 71 |
|
62 | 72 | //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 | + } |
66 | 79 |
|
67 | 80 | for(ContextMenuItem item : SINGLETON.contextMenuItems) |
68 | 81 | { |
69 | 82 | switch(item.getMenuType()) |
70 | 83 | { |
71 | 84 | case CONTAINER: |
72 | | - if(!isContainerSelected) |
| 85 | + if(!isContainerSelected || searchBoxPane) |
73 | 86 | continue; |
74 | 87 | break; |
75 | 88 | case RESOURCE: |
76 | | - if(!isResourceSelected || isContainerSelected) |
| 89 | + if(!isResourceSelected || isContainerSelected || searchBoxPane) |
77 | 90 | continue; |
78 | 91 | break; |
79 | 92 | 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) |
81 | 102 | continue; |
82 | 103 | break; |
83 | 104 | } |
84 | 105 |
|
85 | | - item.getBuildContextMenuItem().buildMenu(tree, selPath, menu); |
| 106 | + item.getBuildContextMenuItem().buildMenu(tree, selPath, selectedNode, menu); |
86 | 107 | } |
87 | 108 | } |
88 | 109 | } |
0 commit comments