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

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

上级 7f8d03d1
package jadx.gui; package jadx.gui;
import javax.swing.*; import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -10,6 +11,7 @@ import jadx.gui.settings.JadxSettings; ...@@ -10,6 +11,7 @@ import jadx.gui.settings.JadxSettings;
import jadx.gui.settings.JadxSettingsAdapter; import jadx.gui.settings.JadxSettingsAdapter;
import jadx.gui.ui.MainWindow; import jadx.gui.ui.MainWindow;
import jadx.gui.utils.NLS; import jadx.gui.utils.NLS;
import jadx.gui.utils.SystemInfo;
import jadx.gui.utils.logs.LogCollector; import jadx.gui.utils.logs.LogCollector;
public class JadxGUI { public class JadxGUI {
...@@ -28,6 +30,8 @@ public class JadxGUI { ...@@ -28,6 +30,8 @@ public class JadxGUI {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} }
NLS.setLocale(settings.getLangLocale()); NLS.setLocale(settings.getLangLocale());
printSystemInfo();
SwingUtilities.invokeLater(new MainWindow(settings)::init); SwingUtilities.invokeLater(new MainWindow(settings)::init);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error: {}", e.getMessage(), e); LOG.error("Error: {}", e.getMessage(), e);
...@@ -47,4 +51,13 @@ public class JadxGUI { ...@@ -47,4 +51,13 @@ public class JadxGUI {
} }
return false; 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; package jadx.gui.ui;
import java.awt.AWTEvent;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
...@@ -7,6 +8,7 @@ import java.awt.DisplayMode; ...@@ -7,6 +8,7 @@ import java.awt.DisplayMode;
import java.awt.Font; import java.awt.Font;
import java.awt.GraphicsDevice; import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.awt.dnd.DnDConstants; import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget; import java.awt.dnd.DropTarget;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
...@@ -97,6 +99,7 @@ import jadx.gui.utils.FontUtils; ...@@ -97,6 +99,7 @@ import jadx.gui.utils.FontUtils;
import jadx.gui.utils.JumpPosition; import jadx.gui.utils.JumpPosition;
import jadx.gui.utils.Link; import jadx.gui.utils.Link;
import jadx.gui.utils.NLS; import jadx.gui.utils.NLS;
import jadx.gui.utils.SystemInfo;
import jadx.gui.utils.UiUtils; import jadx.gui.utils.UiUtils;
import static javax.swing.KeyStroke.getKeyStroke; import static javax.swing.KeyStroke.getKeyStroke;
...@@ -164,6 +167,7 @@ public class MainWindow extends JFrame { ...@@ -164,6 +167,7 @@ public class MainWindow extends JFrame {
FontUtils.registerBundledFonts(); FontUtils.registerBundledFonts();
initUI(); initUI();
initMenuAndToolbar(); initMenuAndToolbar();
registerMouseNavigationButtons();
UiUtils.setWindowIcons(this); UiUtils.setWindowIcons(this);
loadSettings(); loadSettings();
checkForUpdate(); checkForUpdate();
...@@ -958,6 +962,42 @@ public class MainWindow extends JFrame { ...@@ -958,6 +962,42 @@ public class MainWindow extends JFrame {
setTitle(DEFAULT_TITLE); 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) { private static String[] getPathExpansion(TreePath path) {
List<String> pathList = new ArrayList<>(); List<String> pathList = new ArrayList<>();
while (path != null) { while (path != null) {
......
package jadx.gui.ui; package jadx.gui.ui;
import java.awt.*; import java.awt.Component;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.swing.*; import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException; import javax.swing.text.BadLocationException;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
...@@ -40,6 +41,9 @@ public class TabbedPane extends JTabbedPane { ...@@ -40,6 +41,9 @@ public class TabbedPane extends JTabbedPane {
setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
addMouseWheelListener(e -> { addMouseWheelListener(e -> {
if (openTabs.isEmpty()) {
return;
}
int direction = e.getWheelRotation(); int direction = e.getWheelRotation();
int index = getSelectedIndex(); int index = getSelectedIndex();
int maxIndex = getTabCount() - 1; int maxIndex = getTabCount() - 1;
......
...@@ -2,6 +2,9 @@ package jadx.gui.utils; ...@@ -2,6 +2,9 @@ package jadx.gui.utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.jetbrains.annotations.Nullable;
public class JumpManager { public class JumpManager {
...@@ -9,7 +12,7 @@ public class JumpManager { ...@@ -9,7 +12,7 @@ public class JumpManager {
private int currentPos = 0; private int currentPos = 0;
public void addPosition(JumpPosition pos) { public void addPosition(JumpPosition pos) {
if (pos.equals(getCurrent())) { if (ignoreJump(pos)) {
return; return;
} }
currentPos++; currentPos++;
...@@ -25,6 +28,30 @@ public class JumpManager { ...@@ -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() { private JumpPosition getCurrent() {
if (currentPos >= 0 && currentPos < list.size()) { if (currentPos >= 0 && currentPos < list.size()) {
return list.get(currentPos); return list.get(currentPos);
...@@ -32,6 +59,7 @@ public class JumpManager { ...@@ -32,6 +59,7 @@ public class JumpManager {
return null; return null;
} }
@Nullable
public JumpPosition getPrev() { public JumpPosition getPrev() {
if (currentPos == 0) { if (currentPos == 0) {
return null; return null;
...@@ -40,6 +68,7 @@ public class JumpManager { ...@@ -40,6 +68,7 @@ public class JumpManager {
return list.get(currentPos); return list.get(currentPos);
} }
@Nullable
public JumpPosition getNext() { public JumpPosition getNext() {
int size = list.size(); int size = list.size();
if (size == 0) { 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.
先完成此消息的编辑!
想要评论请 注册