@@ -123,6 +124,40 @@
mods = (mods & ~ InputEvent.META_MASK) | InputEvent.ALT_MASK;
ev.setModifiers(mods);
}
+ }
+
+ if (Utilities.getOperatingSystem() == Utilities.OS_MAC) {
+ boolean macSwap = Boolean.getBoolean (
+ "nb.mac.swap.ctrl.and.alt"); //NOI18N
+ if (macSwap) {
+ //Allows international keyboards to use the Alt key as the Compose
+ //key
+ int mods = ev.getModifiers();
+ System.setProperty ("lastKeyModifiers", Integer.toString(mods)); //NOI18N
+ boolean isCtrl = (mods & InputEvent.CTRL_MASK) != 0;
+ boolean isAlt = (mods & InputEvent.ALT_MASK) != 0;
+ int code = ev.getKeyCode();
+ boolean skip = code == KeyEvent.VK_UP || code == KeyEvent.VK_DOWN ||
+ code == KeyEvent.VK_RIGHT || code == KeyEvent.VK_LEFT ||
+ code == KeyEvent.VK_ENTER || code == KeyEvent.VK_SPACE;
+ if (isCtrl != isAlt && !skip) {
+ if (isAlt) {
+ mods ^= InputEvent.ALT_MASK;
+ mods |= InputEvent.CTRL_MASK;
+ }
+ if (isCtrl) {
+ mods ^= InputEvent.CTRL_MASK;
+ mods |= InputEvent.ALT_MASK;
+ }
+ ev.setModifiers (mods);
+ }
+ }
+ if (wasMacSwap != macSwap) {
+ if (!macSwap) {
+ System.getProperties().remove ("lastKeyModifiers"); //NOI18N
+ }
+ }
+ wasMacSwap = macSwap;
}
if (ev.getID() == KeyEvent.KEY_PRESSED
Index: editor/libsrc/org/netbeans/editor/BaseKit.java
===================================================================
RCS file: /cvs/editor/libsrc/org/netbeans/editor/BaseKit.java,v
retrieving revision 1.118
diff -u -u -r1.118 BaseKit.java
--- editor/libsrc/org/netbeans/editor/BaseKit.java 29 Sep 2004 13:08:24 -0000 1.118
+++ editor/libsrc/org/netbeans/editor/BaseKit.java 1 Oct 2004 15:32:24 -0000
@@ -780,28 +780,38 @@
int mod = evt.getModifiers();
boolean ctrl = ((mod & ActionEvent.CTRL_MASK) != 0);
// On the mac, norwegian and french keyboards use Alt to do bracket characters.
- // This replicates Apple's modification DefaultEditorKit.DefaultKeyTypedAction
boolean alt = ((mod & ActionEvent.ALT_MASK) != 0);
- if (isMac && alt) {
- //Ugly, but without IDE-wide global keybinding registry, there
- //simply is no way to find out if it's a character we want
- //or not, so filter for commonly used characters and otherwise
- //handle normally. The problem is really Apple's, that they
- //use Alt- as the compose key in some locales. Eventually
- //perhaps the applemenu module could detect this and provide alternate
- //bindings with a line switch for all Alt- bindings. For
- //4.0, this will have to do.
- //
- //Original patch replicated what Apple does in DefaultKeyAction,
- //(check META instead of ALT) but this broke all Alt-
- //shortcuts. So we do it the ugly way.
- //
- //This *does* break Alt-8/9 key combinations on norwegian and
- //french keyboards, but that's better than not being able to
- //type brackets
- String cmd = evt.getActionCommand();
- alt &= !"{".equals(cmd) && !"}".equals(cmd) && !"[".equals(cmd) && //NOI18N
- !"]".equals(cmd) && !"(".equals(cmd) && !")".equals(cmd); //NOI18N
+
+ if (isMac) {
+ boolean macSwap = Boolean.getBoolean (
+ "nb.mac.swap.ctrl.and.alt"); //NOI18N
+
+ if (alt && !macSwap) {
+ //Ugly, but without IDE-wide global keybinding registry, there
+ //simply is no way to find out if it's a character we want
+ //or not, so filter for commonly used characters and otherwise
+ //handle normally. The problem is really Apple's, that they
+ //use Alt- as the compose key in some locales. Eventually
+ //perhaps the applemenu module could detect this and provide alternate
+ //bindings with a line switch for all Alt- bindings. For
+ //4.0, this will have to do.
+ //
+ //Original patch replicated what Apple does in DefaultKeyAction,
+ //(check META instead of ALT) but this broke all Alt-
+ //shortcuts. So we do it the ugly way.
+ //
+ //This *does* break Alt-8/9 key combinations on norwegian and
+ //french keyboards, but that's better than not being able to
+ //type brackets
+ String cmd = evt.getActionCommand();
+ alt &= !"{".equals(cmd) && !"}".equals(cmd) && !"[".equals(cmd) && //NOI18N
+ !"]".equals(cmd) && !"(".equals(cmd) && !")".equals(cmd); //NOI18N
+ } else if (macSwap) {
+ //Allow alt keys through if the flag is set - replicate
+ //Apple's hack in DefaultKeyAction.
+ alt = false;
+ ctrl = false;
+ }
}
if ((alt && !ctrl) || (ctrl && !alt)) {
Index: editor/libsrc/org/netbeans/editor/ext/ExtKit.java
===================================================================
RCS file: /cvs/editor/libsrc/org/netbeans/editor/ext/ExtKit.java,v
retrieving revision 1.50
diff -u -u -r1.50 ExtKit.java
--- editor/libsrc/org/netbeans/editor/ext/ExtKit.java 14 Sep 2004 14:16:04 -0000 1.50
+++ editor/libsrc/org/netbeans/editor/ext/ExtKit.java 1 Oct 2004 15:32:27 -0000
@@ -15,6 +15,7 @@
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
+import java.awt.event.InputEvent;
import java.io.IOException;
import java.util.List;
import java.util.Iterator;
@@ -397,12 +398,35 @@
}
public void actionPerformed(ActionEvent evt, JTextComponent target) {
+ //Hack: On the mac, we provide an action to globally swap
+ //Ctrl and Alt, so Alt can be used as a control character. But
+ //Goto is bound to Ctrl-G even on mac, so we need to suppress it,
+ //or Alt-G when swapped will not insert an international character.
+ //We provide the alternate binding AS-G so Goto can work even in
+ //swapped mode. See
+ //org.netbeans.core.windows.ShortcutKeyAndMenuEventProcessor
+
+ if (isMac) {
+ String lastMods = System.getProperty("lastKeyModifiers"); //NOI18N
+ if (lastMods != null) {
+ try {
+ int mods = Integer.parseInt(lastMods);
+ if ((mods & InputEvent.ALT_MASK) != 0) {
+ return;
+ }
+ } catch (NumberFormatException e) {
+ //do nothing
+ }
+ }
+ }
+
if (target != null) {
new GotoDialogSupport().showGotoDialog(new KeyEventBlocker(target, false));
}
}
}
+ private static final boolean isMac = System.getProperty("mrj.version") != null; //NOI18N
/** Action to go to the declaration of the variable under the caret.
*/
Index: editor/libsrc/org/netbeans/editor/ext/ExtSettingsDefaults.java
===================================================================
RCS file: /cvs/editor/libsrc/org/netbeans/editor/ext/ExtSettingsDefaults.java,v
retrieving revision 1.35
diff -u -u -r1.35 ExtSettingsDefaults.java
--- editor/libsrc/org/netbeans/editor/ext/ExtSettingsDefaults.java 8 Sep 2004 17:09:06 -0000 1.35
+++ editor/libsrc/org/netbeans/editor/ext/ExtSettingsDefaults.java 1 Oct 2004 15:32:27 -0000
@@ -73,6 +73,7 @@
public static final Dimension defaultJavaDocPreferredSize = new Dimension(500, 300);
public static final Boolean defaultJavaDocAutoPopup = Boolean.TRUE;
private static int MENU_MASK = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
+ private static boolean IS_MAC = System.getProperty("mrj.version") != null;
public static final MultiKeyBinding[] defaultExtKeyBindings
= new MultiKeyBinding[] {
@@ -90,19 +91,29 @@
ExtKit.findAction
),
new MultiKeyBinding(
- KeyStroke.getKeyStroke(KeyEvent.VK_H, MENU_MASK),
+ KeyStroke.getKeyStroke(IS_MAC ? KeyEvent.VK_R : KeyEvent.VK_H, MENU_MASK),
ExtKit.replaceAction
),
new MultiKeyBinding(
KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK),
ExtKit.gotoAction
),
+ //Next entry is to handle suppression of Ctrl-G on mac when
+ //ctrl and alt are swapped (alt is the compose key for international
+ //keyboards on mac, so we allow swapping of Alt and G keys via a
+ //shortcut so users have full use of their keyboard when necessary.
+ //In swap mode, this binding is actually invoked on Ctrl-Shift-G,
+ //not Alt-Shift-G. Wish there were a better way to solve it.
+ new MultiKeyBinding(
+ KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK),
+ ExtKit.gotoAction
+ ),
new MultiKeyBinding(
KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.CTRL_MASK),
ExtKit.completionShowAction
),
new MultiKeyBinding( // Japanese Solaris uses CTRL+SPACE for IM
- KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SLASH, InputEvent.CTRL_MASK),
+ KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SLASH, MENU_MASK),
ExtKit.completionShowAction
),
new MultiKeyBinding(
Index: editor/src/org/netbeans/modules/editor/resources/XMLs/DefaultGlobalKeyBindings.xml
===================================================================
RCS file: /cvs/editor/src/org/netbeans/modules/editor/resources/XMLs/DefaultGlobalKeyBindings.xml,v
retrieving revision 1.11
diff -u -u -r1.11 DefaultGlobalKeyBindings.xml
--- editor/src/org/netbeans/modules/editor/resources/XMLs/DefaultGlobalKeyBindings.xml 8 Sep 2004 17:09:07 -0000 1.11
+++ editor/src/org/netbeans/modules/editor/resources/XMLs/DefaultGlobalKeyBindings.xml 1 Oct 2004 15:32:28 -0000
@@ -97,6 +97,9 @@
+
+
Index: ide/applemenu/src/org/netbeans/modules/applemenu/Bundle.properties
===================================================================
RCS file: /cvs/ide/applemenu/src/org/netbeans/modules/applemenu/Bundle.properties,v
retrieving revision 1.1
diff -u -u -r1.1 Bundle.properties
--- ide/applemenu/src/org/netbeans/modules/applemenu/Bundle.properties 8 Jun 2004 12:46:09 -0000 1.1
+++ ide/applemenu/src/org/netbeans/modules/applemenu/Bundle.properties 1 Oct 2004 15:32:41 -0000
@@ -18,3 +18,6 @@
and moves some standard menu items there - Tools | Options becomes \
Preferences, Help | About becomes about, File | Exit becomes Quit.
+LBL_SwapCtrlAlt=Swap Ctrl and Alt
+MSG_Swapped=Ctrl and Alt swapped
+MSG_NotSwapped=Ctrl and Alt swapping off
Index: ide/applemenu/src/org/netbeans/modules/applemenu/DefaultGlobalKeyBindings.xml
===================================================================
RCS file: /cvs/ide/applemenu/src/org/netbeans/modules/applemenu/DefaultGlobalKeyBindings.xml,v
retrieving revision 1.1
diff -u -u -r1.1 DefaultGlobalKeyBindings.xml
--- ide/applemenu/src/org/netbeans/modules/applemenu/DefaultGlobalKeyBindings.xml 8 Sep 2004 17:09:09 -0000 1.1
+++ ide/applemenu/src/org/netbeans/modules/applemenu/DefaultGlobalKeyBindings.xml 1 Oct 2004 15:32:41 -0000
@@ -120,7 +120,7 @@
-
+
Index: ide/applemenu/src/org/netbeans/modules/applemenu/SwapCtrlAltAction.java
===================================================================
RCS file: ide/applemenu/src/org/netbeans/modules/applemenu/SwapCtrlAltAction.java
diff -N ide/applemenu/src/org/netbeans/modules/applemenu/SwapCtrlAltAction.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ide/applemenu/src/org/netbeans/modules/applemenu/SwapCtrlAltAction.java 1 Oct 2004 15:32:42 -0000
@@ -0,0 +1,84 @@
+/*
+ * Sun Public License Notice
+ *
+ * The contents of this file are subject to the Sun Public License
+ * Version 1.0 (the "License"). You may not use this file except in
+ * compliance with the License. A copy of the License is available at
+ * http://www.sun.com/
+ *
+ * The Original Code is NetBeans. The Initial Developer of the Original
+ * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ */
+/*
+ * SwapCtrlAltAction.java
+ *
+ * Created on October 1, 2004, 1:48 PM
+ */
+
+package org.netbeans.modules.applemenu;
+
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.HelpCtx;
+import org.openide.util.NbBundle;
+import org.openide.util.actions.BooleanStateAction;
+
+/**
+ * Apple uses Alt- as the compose key on international keyboards. This causes
+ * a bunch of conflicts with key bindings. There are low level patches in the
+ * editor and window system to swap Ctrl- and Alt- if a system property is set
+ * to true.
+ *
+ * This action toggles the system property nb.mac.swap.ctrl.and.alt
,
+ * so that international keyboard users can switch between having alt bindings
+ * and having full use of Alt as a compose key on the mac.
+ *
+ * In a perfect world, we would simply not have any Alt- bindings on the mac, and
+ * use Ctrl as an appropriate substitute. Currently, that is not a realistic
+ * option, as there is no way to detect when an international keyboard is
+ * present, and using Alt- for bindings on U.S. keyboards is very likely the
+ * most intuitive choice (not to mention the docs issues it would cause).
+ *
+ * @author Tim Boudreau
+ * @see org.netbeans.core.windows.ShortcutAndMenuKeyEventProcessor#dispatchKeyEvent
+ * @see org.netbeans.editor.BaseKit.DefaultKeyTypedAction#actionPerformed
+ */
+public class SwapCtrlAltAction extends BooleanStateAction {
+ private static final String PROP_KEY = "nb.mac.swap.ctrl.and.alt"; //NOI18N
+
+ /** Creates a new instance of SwapCtrlAltAction */
+ public SwapCtrlAltAction() {
+
+ }
+
+ public void actionPerformed (java.awt.event.ActionEvent ev) {
+ super.actionPerformed (ev);
+ boolean hasProp = propSet();
+ if (hasProp) {
+ System.setProperty(PROP_KEY, "false"); //NOI18N
+ StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(
+ SwapCtrlAltAction.class, "MSG_NotSwapped")); //NOI18N
+ } else {
+ System.setProperty(PROP_KEY, "true"); //NOI18N
+ StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(
+ SwapCtrlAltAction.class, "MSG_Swapped")); //NOI18N
+ }
+ }
+
+ private boolean propSet () {
+ return Boolean.getBoolean (PROP_KEY);
+ }
+
+ protected void initialize () {
+ super.initialize();
+ putProperty(PROP_BOOLEAN_STATE, propSet() ? Boolean.TRUE : Boolean.FALSE);
+ }
+
+ public HelpCtx getHelpCtx() {
+ return HelpCtx.DEFAULT_HELP;
+ }
+
+ public String getName() {
+ return NbBundle.getMessage (SwapCtrlAltAction.class, "LBL_SwapCtrlAlt"); //NOI18N
+ }
+}
Index: ide/applemenu/src/org/netbeans/modules/applemenu/layer.xml
===================================================================
RCS file: /cvs/ide/applemenu/src/org/netbeans/modules/applemenu/layer.xml,v
retrieving revision 1.2
diff -u -u -r1.2 layer.xml
--- ide/applemenu/src/org/netbeans/modules/applemenu/layer.xml 8 Sep 2004 17:09:09 -0000 1.2
+++ ide/applemenu/src/org/netbeans/modules/applemenu/layer.xml 1 Oct 2004 15:32:42 -0000
@@ -34,7 +34,11 @@
--->
+-->
+
+
+
+
@@ -62,6 +66,12 @@