-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gui): add "Go To Declaration" in menu (PR #618)
- Loading branch information
Showing
5 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
jadx-gui/src/main/java/jadx/gui/ui/codearea/GoToDeclarationAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package jadx.gui.ui.codearea; | ||
|
||
import java.awt.Point; | ||
import java.awt.event.ActionEvent; | ||
|
||
import javax.swing.AbstractAction; | ||
import javax.swing.event.PopupMenuEvent; | ||
import javax.swing.event.PopupMenuListener; | ||
|
||
import org.fife.ui.rsyntaxtextarea.Token; | ||
|
||
import jadx.api.JavaNode; | ||
import jadx.gui.treemodel.JClass; | ||
import jadx.gui.treemodel.JNode; | ||
import jadx.gui.ui.MainWindow; | ||
import jadx.gui.utils.JumpPosition; | ||
import jadx.gui.utils.NLS; | ||
|
||
public final class GoToDeclarationAction extends AbstractAction implements PopupMenuListener { | ||
private static final long serialVersionUID = -1186470538894941301L; | ||
private final transient CodePanel contentPanel; | ||
private final transient CodeArea codeArea; | ||
private final transient JClass jCls; | ||
|
||
private transient JavaNode node; | ||
|
||
public GoToDeclarationAction(CodePanel contentPanel, CodeArea codeArea, JClass jCls) { | ||
super(NLS.str("popup.go_to_declaration")); | ||
this.contentPanel = contentPanel; | ||
this.codeArea = codeArea; | ||
this.jCls = jCls; | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
if (node == null) { | ||
return; | ||
} | ||
MainWindow mainWindow = contentPanel.getTabbedPane().getMainWindow(); | ||
JNode jNode = mainWindow.getCacheObject().getNodeCache().makeFrom(node); | ||
mainWindow.getTabbedPane().codeJump(new JumpPosition(jNode, jNode.getLine())); | ||
} | ||
|
||
@Override | ||
public void popupMenuWillBecomeVisible(PopupMenuEvent e) { | ||
node = null; | ||
Point pos = codeArea.getMousePosition(); | ||
if (pos != null) { | ||
Token token = codeArea.viewToToken(pos); | ||
if (token != null) { | ||
node = codeArea.getJavaNodeAtOffset(jCls, token.getOffset()); | ||
} | ||
} | ||
setEnabled(node != null); | ||
} | ||
|
||
@Override | ||
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public void popupMenuCanceled(PopupMenuEvent e) { | ||
// do nothing | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters