Skip to content

Commit

Permalink
Mac specific shortcuts
Browse files Browse the repository at this point in the history
- Add Mac specific Copy/Paste/Cut shortcuts, since the LaF doesn't seem to do it (or at least not always)
- Update version number in help
  • Loading branch information
tduva committed Jun 12, 2016
1 parent 6c06605 commit b5c7ecb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/chatty/gui/GuiUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

package chatty.gui;

import chatty.util.MiscUtil;
import java.awt.Component;
import java.awt.Container;
import java.awt.Frame;
Expand All @@ -20,6 +21,7 @@
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
Expand All @@ -31,6 +33,7 @@
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.Document;
import javax.swing.text.Element;

Expand Down Expand Up @@ -238,6 +241,7 @@ public static void setLookAndFeel(String lafCode) {
}
LOGGER.info("Setting LAF to " + laf);
UIManager.setLookAndFeel(laf);
addMacCopyPaste();
} catch (Exception ex) {
LOGGER.warning("Failed setting LAF: "+ex);
}
Expand Down Expand Up @@ -320,4 +324,28 @@ public static void setSortingForTable(JTable table, String sorting) {
}
}

/**
* Adds the Copy/Paste/Cut shortcuts for Mac (Command instead of Ctrl).
*
* <p>Normally the Look&Feel should do that automatically, but for some
* reason it doesn't seem to do it.</p>
*/
public static void addMacCopyPaste() {
if (MiscUtil.OS_MAC) {
addMacCopyPasteTo("TextField.focusInputMap");
addMacCopyPasteTo("TextArea.focusInputMap");
addMacCopyPasteTo("TextPane.focusInputMap");
}
}

/**
* Based on: http://stackoverflow.com/a/7253059/2375667
*/
private static void addMacCopyPasteTo(String key) {
InputMap im = (InputMap) UIManager.get(key);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.META_DOWN_MASK), DefaultEditorKit.copyAction);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.META_DOWN_MASK), DefaultEditorKit.pasteAction);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.META_DOWN_MASK), DefaultEditorKit.cutAction);
}

}
2 changes: 1 addition & 1 deletion src/chatty/gui/components/help/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h1><a name="top">Chatty (Version: 0.8.3b2)</a></h1>
<h1><a name="top">Chatty (Version: 0.8.3b3)</a></h1>
<table>
<tr>
<td valign="top">
Expand Down

0 comments on commit b5c7ecb

Please sign in to comment.