Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Plugin API: Allow plugins to add context menu entries to tree view #2412

Open
nitram84 opened this issue Feb 16, 2025 · 2 comments

Comments

@nitram84
Copy link
Contributor

Describe your idea

With current version of Jadx API plugins can only add entries to the codearea context menu. Currently it's not possible for plugins to add entries to the tree view on the left side.

My motivation for extending the plugin API

I would like to restore some features of https://github.com/LucasBaizer/apkSpy in my plugin https://github.com/nitram84/jadx-apkspy-plugin which were previously accessible using the tree view context menu:

  • Delete a class
  • Add class to a package
  • Edit method: When I try to replace/edit the method, replace the code in the code cache I'm loosing the usage info. So I can't access the method again using the codearea context menu. With a context menu entry in tree view I might implement a different access path as workaround (I would know the method - I just have to find it in the modified source code.).

For all these features I would consider a tree view context menu like in https://github.com/LucasBaizer/apkSpy to be more user friendly.

Is it possible to access a static block "static {}" via codearea context menu? With a tree view context menu this might be possible.

Perhaps extending the context menu of tree view is useful for other plugins too.

@skylot
Copy link
Owner

skylot commented Feb 17, 2025

Allow plugins to add context menu entries to tree view

Done. New method added to JadxGuiContext:

/**
 * Add popup menu entry for tree node
 *
 * @param name         entry title
 * @param addPredicate check if entry should be added for provided node, called on popup creation
 */
@ApiStatus.Experimental
void addTreePopupMenuEntry(String name, Predicate<ITreeNode> addPredicate, Consumer<ITreeNode> action);

Usage example:

guiContext.addTreePopupMenuEntry("Print class full name",
  node -> node.getCodeNodeRef() instanceof ClassNode,
  node -> System.out.println("Class: " + ((ClassNode) node.getCodeNodeRef()).getFullName())
);

Although, right now I am working on extended jadx-gui API, so this method may be moved to another module later.

Is it possible to access a static block "static {}" via codearea context menu?

Fixed. Now class init method node it is correctly detected (on static keyword), and popup menu entries can be used on it.

@nitram84
Copy link
Contributor Author

Thank you very much! If there are breaking API changes in the future, I' don't have problems with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants