Commit cfbbd99b authored by sergey-wowwow's avatar sergey-wowwow Committed by skylot

fix(gui): use command (CMD) button for MacOS (#165) (PR #616)

parent c74b7f20
...@@ -8,10 +8,12 @@ import java.awt.DisplayMode; ...@@ -8,10 +8,12 @@ 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;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
...@@ -560,7 +562,7 @@ public class MainWindow extends JFrame { ...@@ -560,7 +562,7 @@ public class MainWindow extends JFrame {
} }
}; };
openAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("file.open_action")); openAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("file.open_action"));
openAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK)); openAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_O, Utils.ctrlButton()));
newProjectAction = new AbstractAction(NLS.str("file.new_project")) { newProjectAction = new AbstractAction(NLS.str("file.new_project")) {
@Override @Override
...@@ -593,7 +595,7 @@ public class MainWindow extends JFrame { ...@@ -593,7 +595,7 @@ public class MainWindow extends JFrame {
} }
}; };
saveAllAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("file.save_all")); saveAllAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("file.save_all"));
saveAllAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK)); saveAllAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_S, Utils.ctrlButton()));
Action exportAction = new AbstractAction(NLS.str("file.export_gradle"), ICON_EXPORT) { Action exportAction = new AbstractAction(NLS.str("file.export_gradle"), ICON_EXPORT) {
@Override @Override
...@@ -602,7 +604,7 @@ public class MainWindow extends JFrame { ...@@ -602,7 +604,7 @@ public class MainWindow extends JFrame {
} }
}; };
exportAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("file.export_gradle")); exportAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("file.export_gradle"));
exportAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_E, KeyEvent.CTRL_DOWN_MASK)); exportAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_E, Utils.ctrlButton()));
JMenu recentProjects = new JMenu(NLS.str("menu.recent_projects")); JMenu recentProjects = new JMenu(NLS.str("menu.recent_projects"));
recentProjects.addMenuListener(new RecentProjectsMenuListener(recentProjects)); recentProjects.addMenuListener(new RecentProjectsMenuListener(recentProjects));
...@@ -615,7 +617,7 @@ public class MainWindow extends JFrame { ...@@ -615,7 +617,7 @@ public class MainWindow extends JFrame {
}; };
prefsAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.preferences")); prefsAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.preferences"));
prefsAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_P, prefsAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_P,
KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK)); Utils.ctrlButton() | KeyEvent.SHIFT_DOWN_MASK));
Action exitAction = new AbstractAction(NLS.str("file.exit"), ICON_CLOSE) { Action exitAction = new AbstractAction(NLS.str("file.exit"), ICON_CLOSE) {
@Override @Override
...@@ -642,7 +644,7 @@ public class MainWindow extends JFrame { ...@@ -642,7 +644,7 @@ public class MainWindow extends JFrame {
} }
}; };
syncAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.sync")); syncAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.sync"));
syncAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_T, KeyEvent.CTRL_DOWN_MASK)); syncAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_T, Utils.ctrlButton()));
Action textSearchAction = new AbstractAction(NLS.str("menu.text_search"), ICON_SEARCH) { Action textSearchAction = new AbstractAction(NLS.str("menu.text_search"), ICON_SEARCH) {
@Override @Override
...@@ -652,7 +654,7 @@ public class MainWindow extends JFrame { ...@@ -652,7 +654,7 @@ public class MainWindow extends JFrame {
}; };
textSearchAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.text_search")); textSearchAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.text_search"));
textSearchAction.putValue(Action.ACCELERATOR_KEY, textSearchAction.putValue(Action.ACCELERATOR_KEY,
getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK)); getKeyStroke(KeyEvent.VK_F, Utils.ctrlButton() | KeyEvent.SHIFT_DOWN_MASK));
Action clsSearchAction = new AbstractAction(NLS.str("menu.class_search"), ICON_FIND) { Action clsSearchAction = new AbstractAction(NLS.str("menu.class_search"), ICON_FIND) {
@Override @Override
...@@ -661,7 +663,7 @@ public class MainWindow extends JFrame { ...@@ -661,7 +663,7 @@ public class MainWindow extends JFrame {
} }
}; };
clsSearchAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.class_search")); clsSearchAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.class_search"));
clsSearchAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK)); clsSearchAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_N, Utils.ctrlButton()));
Action deobfAction = new AbstractAction(NLS.str("menu.deobfuscation"), ICON_DEOBF) { Action deobfAction = new AbstractAction(NLS.str("menu.deobfuscation"), ICON_DEOBF) {
@Override @Override
...@@ -671,7 +673,7 @@ public class MainWindow extends JFrame { ...@@ -671,7 +673,7 @@ public class MainWindow extends JFrame {
}; };
deobfAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("preferences.deobfuscation")); deobfAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("preferences.deobfuscation"));
deobfAction.putValue(Action.ACCELERATOR_KEY, deobfAction.putValue(Action.ACCELERATOR_KEY,
getKeyStroke(KeyEvent.VK_D, KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK)); getKeyStroke(KeyEvent.VK_D, Utils.ctrlButton() | KeyEvent.ALT_DOWN_MASK));
deobfToggleBtn = new JToggleButton(deobfAction); deobfToggleBtn = new JToggleButton(deobfAction);
deobfToggleBtn.setSelected(settings.isDeobfuscationOn()); deobfToggleBtn.setSelected(settings.isDeobfuscationOn());
...@@ -688,7 +690,7 @@ public class MainWindow extends JFrame { ...@@ -688,7 +690,7 @@ public class MainWindow extends JFrame {
}; };
logAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.log")); logAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.log"));
logAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_L, logAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_L,
KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK)); Utils.ctrlButton() | KeyEvent.SHIFT_DOWN_MASK));
Action aboutAction = new AbstractAction(NLS.str("menu.about"), ICON_JADX) { Action aboutAction = new AbstractAction(NLS.str("menu.about"), ICON_JADX) {
@Override @Override
...@@ -705,7 +707,7 @@ public class MainWindow extends JFrame { ...@@ -705,7 +707,7 @@ public class MainWindow extends JFrame {
}; };
backAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("nav.back")); backAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("nav.back"));
backAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_LEFT, backAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_LEFT,
KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK)); Utils.ctrlButton() | KeyEvent.ALT_DOWN_MASK));
Action forwardAction = new AbstractAction(NLS.str("nav.forward"), ICON_FORWARD) { Action forwardAction = new AbstractAction(NLS.str("nav.forward"), ICON_FORWARD) {
@Override @Override
...@@ -715,7 +717,7 @@ public class MainWindow extends JFrame { ...@@ -715,7 +717,7 @@ public class MainWindow extends JFrame {
}; };
forwardAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("nav.forward")); forwardAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("nav.forward"));
forwardAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_RIGHT, forwardAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_RIGHT,
KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK)); Utils.ctrlButton() | KeyEvent.ALT_DOWN_MASK));
JMenu file = new JMenu(NLS.str("menu.file")); JMenu file = new JMenu(NLS.str("menu.file"));
file.setMnemonic(KeyEvent.VK_F); file.setMnemonic(KeyEvent.VK_F);
......
...@@ -32,7 +32,7 @@ public final class CodePanel extends ContentPanel { ...@@ -32,7 +32,7 @@ public final class CodePanel extends ContentPanel {
add(searchBar, BorderLayout.NORTH); add(searchBar, BorderLayout.NORTH);
add(scrollPane); add(scrollPane);
KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_DOWN_MASK); KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_F, Utils.ctrlButton());
Utils.addKeyBinding(codeArea, key, "SearchAction", new SearchAction()); Utils.addKeyBinding(codeArea, key, "SearchAction", new SearchAction());
} }
......
...@@ -100,9 +100,9 @@ public class TextStandardActions { ...@@ -100,9 +100,9 @@ public class TextStandardActions {
} }
private void addKeyActions() { private void addKeyActions() {
KeyStroke undoKey = KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_DOWN_MASK); KeyStroke undoKey = KeyStroke.getKeyStroke(KeyEvent.VK_Z, Utils.ctrlButton());
textComponent.getInputMap().put(undoKey, undoAction); textComponent.getInputMap().put(undoKey, undoAction);
KeyStroke redoKey = KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK); KeyStroke redoKey = KeyStroke.getKeyStroke(KeyEvent.VK_R, Utils.ctrlButton());
textComponent.getInputMap().put(redoKey, redoAction); textComponent.getInputMap().put(redoKey, redoAction);
} }
......
...@@ -5,6 +5,7 @@ import java.awt.*; ...@@ -5,6 +5,7 @@ import java.awt.*;
import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
import java.awt.event.InputEvent;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -202,4 +203,13 @@ public class Utils { ...@@ -202,4 +203,13 @@ public class Utils {
icons.add(Utils.openImage("/logos/jadx-logo.png")); icons.add(Utils.openImage("/logos/jadx-logo.png"));
window.setIconImages(icons); window.setIconImages(icons);
} }
public static int ctrlButton() {
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
return Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
}
else {
return InputEvent.CTRL_DOWN_MASK;
}
}
} }
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