-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gui): fix "Go to declaration" and "Find usage" menu actions
- Loading branch information
Showing
5 changed files
with
113 additions
and
124 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
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
53 changes: 6 additions & 47 deletions
53
jadx-gui/src/main/java/jadx/gui/ui/codearea/FindUsageAction.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 |
---|---|---|
@@ -1,66 +1,25 @@ | ||
package jadx.gui.ui.codearea; | ||
|
||
import java.awt.*; | ||
import java.awt.event.ActionEvent; | ||
|
||
import javax.swing.*; | ||
import javax.swing.event.PopupMenuEvent; | ||
import javax.swing.event.PopupMenuListener; | ||
|
||
import org.fife.ui.rsyntaxtextarea.Token; | ||
|
||
import jadx.api.JavaNode; | ||
import jadx.gui.treemodel.JNode; | ||
import jadx.gui.ui.ContentPanel; | ||
import jadx.gui.ui.MainWindow; | ||
import jadx.gui.ui.UsageDialog; | ||
import jadx.gui.utils.NLS; | ||
|
||
public final class FindUsageAction extends AbstractAction implements PopupMenuListener { | ||
public final class FindUsageAction extends JNodeMenuAction { | ||
private static final long serialVersionUID = 4692546569977976384L; | ||
|
||
private final transient ContentPanel contentPanel; | ||
private final transient CodeArea codeArea; | ||
|
||
private transient JavaNode node; | ||
|
||
public FindUsageAction(ContentPanel contentPanel, CodeArea codeArea) { | ||
super(NLS.str("popup.find_usage")); | ||
this.contentPanel = contentPanel; | ||
this.codeArea = codeArea; | ||
public FindUsageAction(CodeArea codeArea) { | ||
super(NLS.str("popup.find_usage"), codeArea); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
if (node == null) { | ||
if (jumpPos == null) { | ||
return; | ||
} | ||
MainWindow mainWindow = contentPanel.getTabbedPane().getMainWindow(); | ||
JNode jNode = mainWindow.getCacheObject().getNodeCache().makeFrom(node); | ||
UsageDialog usageDialog = new UsageDialog(mainWindow, jNode); | ||
MainWindow mainWindow = codeArea.getContentPanel().getTabbedPane().getMainWindow(); | ||
UsageDialog usageDialog = new UsageDialog(mainWindow, jumpPos.getNode()); | ||
usageDialog.setVisible(true); | ||
} | ||
|
||
@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(token.getOffset()); | ||
} | ||
} | ||
setEnabled(node != null); | ||
} | ||
|
||
@Override | ||
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public void popupMenuCanceled(PopupMenuEvent e) { | ||
// do nothing | ||
} | ||
} |
53 changes: 8 additions & 45 deletions
53
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 |
---|---|---|
@@ -1,67 +1,30 @@ | ||
package jadx.gui.ui.codearea; | ||
|
||
import java.awt.Point; | ||
import java.awt.event.ActionEvent; | ||
|
||
import javax.swing.AbstractAction; | ||
import javax.swing.*; | ||
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.ContentPanel; | ||
import jadx.gui.ui.MainWindow; | ||
import jadx.gui.utils.JumpPosition; | ||
import jadx.gui.utils.NLS; | ||
|
||
public final class GoToDeclarationAction extends AbstractAction implements PopupMenuListener { | ||
public final class GoToDeclarationAction extends JNodeMenuAction { | ||
private static final long serialVersionUID = -1186470538894941301L; | ||
private final transient ContentPanel contentPanel; | ||
private final transient CodeArea codeArea; | ||
private final transient JClass jCls; | ||
|
||
private transient JavaNode node; | ||
|
||
public GoToDeclarationAction(ContentPanel contentPanel, CodeArea codeArea, JClass jCls) { | ||
super(NLS.str("popup.go_to_declaration")); | ||
this.contentPanel = contentPanel; | ||
this.codeArea = codeArea; | ||
this.jCls = jCls; | ||
public GoToDeclarationAction(CodeArea codeArea) { | ||
super(NLS.str("popup.go_to_declaration"), codeArea); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
if (node == null) { | ||
return; | ||
if (jumpPos != null) { | ||
codeArea.getContentPanel().getTabbedPane().codeJump(jumpPos); | ||
} | ||
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(token.getOffset()); | ||
} | ||
} | ||
setEnabled(node != null); | ||
} | ||
super.popupMenuWillBecomeVisible(e); | ||
|
||
@Override | ||
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public void popupMenuCanceled(PopupMenuEvent e) { | ||
// do nothing | ||
putValue(Action.SMALL_ICON, jumpPos == null ? null : jumpPos.getNode().getIcon()); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
jadx-gui/src/main/java/jadx/gui/ui/codearea/JNodeMenuAction.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,55 @@ | ||
package jadx.gui.ui.codearea; | ||
|
||
import java.awt.*; | ||
import java.awt.event.ActionEvent; | ||
|
||
import javax.swing.*; | ||
import javax.swing.event.PopupMenuEvent; | ||
import javax.swing.event.PopupMenuListener; | ||
|
||
import org.fife.ui.rsyntaxtextarea.Token; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import jadx.gui.utils.JumpPosition; | ||
|
||
public abstract class JNodeMenuAction extends AbstractAction implements PopupMenuListener { | ||
|
||
protected final transient CodeArea codeArea; | ||
@Nullable | ||
protected transient JumpPosition jumpPos; | ||
|
||
public JNodeMenuAction(String name, CodeArea codeArea) { | ||
super(name); | ||
this.codeArea = codeArea; | ||
} | ||
|
||
@Override | ||
public abstract void actionPerformed(ActionEvent e); | ||
|
||
@Override | ||
public void popupMenuWillBecomeVisible(PopupMenuEvent e) { | ||
jumpPos = getJumpPos(); | ||
setEnabled(jumpPos != null); | ||
} | ||
|
||
@Nullable | ||
private JumpPosition getJumpPos() { | ||
Point pos = codeArea.getMousePosition(); | ||
if (pos != null) { | ||
Token token = codeArea.viewToToken(pos); | ||
int offset = codeArea.adjustOffsetForToken(token); | ||
return codeArea.getDefPosForNodeAtOffset(offset); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public void popupMenuCanceled(PopupMenuEvent e) { | ||
// do nothing | ||
} | ||
} |