Extended Context Menu API

This extends the right-click context menu API to support interactions on the search box panel
This commit is contained in:
Konloch 2021-07-29 20:28:10 -07:00
parent d95b9d0158
commit 9e08f06327
16 changed files with 288 additions and 69 deletions

View file

@ -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.gui.resourcelist.ResourceTree;
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult;
import javax.swing.*; import javax.swing.*;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
@ -29,5 +30,5 @@ import javax.swing.tree.TreePath;
*/ */
public interface BuildContextMenuItem public interface BuildContextMenuItem
{ {
void buildMenu(ResourceTree tree, TreePath selPath, JPopupMenu menu); void buildMenu(ResourceTree tree, TreePath selPath, LDCSearchTreeNodeResult result, JPopupMenu menu);
} }

View file

@ -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.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Constants;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceTree; 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.*;
import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import java.awt.event.ActionEvent;
import java.util.ArrayList; import java.util.ArrayList;
/*************************************************************************** /***************************************************************************
@ -39,6 +41,7 @@ public class ContextMenu
static static
{ {
//resource list
addContext(new Remove()); //TODO rename to delete and add support for resources & whole parent nodes (directories) addContext(new Remove()); //TODO rename to delete and add support for resources & whole parent nodes (directories)
addContext(new New()); addContext(new New());
addContext(new Open()); addContext(new Open());
@ -46,6 +49,11 @@ public class ContextMenu
addContext(new QuickEdit()); addContext(new QuickEdit());
addContext(new Expand()); addContext(new Expand());
addContext(new Collapse()); 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) public static void addContext(ContextMenuItem menuItem)
@ -53,36 +61,49 @@ public class ContextMenu
SINGLETON.contextMenuItems.add(menuItem); 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(); 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 //TODO this is hacky - there is probably a better way to do this
if(!searchBoxPane)
{
tree.setSelectionPath(selPath); tree.setSelectionPath(selPath);
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
boolean isResourceSelected = !node.children().hasMoreElements(); isResourceSelected = !node.children().hasMoreElements();
}
for(ContextMenuItem item : SINGLETON.contextMenuItems) for(ContextMenuItem item : SINGLETON.contextMenuItems)
{ {
switch(item.getMenuType()) switch(item.getMenuType())
{ {
case CONTAINER: case CONTAINER:
if(!isContainerSelected) if(!isContainerSelected || searchBoxPane)
continue; continue;
break; break;
case RESOURCE: case RESOURCE:
if(!isResourceSelected || isContainerSelected) if(!isResourceSelected || isContainerSelected || searchBoxPane)
continue; continue;
break; break;
case DIRECTORY: case DIRECTORY:
if(isResourceSelected) if(isResourceSelected || searchBoxPane)
continue;
break;
case RESOURCE_LIST:
if(searchBoxPane)
continue;
break;
case SEARCH_BOX_RESULT:
if(!searchBoxPane)
continue; continue;
break; break;
} }
item.getBuildContextMenuItem().buildMenu(tree, selPath, menu); item.getBuildContextMenuItem().buildMenu(tree, selPath, selectedNode, menu);
} }
} }
} }

View file

@ -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 * * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *

View file

@ -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 * * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
@ -24,8 +24,9 @@ package the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu;
*/ */
public enum ContextMenuType public enum ContextMenuType
{ {
ALL, RESOURCE_LIST,
RESOURCE, RESOURCE,
DIRECTORY, DIRECTORY,
CONTAINER, CONTAINER,
SEARCH_BOX_RESULT,
} }

View file

