diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/BuildContextMenuItem.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/BuildContextMenuItem.java similarity index 86% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/BuildContextMenuItem.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/BuildContextMenuItem.java index dba773b1..371c4902 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/BuildContextMenuItem.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/BuildContextMenuItem.java @@ -1,6 +1,7 @@ -package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu; +package the.bytecode.club.bytecodeviewer.gui.contextmenu; import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceTree; +import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult; import javax.swing.*; import javax.swing.tree.TreePath; @@ -29,5 +30,5 @@ import javax.swing.tree.TreePath; */ public interface BuildContextMenuItem { - void buildMenu(ResourceTree tree, TreePath selPath, JPopupMenu menu); + void buildMenu(ResourceTree tree, TreePath selPath, LDCSearchTreeNodeResult result, JPopupMenu menu); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/ContextMenu.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/ContextMenu.java similarity index 63% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/ContextMenu.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/ContextMenu.java index 34221ca0..6b8d96cf 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/ContextMenu.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/ContextMenu.java @@ -1,13 +1,15 @@ -package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu; +package the.bytecode.club.bytecodeviewer.gui.contextmenu; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.Constants; import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceTree; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.impl.*; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist.*; +import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult; +import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; +import java.awt.event.ActionEvent; import java.util.ArrayList; /*************************************************************************** @@ -39,6 +41,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 New()); addContext(new Open()); @@ -46,6 +49,11 @@ public class ContextMenu addContext(new QuickEdit()); addContext(new Expand()); addContext(new Collapse()); + + //search box + addContext(new the.bytecode.club.bytecodeviewer.gui.contextmenu.searchbox.Open()); + addContext(new the.bytecode.club.bytecodeviewer.gui.contextmenu.searchbox.QuickOpen()); + addContext(new the.bytecode.club.bytecodeviewer.gui.contextmenu.searchbox.QuickEdit()); } public static void addContext(ContextMenuItem menuItem) @@ -53,36 +61,49 @@ public class ContextMenu SINGLETON.contextMenuItems.add(menuItem); } - public static void buildMenu(ResourceTree tree, TreePath selPath, JPopupMenu menu) + public static void buildMenu(ResourceTree tree, TreePath selPath, LDCSearchTreeNodeResult selectedNode, JPopupMenu menu) { menu.removeAll(); - boolean isContainerSelected = selPath.getParentPath() != null && selPath.getParentPath().getParentPath() == null; + boolean searchBoxPane = selectedNode != null; + boolean isContainerSelected = !searchBoxPane && selPath.getParentPath() != null && selPath.getParentPath().getParentPath() == null; + boolean isResourceSelected = false; //TODO this is hacky - there is probably a better way to do this - tree.setSelectionPath(selPath); - DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); - boolean isResourceSelected = !node.children().hasMoreElements(); + if(!searchBoxPane) + { + tree.setSelectionPath(selPath); + DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); + isResourceSelected = !node.children().hasMoreElements(); + } for(ContextMenuItem item : SINGLETON.contextMenuItems) { switch(item.getMenuType()) { case CONTAINER: - if(!isContainerSelected) + if(!isContainerSelected || searchBoxPane) continue; break; case RESOURCE: - if(!isResourceSelected || isContainerSelected) + if(!isResourceSelected || isContainerSelected || searchBoxPane) continue; break; case DIRECTORY: - if(isResourceSelected) + if(isResourceSelected || searchBoxPane) + continue; + break; + case RESOURCE_LIST: + if(searchBoxPane) + continue; + break; + case SEARCH_BOX_RESULT: + if(!searchBoxPane) continue; break; } - item.getBuildContextMenuItem().buildMenu(tree, selPath, menu); + item.getBuildContextMenuItem().buildMenu(tree, selPath, selectedNode, menu); } } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/ContextMenuItem.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/ContextMenuItem.java similarity index 96% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/ContextMenuItem.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/ContextMenuItem.java index 6d0b78c4..0a124fda 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/ContextMenuItem.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/ContextMenuItem.java @@ -1,4 +1,4 @@ -package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu; +package the.bytecode.club.bytecodeviewer.gui.contextmenu; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/ContextMenuType.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/ContextMenuType.java similarity index 93% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/ContextMenuType.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/ContextMenuType.java index 312f8ce4..b3356887 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/ContextMenuType.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/ContextMenuType.java @@ -1,4 +1,4 @@ -package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu; +package the.bytecode.club.bytecodeviewer.gui.contextmenu; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * @@ -24,8 +24,9 @@ package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu; */ public enum ContextMenuType { - ALL, + RESOURCE_LIST, RESOURCE, DIRECTORY, CONTAINER, + SEARCH_BOX_RESULT, } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/Collapse.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Collapse.java similarity index 85% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/Collapse.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Collapse.java index 6b62a99c..39e99265 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/Collapse.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Collapse.java @@ -1,8 +1,8 @@ -package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.impl; +package the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import javax.swing.*; @@ -34,7 +34,7 @@ public class Collapse extends ContextMenuItem { public Collapse() { - super(ContextMenuType.DIRECTORY, ((tree, selPath, menu) -> + super(ContextMenuType.DIRECTORY, ((tree, selPath, result, menu) -> { menu.add(new AbstractAction(TranslatedStrings.COLLAPSE.toString()) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/Expand.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Expand.java similarity index 85% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/Expand.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Expand.java index d346a701..1b1b6a9f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/Expand.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Expand.java @@ -1,8 +1,8 @@ -package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.impl; +package the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import javax.swing.*; @@ -34,7 +34,7 @@ public class Expand extends ContextMenuItem { public Expand() { - super(ContextMenuType.DIRECTORY, ((tree, selPath, menu) -> + super(ContextMenuType.DIRECTORY, ((tree, selPath, result, menu) -> { menu.add(new AbstractAction(TranslatedStrings.EXPAND.toString()) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/New.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/New.java similarity index 93% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/New.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/New.java index 5ca9ed13..309bff2a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/New.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/New.java @@ -1,18 +1,16 @@ -package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.impl; +package the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist; import org.apache.commons.io.FilenameUtils; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Constants; import the.bytecode.club.bytecodeviewer.api.ASMUtil; -import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.MutableTreeNode; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import java.util.Enumeration; @@ -43,7 +41,7 @@ public class New extends ContextMenuItem { public New() { - super(ContextMenuType.ALL, ((tree, selPath, menu) -> + super(ContextMenuType.RESOURCE_LIST, ((tree, selPath, result, menu) -> { JMenu quickOpen = new JMenu(TranslatedStrings.NEW.toString()); quickOpen.add(createMenu("Class", FileType.CLASS, selPath)); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/Open.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Open.java similarity index 85% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/Open.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Open.java index 9ebe7180..d2854807 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/Open.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Open.java @@ -1,8 +1,8 @@ -package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.impl; +package the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import javax.swing.*; @@ -34,7 +34,7 @@ public class Open extends ContextMenuItem { public Open() { - super(ContextMenuType.RESOURCE, ((tree, selPath, menu) -> + super(ContextMenuType.RESOURCE, ((tree, selPath, result, menu) -> { menu.add(new AbstractAction(TranslatedStrings.OPEN_UNSTYLED.toString()) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/QuickEdit.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/QuickEdit.java similarity index 87% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/QuickEdit.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/QuickEdit.java index 030cea8a..2c5f9498 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/QuickEdit.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/QuickEdit.java @@ -1,9 +1,9 @@ -package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.impl; +package the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import javax.swing.*; @@ -34,7 +34,7 @@ public class QuickEdit extends ContextMenuItem { public QuickEdit() { - super(ContextMenuType.RESOURCE, ((tree, selPath, menu) -> + super(ContextMenuType.RESOURCE, ((tree, selPath, result, menu) -> { JMenu quickOpen = new JMenu("Quick Edit"); quickOpen.add(createMenu(TranslatedStrings.KRAKATAU.toString(), ()-> diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/QuickOpen.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/QuickOpen.java similarity index 90% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/QuickOpen.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/QuickOpen.java index 13393c75..948d5587 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/QuickOpen.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/QuickOpen.java @@ -1,9 +1,9 @@ -package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.impl; +package the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import javax.swing.*; @@ -34,7 +34,7 @@ public class QuickOpen extends ContextMenuItem { public QuickOpen() { - super(ContextMenuType.RESOURCE, ((tree, selPath, menu) -> + super(ContextMenuType.RESOURCE, ((tree, selPath, result, menu) -> { JMenu quickOpen = new JMenu(TranslatedStrings.QUICK_OPEN.toString()); quickOpen.add(createMenu(TranslatedStrings.PROCYON.toString(), ()->BytecodeViewer.viewer.resourcePane.quickDecompile(Decompiler.PROCYON_DECOMPILER, selPath, false))); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/Remove.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Remove.java similarity index 85% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/Remove.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Remove.java index 0fc76c19..caf330ed 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/contextmenu/impl/Remove.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Remove.java @@ -1,8 +1,8 @@ -package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.impl; +package the.bytecode.club.bytecodeviewer.gui.contextmenu.resourcelist; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import javax.swing.*; @@ -34,7 +34,7 @@ public class Remove extends ContextMenuItem { public Remove() { - super(ContextMenuType.CONTAINER, ((tree, selPath, menu) -> + super(ContextMenuType.CONTAINER, ((tree, selPath, result, menu) -> { menu.add(new AbstractAction(TranslatedStrings.REMOVE.toString()) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/searchbox/Open.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/searchbox/Open.java new file mode 100644 index 00000000..7c79cfd3 --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/searchbox/Open.java @@ -0,0 +1,49 @@ +package the.bytecode.club.bytecodeviewer.gui.contextmenu.searchbox; + +import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType; +import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; + +import javax.swing.*; +import java.awt.event.ActionEvent; + +/*************************************************************************** + * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * + * Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +/** + * @author Konloch + * @since 7/29/2021 + */ +public class Open extends ContextMenuItem +{ + public Open() + { + super(ContextMenuType.SEARCH_BOX_RESULT, ((tree, selPath, result, menu) -> + { + menu.add(new AbstractAction(TranslatedStrings.OPEN_UNSTYLED.toString()) + { + @Override + public void actionPerformed(ActionEvent e) + { + BytecodeViewer.viewer.workPane.addClassResource(result.container, result.resourceWorkingName); + } + }); + })); + } +} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/searchbox/QuickEdit.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/searchbox/QuickEdit.java new file mode 100644 index 00000000..6cf4de66 --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/searchbox/QuickEdit.java @@ -0,0 +1,52 @@ +package the.bytecode.club.bytecodeviewer.gui.contextmenu.searchbox; + +import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType; +import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; + +import javax.swing.*; + +/*************************************************************************** + * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * + * Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +/** + * @author Konloch + * @since 7/27/2021 + */ +public class QuickEdit extends ContextMenuItem +{ + public QuickEdit() + { + super(ContextMenuType.SEARCH_BOX_RESULT, ((tree, selPath, result, menu) -> + { + JMenu quickOpen = new JMenu("Quick Edit"); + quickOpen.add(createMenu(TranslatedStrings.KRAKATAU.toString(), ()-> + BytecodeViewer.viewer.searchBoxPane.quickDecompile(Decompiler.KRAKATAU_DISASSEMBLER, result, true))); + menu.add(quickOpen); + })); + } + + private static JMenuItem createMenu(String name, Runnable onClick) + { + JMenuItem menu = new JMenuItem(name); + menu.addActionListener((e)->onClick.run()); + return menu; + } +} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/searchbox/QuickOpen.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/searchbox/QuickOpen.java new file mode 100644 index 00000000..c86b26ba --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/searchbox/QuickOpen.java @@ -0,0 +1,55 @@ +package the.bytecode.club.bytecodeviewer.gui.contextmenu.searchbox; + +import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType; +import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; + +import javax.swing.*; + +/*************************************************************************** + * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * + * Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +/** + * @author Konloch + * @since 7/26/2021 + */ +public class QuickOpen extends ContextMenuItem +{ + public QuickOpen() + { + super(ContextMenuType.SEARCH_BOX_RESULT, ((tree, selPath, result, menu) -> + { + JMenu quickOpen = new JMenu(TranslatedStrings.QUICK_OPEN.toString()); + quickOpen.add(createMenu(TranslatedStrings.PROCYON.toString(), ()->BytecodeViewer.viewer.searchBoxPane.quickDecompile(Decompiler.PROCYON_DECOMPILER, result, false))); + quickOpen.add(createMenu(TranslatedStrings.CFR.toString(), ()->BytecodeViewer.viewer.searchBoxPane.quickDecompile(Decompiler.CFR_DECOMPILER, result, false))); + quickOpen.add(createMenu(TranslatedStrings.FERNFLOWER.toString(), ()->BytecodeViewer.viewer.searchBoxPane.quickDecompile(Decompiler.FERNFLOWER_DECOMPILER, result, false))); + quickOpen.add(createMenu(TranslatedStrings.KRAKATAU.toString(), ()->BytecodeViewer.viewer.searchBoxPane.quickDecompile(Decompiler.KRAKATAU_DECOMPILER, result, false))); + quickOpen.add(createMenu(TranslatedStrings.BYTECODE.toString(), ()->BytecodeViewer.viewer.searchBoxPane.quickDecompile(Decompiler.BYTECODE_DISASSEMBLER, result, false))); + menu.add(quickOpen); + })); + } + + private static JMenuItem createMenu(String name, Runnable onClick) + { + JMenuItem menu = new JMenuItem(name); + menu.addActionListener((e)->onClick.run()); + return menu; + } +} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListPane.java index ab621da2..64690ae8 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ResourceListPane.java @@ -2,7 +2,6 @@ package the.bytecode.club.bytecodeviewer.gui.resourcelist; import java.awt.BorderLayout; import java.awt.Color; -import java.awt.event.ActionEvent; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.awt.event.KeyAdapter; @@ -13,19 +12,15 @@ import java.awt.event.MouseEvent; import java.io.File; import java.util.Enumeration; import java.util.Map.Entry; -import java.util.Objects; import javax.swing.*; -import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import me.konloch.kontainer.io.DiskWriter; import org.apache.commons.io.FilenameUtils; -import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.api.ASMUtil; import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; -import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenu; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenu; import the.bytecode.club.bytecodeviewer.resources.importing.Import; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.translation.TranslatedComponents; @@ -86,7 +81,7 @@ public class ResourceListPane extends TranslatedVisibleComponent implements File if (selPath == null) return; - ContextMenu.buildMenu(tree, selPath, rightClickMenu); + ContextMenu.buildMenu(tree, selPath, null, rightClickMenu); rightClickMenu.show(this.tree, x, y); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchBoxPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchBoxPane.java index 241eebf6..83bf4d44 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchBoxPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchBoxPane.java @@ -6,25 +6,18 @@ import java.awt.event.ItemListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Objects; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTree; -import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.*; import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreePath; -import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; +import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenu; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer; import the.bytecode.club.bytecodeviewer.searching.BackgroundSearchThread; import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult; -import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.translation.TranslatedComponents; import the.bytecode.club.bytecodeviewer.translation.components.*; -import the.bytecode.club.bytecodeviewer.resources.ResourceContainer; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * @@ -63,6 +56,7 @@ public class SearchBoxPane extends TranslatedVisibleComponent public SearchType searchType = null; public final JComboBox searchRadiusBox; + public final JPopupMenu rightClickMenu = new JPopupMenu(); public JButton search = new TranslatedJButton("Search", TranslatedComponents.SEARCH); public BackgroundSearchThread performSearchThread; @@ -139,6 +133,22 @@ public class SearchBoxPane extends TranslatedVisibleComponent //TODO right-click context menu if (e.isMetaDown()) { + TreePath selPath = SearchBoxPane.this.tree.getClosestPathForLocation(e.getX(), e.getY()); + + if (selPath == null) + return; + + //select the closest path + SearchBoxPane.this.tree.clearSelection(); + SearchBoxPane.this.tree.addSelectionPath(selPath); + + if(!(tree.getLastSelectedPathComponent() instanceof LDCSearchTreeNodeResult)) + return; + + //get selected path + LDCSearchTreeNodeResult result = (LDCSearchTreeNodeResult) tree.getLastSelectedPathComponent(); + + showContextMenu(result, e.getX(), e.getY()); } else if (e.getButton() == MouseEvent.BUTTON1) { @@ -155,7 +165,12 @@ public class SearchBoxPane extends TranslatedVisibleComponent }); this.setVisible(true); - + } + + public void resetWorkspace() + { + treeRoot.removeAllChildren(); + tree.updateUI(); } public void search() @@ -188,10 +203,42 @@ public class SearchBoxPane extends TranslatedVisibleComponent } } - public void resetWorkspace() + private void showContextMenu(LDCSearchTreeNodeResult selectedNode, int x, int y) { - treeRoot.removeAllChildren(); - tree.updateUI(); + if (selectedNode == null) + return; + + ContextMenu.buildMenu(null, null, selectedNode, rightClickMenu); + rightClickMenu.show(this.tree, x, y); + } + + /** + * Opens and decompiles the LDCSearchTreeNodeResult in a new tab + */ + public void quickDecompile(Decompiler decompiler, LDCSearchTreeNodeResult result, boolean quickEdit) + { + Decompiler tempDecompiler1 = BytecodeViewer.viewer.viewPane1.getSelectedDecompiler(); + boolean editable1 = BytecodeViewer.viewer.viewPane1.isPaneEditable(); + Decompiler tempDecompiler2 = BytecodeViewer.viewer.viewPane2.getSelectedDecompiler(); + boolean editable2 = BytecodeViewer.viewer.viewPane2.isPaneEditable(); + Decompiler tempDecompiler3 = BytecodeViewer.viewer.viewPane3.getSelectedDecompiler(); + boolean editable3 = BytecodeViewer.viewer.viewPane3.isPaneEditable(); + + BytecodeViewer.viewer.viewPane1.setSelectedDecompiler(decompiler); + BytecodeViewer.viewer.viewPane1.setPaneEditable(quickEdit); + BytecodeViewer.viewer.viewPane2.setSelectedDecompiler(Decompiler.NONE); + BytecodeViewer.viewer.viewPane2.setPaneEditable(false); + BytecodeViewer.viewer.viewPane3.setSelectedDecompiler(Decompiler.NONE); + BytecodeViewer.viewer.viewPane3.setPaneEditable(false); + + BytecodeViewer.viewer.workPane.addClassResource(result.container, result.resourceWorkingName); + + BytecodeViewer.viewer.viewPane1.setSelectedDecompiler(tempDecompiler1); + BytecodeViewer.viewer.viewPane1.setPaneEditable(editable1); + BytecodeViewer.viewer.viewPane2.setSelectedDecompiler(tempDecompiler2); + BytecodeViewer.viewer.viewPane2.setPaneEditable(editable2); + BytecodeViewer.viewer.viewPane3.setSelectedDecompiler(tempDecompiler3); + BytecodeViewer.viewer.viewPane3.setPaneEditable(editable3); } private static final long serialVersionUID = -1098524689236993932L;