feat(gui): add "Go To Declaration" in menu (PR #618)
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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=
|
||||
|
||||
Reference in New Issue
Block a user