Skip to content

Commit

Permalink
feat(gui): add "Go To Declaration" in menu (PR #618)
Browse files Browse the repository at this point in the history
  • Loading branch information
asashour authored and skylot committed Apr 22, 2019
1 parent 6167527 commit aa41a4d
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
3 changes: 3 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/ui/codearea/CodeArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,14 @@ private void highlightAllMatches(@Nullable String str) {

private void addMenuItems(JClass jCls) {
FindUsageAction findUsage = new FindUsageAction(contentPanel, this, jCls);
GoToDeclarationAction goToDeclaration = new GoToDeclarationAction(contentPanel, this, jCls);

JPopupMenu popup = getPopupMenu();
popup.addSeparator();
popup.add(findUsage);
popup.add(goToDeclaration);
popup.addPopupMenuListener(findUsage);
popup.addPopupMenuListener(goToDeclaration);
}

public void loadSettings() {
Expand Down
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
}
}
1 change: 1 addition & 0 deletions jadx-gui/src/main/resources/i18n/Messages_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ popup.paste=Paste
popup.delete=Delete
popup.select_all=Select All
popup.find_usage=Find Usage
popup.go_to_declaration=Go to declaration
popup.exclude=Exclude
confirm.save_as_title=Confirm Save as
Expand Down
1 change: 1 addition & 0 deletions jadx-gui/src/main/resources/i18n/Messages_es_ES.properties
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ popup.paste=Pegar
popup.delete=Borrar
popup.select_all=Seleccionar todo
#popup.find_usage=
#popup.go_to_declaration=
#popup.exclude=

#confirm.save_as_title=
Expand Down
1 change: 1 addition & 0 deletions jadx-gui/src/main/resources/i18n/Messages_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ popup.paste=粘贴
popup.delete=删除
popup.select_all=全选
popup.find_usage=查找用例
#popup.go_to_declaration=
#popup.exclude=

#confirm.save_as_title=
Expand Down

0 comments on commit aa41a4d

Please sign in to comment.