@ -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.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import javax.swing.*; import javax.swing.*;
@ -34,7 +34,7 @@ public class Collapse extends ContextMenuItem
{ {
public Collapse() public Collapse()
{ {
super(ContextMenuType.DIRECTORY, ((tree, selPath, menu) -> super(ContextMenuType.DIRECTORY, ((tree, selPath, result, menu) ->
{ {
menu.add(new AbstractAction(TranslatedStrings.COLLAPSE.toString()) menu.add(new AbstractAction(TranslatedStrings.COLLAPSE.toString())
{ {

View file

@ -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.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import javax.swing.*; import javax.swing.*;
@ -34,7 +34,7 @@ public class Expand extends ContextMenuItem
{ {
public Expand() public Expand()
{ {
super(ContextMenuType.DIRECTORY, ((tree, selPath, menu) -> super(ContextMenuType.DIRECTORY, ((tree, selPath, result, menu) ->
{ {
menu.add(new AbstractAction(TranslatedStrings.EXPAND.toString()) menu.add(new AbstractAction(TranslatedStrings.EXPAND.toString())
{ {

View file

@ -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.apache.commons.io.FilenameUtils;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Constants; import the.bytecode.club.bytecodeviewer.Constants;
import the.bytecode.club.bytecodeviewer.api.ASMUtil; import the.bytecode.club.bytecodeviewer.api.ASMUtil;
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import javax.swing.*; import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode; import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import java.util.Enumeration; import java.util.Enumeration;
@ -43,7 +41,7 @@ public class New extends ContextMenuItem
{ {
public New() public New()
{ {
super(ContextMenuType.ALL, ((tree, selPath, menu) -> super(ContextMenuType.RESOURCE_LIST, ((tree, selPath, result, menu) ->
{ {
JMenu quickOpen = new JMenu(TranslatedStrings.NEW.toString()); JMenu quickOpen = new JMenu(TranslatedStrings.NEW.toString());
quickOpen.add(createMenu("Class", FileType.CLASS, selPath)); quickOpen.add(createMenu("Class", FileType.CLASS, selPath));

View file

@ -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.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import javax.swing.*; import javax.swing.*;
@ -34,7 +34,7 @@ public class Open extends ContextMenuItem
{ {
public Open() public Open()
{ {
super(ContextMenuType.RESOURCE, ((tree, selPath, menu) -> super(ContextMenuType.RESOURCE, ((tree, selPath, result, menu) ->
{ {
menu.add(new AbstractAction(TranslatedStrings.OPEN_UNSTYLED.toString()) menu.add(new AbstractAction(TranslatedStrings.OPEN_UNSTYLED.toString())
{ {

View file

@ -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.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import javax.swing.*; import javax.swing.*;
@ -34,7 +34,7 @@ public class QuickEdit extends ContextMenuItem
{ {
public QuickEdit() public QuickEdit()
{ {
super(ContextMenuType.RESOURCE, ((tree, selPath, menu) -> super(ContextMenuType.RESOURCE, ((tree, selPath, result, menu) ->
{ {
JMenu quickOpen = new JMenu("Quick Edit"); JMenu quickOpen = new JMenu("Quick Edit");
quickOpen.add(createMenu(TranslatedStrings.KRAKATAU.toString(), ()-> quickOpen.add(createMenu(TranslatedStrings.KRAKATAU.toString(), ()->

View file

@ -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.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import javax.swing.*; import javax.swing.*;
@ -34,7 +34,7 @@ public class QuickOpen extends ContextMenuItem
{ {
public QuickOpen() public QuickOpen()
{ {
super(ContextMenuType.RESOURCE, ((tree, selPath, menu) -> super(ContextMenuType.RESOURCE, ((tree, selPath, result, menu) ->
{ {
JMenu quickOpen = new JMenu(TranslatedStrings.QUICK_OPEN.toString()); JMenu quickOpen = new JMenu(TranslatedStrings.QUICK_OPEN.toString());
quickOpen.add(createMenu(TranslatedStrings.PROCYON.toString(), ()->BytecodeViewer.viewer.resourcePane.quickDecompile(Decompiler.PROCYON_DECOMPILER, selPath, false))); quickOpen.add(createMenu(TranslatedStrings.PROCYON.toString(), ()->BytecodeViewer.viewer.resourcePane.quickDecompile(Decompiler.PROCYON_DECOMPILER, selPath, false)));

View file

@ -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.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuItem; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem;
import the.bytecode.club.bytecodeviewer.gui.resourcelist.contextmenu.ContextMenuType; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import javax.swing.*; import javax.swing.*;
@ -34,7 +34,7 @@ public class Remove extends ContextMenuItem
{ {
public Remove() public Remove()
{ {
super(ContextMenuType.CONTAINER, ((tree, selPath, menu) -> super(ContextMenuType.CONTAINER, ((tree, selPath, result, menu) ->
{ {
menu.add(new AbstractAction(TranslatedStrings.REMOVE.toString()) menu.add(new AbstractAction(TranslatedStrings.REMOVE.toString())
{ {

View file

@ -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 <http://www.gnu.org/licenses/>. *
***************************************************************************/
/**
* @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);
}
});
}));
}
}

View file

@ -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 <http://www.gnu.org/licenses/>. *
***************************************************************************/
/**
* @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;
}
}

View file

@ -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 <http://www.gnu.org/licenses/>. *
***************************************************************************/
/**
* @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;
}
}

View file

@ -2,7 +2,6 @@ package the.bytecode.club.bytecodeviewer.gui.resourcelist;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.awt.event.FocusListener; import java.awt.event.FocusListener;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
@ -13,19 +12,15 @@ import java.awt.event.MouseEvent;
import java.io.File; import java.io.File;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Objects;
import javax.swing.*; import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode; import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import me.konloch.kontainer.io.DiskWriter; import me.konloch.kontainer.io.DiskWriter;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer; 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.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.resources.importing.Import;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import the.bytecode.club.bytecodeviewer.translation.TranslatedComponents; import the.bytecode.club.bytecodeviewer.translation.TranslatedComponents;
@ -86,7 +81,7 @@ public class ResourceListPane extends TranslatedVisibleComponent implements File
if (selPath == null) if (selPath == null)
return; return;
ContextMenu.buildMenu(tree, selPath, rightClickMenu); ContextMenu.buildMenu(tree, selPath, null, rightClickMenu);
rightClickMenu.show(this.tree, x, y); rightClickMenu.show(this.tree, x, y);
} }

View file

@ -6,25 +6,18 @@ import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.Objects; import java.util.Objects;
import javax.swing.DefaultComboBoxModel; import javax.swing.*;
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.tree.DefaultTreeModel; 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.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.gui.resourceviewer.viewer.ResourceViewer;
import the.bytecode.club.bytecodeviewer.searching.BackgroundSearchThread; import the.bytecode.club.bytecodeviewer.searching.BackgroundSearchThread;
import the.bytecode.club.bytecodeviewer.searching.LDCSearchTreeNodeResult; 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.TranslatedComponents;
import the.bytecode.club.bytecodeviewer.translation.components.*; import the.bytecode.club.bytecodeviewer.translation.components.*;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
/*************************************************************************** /***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
@ -63,6 +56,7 @@ public class SearchBoxPane extends TranslatedVisibleComponent
public SearchType searchType = null; public SearchType searchType = null;
public final JComboBox searchRadiusBox; public final JComboBox searchRadiusBox;
public final JPopupMenu rightClickMenu = new JPopupMenu();
public JButton search = new TranslatedJButton("Search", TranslatedComponents.SEARCH); public JButton search = new TranslatedJButton("Search", TranslatedComponents.SEARCH);
public BackgroundSearchThread performSearchThread; public BackgroundSearchThread performSearchThread;
@ -139,6 +133,22 @@ public class SearchBoxPane extends TranslatedVisibleComponent
//TODO right-click context menu //TODO right-click context menu
if (e.isMetaDown()) 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) else if (e.getButton() == MouseEvent.BUTTON1)
{ {
@ -155,7 +165,12 @@ public class SearchBoxPane extends TranslatedVisibleComponent
}); });
this.setVisible(true); this.setVisible(true);
}
public void resetWorkspace()
{
treeRoot.removeAllChildren();
tree.updateUI();
} }
public void search() 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(); if (selectedNode == null)
tree.updateUI(); 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; private static final long serialVersionUID = -1098524689236993932L;