From 28c505fb05ad51ceff6b8bb62fa12f3ba0550b35 Mon Sep 17 00:00:00 2001 From: Andreas Justin Date: Sat, 20 Feb 2021 14:14:23 +0100 Subject: [PATCH] #150 MAC OS --- src/at/mep/editor/EMEPKeyStrokes.java | 22 ++++++++++--------- .../mep/gui/components/UndecoratedFrame.java | 2 +- src/at/mep/util/KeyStrokeUtil.java | 21 ++++++++++++------ 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/at/mep/editor/EMEPKeyStrokes.java b/src/at/mep/editor/EMEPKeyStrokes.java index 599b2c9..61f9210 100644 --- a/src/at/mep/editor/EMEPKeyStrokes.java +++ b/src/at/mep/editor/EMEPKeyStrokes.java @@ -2,6 +2,7 @@ import at.mep.EMatlabKeyStrokesCommands; import at.mep.util.KeyStrokeUtil; +import java.awt.Toolkit; import javax.swing.*; import java.awt.event.KeyEvent; @@ -9,27 +10,28 @@ /** Created by Andreas Justin on 2016-10-12. */ @Deprecated public enum EMEPKeyStrokes { - KS_MEP_DEBUG(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_E, true, true, false, false)), + KS_MEP_DEBUG(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_E, true, false, true, false, false)), - KS_MEP_EXECUTE_CURRENT_LINE(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_F9, false, true, false, false)), + KS_MEP_EXECUTE_CURRENT_LINE(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_F9, false, false, true, false, false)), - KS_MEP_SHOW_FILE_STRUCTURE(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_F12, true, false, false, false)), + KS_MEP_SHOW_FILE_STRUCTURE(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_F12, true, false, false, false, false)), - KS_MEP_SHOW_COPY_CLIP_BOARD(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_V, true, true, false, false)), - KS_MEP_COPY_CLIP_BOARD(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_C, true, false, false, false)), + KS_MEP_SHOW_COPY_CLIP_BOARD(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_V, true, false, true, false, false)), + KS_MEP_COPY_CLIP_BOARD(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_C, true, false, false, false, false)), - KS_MEP_DELETE_CURRENT_LINES(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_Y, true, true, false, false)), - KS_MEP_DUPLICATE_CURRENT_LINE_OR_SELECTION(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_D, true, true, false, false)), + KS_MEP_DELETE_CURRENT_LINES(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_Y, true, false, true, false, false)), + KS_MEP_DUPLICATE_CURRENT_LINE_OR_SELECTION(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_D, true, false, true, false, false)), KS_MEP_BOOKMARK(KeyStrokeUtil.getMatlabKeyStroke(EMatlabKeyStrokesCommands.CTRL_PRESSED_F2)), KS_MEP_SHOW_BOOKMARKS(KeyStrokeUtil.getKeyStroke( KS_MEP_BOOKMARK.getKeyStroke().getKeyCode(), - (KS_MEP_BOOKMARK.getKeyStroke().getModifiers() & KeyEvent.CTRL_DOWN_MASK) == KeyEvent.CTRL_DOWN_MASK, + false, + (KS_MEP_BOOKMARK.getKeyStroke().getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) == Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), (KS_MEP_BOOKMARK.getKeyStroke().getModifiers() & KeyEvent.SHIFT_DOWN_MASK) != KeyEvent.SHIFT_DOWN_MASK, false, false)), - KS_MEP_MEPR_INSERT(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_INSERT, false, false, true, false)), - KS_MEP_MEPR_QUICK_SEARCH(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_SPACE, true, false, true, false)), + KS_MEP_MEPR_INSERT(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_INSERT, false, false, false, true, false)), + KS_MEP_MEPR_QUICK_SEARCH(KeyStrokeUtil.getKeyStroke(KeyEvent.VK_SPACE, true, false, false, true, false)), ; private final KeyStroke keyStroke; diff --git a/src/at/mep/gui/components/UndecoratedFrame.java b/src/at/mep/gui/components/UndecoratedFrame.java index 7077f28..b52713b 100644 --- a/src/at/mep/gui/components/UndecoratedFrame.java +++ b/src/at/mep/gui/components/UndecoratedFrame.java @@ -87,7 +87,7 @@ public UndecoratedFrame() { setUndecorated(true); // escape hiding window - KeyStroke ks = KeyStrokeUtil.getKeyStroke(KeyEvent.VK_ESCAPE, false, false, false, true); + KeyStroke ks = KeyStrokeUtil.getKeyStroke(KeyEvent.VK_ESCAPE, false, false, false, false, true); getRootPane().getInputMap(IFW).put(ks, CLOSE_ACTION); getRootPane().getActionMap().put(CLOSE_ACTION, closeAction); diff --git a/src/at/mep/util/KeyStrokeUtil.java b/src/at/mep/util/KeyStrokeUtil.java index 485fb3e..705385d 100644 --- a/src/at/mep/util/KeyStrokeUtil.java +++ b/src/at/mep/util/KeyStrokeUtil.java @@ -2,6 +2,7 @@ import at.mep.EMatlabKeyStrokesCommands; import at.mep.editor.EditorWrapper; +import java.awt.Toolkit; import javax.swing.*; import java.awt.event.InputEvent; @@ -16,7 +17,8 @@ public class KeyStrokeUtil { private static final String ALT = "alt"; - private static final String CONTROL = "control"; + private static final String CONTROL = "control"; // WINDOWS + private static final String META = "meta"; // MAC OS; #150 private static final String SHIFT = "shift"; private static final String RELEASED = "released"; private static final String PRESSED = "pressed"; @@ -39,7 +41,7 @@ public static String keyStrokeToString(KeyStroke key) { if (key == null) return ""; StringBuilder s = new StringBuilder(30); int m = key.getModifiers(); - if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) { + if( (m & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0 ){ //| InputEvent.CTRL_MASK)) != 0) s.append("Ctrl + "); } if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) { @@ -95,13 +97,14 @@ public static KeyStroke getKeyStroke(int keyCode) { return KeyStroke.getKeyStroke(getKeyText(keyCode)); } - public static KeyStroke getKeyStroke(int keyCode, boolean control, boolean shift, boolean alt, boolean released) { - return KeyStroke.getKeyStroke(getKeyText(keyCode, control, shift, alt, released)); + public static KeyStroke getKeyStroke(int keyCode, boolean control, boolean meta, boolean shift, boolean alt, boolean released) { + return KeyStroke.getKeyStroke(getKeyText(keyCode, control, meta, shift, alt, released)); } public static KeyStroke getKeyStroke(String kbStringSetting) { String[] keys = kbStringSetting.split("\\s*\\++\\s*"); boolean control = false; + boolean meta = false; boolean shift = false; boolean alt = false; boolean released = false; @@ -113,6 +116,9 @@ public static KeyStroke getKeyStroke(String kbStringSetting) { case "CONTROL": control = true; break; + case "META": + meta = true; + break; case "SHIFT": shift = true; break; @@ -129,15 +135,16 @@ public static KeyStroke getKeyStroke(String kbStringSetting) { if (keyCode == Integer.MIN_VALUE) { throw new IllegalArgumentException("String '" + kbStringSetting + "' cannot be parsed make sure it is a valid VK_* string"); } - return KeyStroke.getKeyStroke(getKeyText(keyCode, control, shift, alt, released)); + return KeyStroke.getKeyStroke(getKeyText(keyCode, control, meta, shift, alt, released)); } - public static String getKeyText(int keyCode, boolean control, boolean shift, boolean alt, boolean released) { + public static String getKeyText(int keyCode, boolean control, boolean meta, boolean shift, boolean alt, boolean released) { String keyText = getKeyText(keyCode); String retText = ""; if (shift) retText = retText + " " + SHIFT; if (control) retText = retText + " " + CONTROL; + if (meta) retText = retText + " " + META; if (alt) retText = retText + " " + ALT; if (released) retText = retText + " " + RELEASED; if (!released) retText = retText + " " + PRESSED; @@ -150,7 +157,7 @@ public static String getKeyText(int keyCode) { public static int keyEventModifiersToKeyStrokeModifiers(int modifiers) { int shift = InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK; - int ctrl = InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK; + int ctrl = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); // | InputEvent.CTRL_MASK; int alt = InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK; switch (modifiers) { case 1: