Ok, I have neglected the blog for a while, partly out of necessity as I was on vacation and without internet access, partly out of laziness. Neither of those reasons implies I didn’t do anything, though (yes, I work during my vacation because I enjoy my work), but I’ll fill in the gaps in a later post.
I was just going through some of the // TODO
items I had left in the DrJava codebase, and I came across a problem with the “Import Package” checkbox in the “Auto Import Class” dialog in the Interactions Pane (the dialog is displayed if a class name is not recognized because it has not been imported yet).
For this checkbox, I have used Java’s setMnemonic('p')
. On Windows, that means you press Alt+P, and the state of the checkbox toggles. On the Mac, however, it toggles AND inserts a Greek lower-case pi character. I searched for other uses of setMnemonic()
in DrJava, and we have a bunch of them:
- A similar checkbox controls whether the Standard Java API should be considered as well for auto-completion in the Definitions Pane (Ctrl-Space or Command-Space). Pressing Alt-J on the Mac, toggles the checkbox and inserts a Greek upper-case delta.
- All the menus in DrJava’s main windw (File, Edit, Tools, Project, Debug, Language Level and Help) have mnemonics set to respond to Alt-F/E/T/P/D/L/H. The behavior on the Mac is totally erratic:
- Alt-F displays the File menu, albeit in an awkward place, but also inserts a florin, which is a stylized lower-case f and apparently a currency symbol.
- Alt-E does not display the Edit menu, but instead inserts an accent acute and waits for a suitable second letter to be entered to create accented letters.
- Alt-T displays the Tools menu in an awkward place, but also inserts a dagger.
- Alt-P displays the Project menu in an awkward place and inserts the lower-case pi, as reported above.
- Alt-D displays the Debug menu in an awkward place and inserts what could be a lower-case delta.
- Alt-L displays the Language Level menu in an awkward place and inserts a logical not.
- Alt-H displays the Help menu in an awkward place and inserts what I believe is a diacritic dot, although it does not wait for a second letter, as Alt-E.
- In a currently unused class,
ScrollableListSelectionDialog
, there are mnemonics Alt-A and Alt-N for the “Select All” and “Select None” buttons, respectively.- Since there is no text input here, Alt-A, which would enter a Swedish/Danish a-circle, actually invokes the button’s action.
- Alt-N, however does not do anything. Just like Alt-E, if text were entered, it inserts a tilde and then waits for a second suitable letter to which the tilde will belong.
A good reference for the different Alt key combinations is at: Everything2 Special Alt key characters & accents.
As a summary, Java mnemonic on Mac OS are broken, and we need to do something about it. There are several options:
- We attempt to block the symbols from being inserted, but at least for Alt-E and Alt-N, possibly for other key combinations as well, the treatment might very well be a hard-wired Mac OS feature. Blocking these symbols would also make DrJava pretty much unusable for users who program in languages that use diacritics: German, French, and the Scandinavian languages, just to name a few.
- We ditch mnemonics on the Mac completely. Even though I miss the ability to open menus like a File menu using Alt-F as can be done Windows, I have never seen a Mac application that does that. So not using these mnemonics on Mac OS would probably make DrJava more compliant with Apple’s user interface guidelines.
There’s one caveat: We have to make sure that every feature that was accessible using a mnemonic is still accessible in some way on the Mac, probably using the mouse. However, I think that already is the case. - We use a different key for mnemonics on the Mac, e.g. Ctrl. This could work in most cases, since keyboard shortcuts like Ctrl-S to save a file on Windows are mapped to Command-S on the Mac. I checked, and the only places where we seem to have hard-coded the Ctrl, even on the Mac, is in the following places:
- Find/Replace panel: Ctrl-Enter inserts a newline instead of invoking the “Find Next” action; Ctrl-Tab inserts a tab instead of switching focus to the next component
- Interactions pane: Ctrl-Enter, same as above.
- Ctrl-Backtick/Ctrl-Shift-Backtick to switch back and forth between recent documents.
These cannot be replaced since Command-Tab toggles between MacOS applications and Command-Backtick between individual windows. Using Ctrl-Enter even though Command-Enter would work seems more consistent than using Ctrl-Tab to insert a tab, but Command-Enter to insert a newline.
I don’t know how difficult to implement this option is becausesetMnemonic()
asks either for a character like'p'
or for aVK_xxx
constant, but what mask key to use can’t be specified.
Considering these three options (that I can think of — please chime in if you have a different idea), I believe we should choose option 2) and disable mnemonics on the Mac.
It would still be very interesting to figure out how we can use the Mac OS-standard Command-Backtick/Command-Shift-Backtick to switch between documents.