Skip to content

Commit

Permalink
#150 MAC OS
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Justin committed Feb 20, 2021
1 parent 15100e8 commit 28c505f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
22 changes: 12 additions & 10 deletions src/at/mep/editor/EMEPKeyStrokes.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@

import at.mep.EMatlabKeyStrokesCommands;
import at.mep.util.KeyStrokeUtil;
import java.awt.Toolkit;

import javax.swing.*;
import java.awt.event.KeyEvent;

/** 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;
Expand Down
2 changes: 1 addition & 1 deletion src/at/mep/gui/components/UndecoratedFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
21 changes: 14 additions & 7 deletions src/at/mep/util/KeyStrokeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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:
Expand Down

0 comments on commit 28c505f

Please sign in to comment.