feat(api): access node under caret/mouse and jump (PR #1903)
* Access node under caret/mouse and jump * Apply lint
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import jadx.api.metadata.ICodeNodeRef
|
||||
import jadx.core.dex.nodes.MethodNode
|
||||
|
||||
val jadx = getJadxInstance()
|
||||
var savedBookmark: ICodeNodeRef? = null
|
||||
|
||||
jadx.gui.ifAvailable {
|
||||
addPopupMenuAction(
|
||||
"Set bookmark",
|
||||
enabled = { true },
|
||||
keyBinding = "B",
|
||||
action = ::setBookmark,
|
||||
)
|
||||
|
||||
addMenuAction(
|
||||
"Jump to bookmark",
|
||||
action = ::jumpToBookmark,
|
||||
)
|
||||
}
|
||||
|
||||
fun setBookmark(node: ICodeNodeRef) {
|
||||
val enclosing = jadx.gui.enclosingNodeUnderCaret ?: run {
|
||||
jadx.log.info { "No enclosing node" }
|
||||
return
|
||||
}
|
||||
|
||||
// You can bookmark a field, method or a class
|
||||
val target = if (enclosing is MethodNode) enclosing else node
|
||||
|
||||
jadx.log.info { "Setting bookmark to: $target" }
|
||||
savedBookmark = target
|
||||
}
|
||||
|
||||
fun jumpToBookmark() {
|
||||
if (savedBookmark == null) {
|
||||
jadx.log.info { "No bookmark" }
|
||||
} else {
|
||||
val res = jadx.gui.open(savedBookmark!!)
|
||||
if (!res) {
|
||||
jadx.log.info { "Failed to jump to bookmark" }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import jadx.api.metadata.ICodeNodeRef
|
||||
|
||||
val jadx = getJadxInstance()
|
||||
|
||||
jadx.gui.ifAvailable {
|
||||
addPopupMenuAction(
|
||||
"Print enclosing symbols under caret or mouse",
|
||||
enabled = { true },
|
||||
keyBinding = "G",
|
||||
action = ::runAction,
|
||||
)
|
||||
}
|
||||
|
||||
fun runAction(node: ICodeNodeRef) {
|
||||
jadx.log.info { "Node under caret: ${jadx.gui.nodeUnderCaret}" }
|
||||
jadx.log.info { "Enclosing node under caret: ${jadx.gui.enclosingNodeUnderCaret}" }
|
||||
jadx.log.info { "Node under mouse: ${jadx.gui.nodeUnderMouse}" }
|
||||
jadx.log.info { "Enclosing Node under mouse: ${jadx.gui.enclosingNodeUnderMouse}" }
|
||||
}
|
||||
Reference in New Issue
Block a user