提交 9ab003df 编写于 作者: S Skylot

feat(gui): map back and forward mouse keys for navigation (#807)

上级 7f8d03d1
package jadx.gui;
import javax.swing.*;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -10,6 +11,7 @@ import jadx.gui.settings.JadxSettings;
import jadx.gui.settings.JadxSettingsAdapter;
import jadx.gui.ui.MainWindow;
import jadx.gui.utils.NLS;
import jadx.gui.utils.SystemInfo;
import jadx.gui.utils.logs.LogCollector;
public class JadxGUI {
......@@ -28,6 +30,8 @@ public class JadxGUI {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
NLS.setLocale(settings.getLangLocale());
printSystemInfo();
SwingUtilities.invokeLater(new MainWindow(settings)::init);
} catch (Exception e) {
LOG.error("Error: {}", e.getMessage(), e);
......@@ -47,4 +51,13 @@ public class JadxGUI {
}
return false;
}
private static void printSystemInfo() {
if (LOG.isDebugEnabled()) {
LOG.debug("Starting jadx-gui. Version: '{}'. JVM: {} {}. OS: {} {}",
SystemInfo.JADX_VERSION,
SystemInfo.JAVA_VM, SystemInfo.JAVA_VER,
SystemInfo.OS_NAME, SystemInfo.OS_VERSION);
}
}
}
package jadx.gui.ui;
import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
......@@ -7,6 +8,7 @@ import java.awt.DisplayMode;
import java.awt.Font;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.event.ActionEvent;
......@@ -97,6 +99,7 @@ import jadx.gui.utils.FontUtils;
import jadx.gui.utils.JumpPosition;
import jadx.gui.utils.Link;
import jadx.gui.utils.NLS;
import jadx.gui.utils.SystemInfo;
import jadx.gui.utils.UiUtils;
import static javax.swing.KeyStroke.getKeyStroke;
......@@ -164,6 +167,7 @@ public class MainWindow extends JFrame {
FontUtils.registerBundledFonts();
initUI();
initMenuAndToolbar();
registerMouseNavigationButtons();
UiUtils.setWindowIcons(this);
loadSettings();
checkForUpdate();
......@@ -958,6 +962,42 @@ public class MainWindow extends JFrame {
setTitle(DEFAULT_TITLE);
}
private void registerMouseNavigationButtons() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
toolkit.addAWTEventListener(event -> {
if (event instanceof MouseEvent) {
MouseEvent mouseEvent = (MouseEvent) event;
if (mouseEvent.getID() == MouseEvent.MOUSE_PRESSED) {
int rawButton = mouseEvent.getButton();
if (rawButton <= 3) {
return;
}
int button = remapMouseButton(rawButton);
switch (button) {
case 4:
tabbedPane.navBack();
break;
case 5:
tabbedPane.navForward();
break;
}
}
}
}, AWTEvent.MOUSE_EVENT_MASK);
}
private static int remapMouseButton(int rawButton) {
if (SystemInfo.IS_LINUX) {
if (rawButton == 6) {
return 4;
}
if (rawButton == 7) {
return 5;
}
}
return rawButton;
}
private static String[] getPathExpansion(TreePath path) {
List<String> pathList = new ArrayList<>();
while (path != null) {
......
package jadx.gui.ui;
import java.awt.*;
import java.awt.Component;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.swing.*;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import org.jetbrains.annotations.Nullable;
......@@ -40,6 +41,9 @@ public class TabbedPane extends JTabbedPane {
setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
addMouseWheelListener(e -> {
if (openTabs.isEmpty()) {
return;
}
int direction = e.getWheelRotation();
int index = getSelectedIndex();
int maxIndex = getTabCount() - 1;
......
......@@ -2,6 +2,9 @@ package jadx.gui.utils;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.jetbrains.annotations.Nullable;
public class JumpManager {
......@@ -9,7 +12,7 @@ public class JumpManager {
private int currentPos = 0;
public void addPosition(JumpPosition pos) {
if (pos.equals(getCurrent())) {
if (ignoreJump(pos)) {
return;
}
currentPos++;
......@@ -25,6 +28,30 @@ public class JumpManager {
}
}
private boolean ignoreJump(JumpPosition pos) {
JumpPosition current = getCurrent();
if (current == null) {
return false;
}
if (pos.equals(current)) {
return true;
}
if (Objects.equals(current.getNode(), pos.getNode())) {
// undefined jump line in same node // TODO: find the cause
if (pos.getLine() == 0) {
return true;
}
if (current.getLine() == 0) {
// replace current
getPrev();
return false;
}
return false;
}
return false;
}
@Nullable
private JumpPosition getCurrent() {
if (currentPos >= 0 && currentPos < list.size()) {
return list.get(currentPos);
......@@ -32,6 +59,7 @@ public class JumpManager {
return null;
}
@Nullable
public JumpPosition getPrev() {
if (currentPos == 0) {
return null;
......@@ -40,6 +68,7 @@ public class JumpManager {
return list.get(currentPos);
}
@Nullable
public JumpPosition getNext() {
int size = list.size();
if (size == 0) {
......
package jadx.gui.utils;
import java.util.Locale;
import jadx.api.JadxDecompiler;
public class SystemInfo {
public static final String JADX_VERSION = JadxDecompiler.getVersion();
public static final String JAVA_VM = System.getProperty("java.vm.name");
public static final String JAVA_VER = System.getProperty("java.version");
public static final String OS_NAME = System.getProperty("os.name");
public static final String OS_VERSION = System.getProperty("os.version");
private static final String LOWER_OS_NAME = OS_NAME.toLowerCase(Locale.ENGLISH);
public static final boolean IS_WINDOWS = LOWER_OS_NAME.startsWith("windows");
public static final boolean IS_MAC = LOWER_OS_NAME.startsWith("mac");
public static final boolean IS_LINUX = LOWER_OS_NAME.startsWith("linux");
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册