Commit aa41a4d9 authored by Ahmed Ashour's avatar Ahmed Ashour Committed by skylot

feat(gui): add "Go To Declaration" in menu (PR #618)

parent 61675275
......@@ -96,11 +96,14 @@ public final class CodeArea extends RSyntaxTextArea {
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() {
......
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
}
}
......@@ -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
......
......@@ -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=
......
......@@ -136,6 +136,7 @@ popup.paste=粘贴
popup.delete=删除
popup.select_all=全选
popup.find_usage=查找用例
#popup.go_to_declaration=
#popup.exclude=
#confirm.save_as_title=
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment