Wednesday, January 21, 2009

eRCP/eSWT: Windows CE and Win32 (XP): Different Keyboard Event Handling

When developing GUIs with Swing in Java I often swear about event handling, because it sometimes slightly differs from what the underlying platform would do. However when using SWT/eSWT and getting the native behaviors there are also gotchas waiting...

In our Eclipse Embedded Rich Client Platform (eRCP) based mobile application we want to allow keyboard as well as touch-screen access. In order to do so we attach a KeyListener to the buttons that handle the assigned shortcut bindings in addition to a SelectionListener to respond to clicks.

Another feature request called for the possibility to trigger a button by moving the focus to it with the keyboard and then hitting enter.

During development we usually work with the eSWT implementation for Win32. Because by default pressing enter does not do anything on a button, we add another KeyListener to respond to the return key. This usually works flawlessly. However on the mobile device we had trouble with button actions being triggered twice, even though the return key was only pressed once.

It took us some time to realize that the problem only occurs on the Windows CE platform, but never on our XP development machines.

This is were that “closer to the platform” part of SWT comes is: Hitting a button on a CE device seems to be the same as pressing return on it (as well as the space key, however on our hardware there is no way to do so except the onscreen keyboard). As soon as we removed the KeyListener that responded to the CR KeyEvent, the problems vanished on the mobile devices.

In retrospect it is hard to believe that we did not solve this much earlier. Seemingly regardless of whether you use a cross-platform library like Swing or the “closer to the real thing” SWT variant, you always seem to get caught by the same things – the one way round or the other…

Technorati Tags: ,,,,

Tuesday, January 20, 2009

Prefer plain-text message display in Apple Mail

If a received mail contains a plain-text part I prefer Mail to display that instead of the often more “stylish” HTML or Rich-Text parts. While this cannot be configured via the GUI, it can be from the command line.

This is a reminder post for myself and anyone who might be interested.

Turn on:

defaults write com.apple.mail PreferPlainText -bool TRUE

Turn off:

defaults delete com.apple.mail PreferPlainText

Mail.app should be closed while you do this.

Technorati Tags: ,,,,

Friday, January 16, 2009

Windows CE 5 Batch File Caveats

If you find yourself in the unlucky position to have to write some batch files for the Windows CE5 version of cmd.exe (called Pocket CMD v 5.0) you might be interested in these peculiarities I stumbled across today:

  • IF EXIST foldername GOTO label

    This will not tell you for real if a folder called "foldername" exists and jump to "label" if it does. Instead, this will always fail and never jump to the designated target label. You can try this yourself with

    IF NOT EXIST \WINDOWS ECHO "I have no OS"

    If this output were true, I'd wonder where the Pocket CMD that had issued the command came from.

    You need to check for a file contained in that folder with IF EXISTS, which will work fine. If you do not know a file name to check for - for example if you want to check if a removable storage card is inserted, you can check for the "nul" file which will always exist on a FAT formatted drive, according to Microsoft Knowledge Base Entry #65994

  • IF ERRORLEVEL 10 GOTO fatalError

    This will not jump to the "fatalError" label in case the program that last finished with an exit code of 10 or above.

    Instead you will get an error message "Bad errorlevel conditional". In the German localization of CE5 this is even better: "Ungültige Bedingung in Fehlerebene" and proves that the person who translated this had no idea what the message meant. The problem in fact is, that the Pocket CMD only allows single digit error levels!

    If you want (or rather have) to use errorlevels in your batch script, you better hope (or can control) the exit codes of the applications you'd like to query.

If I come across more things like this, I will update this post.

Tuesday, January 06, 2009

Launch Mac application / AppleScript by keyboard

In the comments to my recent post about full keyboard access to Mac OS X GUI controls “christian” asks about a way to open a new Finder window regardless of the front application. I understand his need, on Windows you just hit Windows+E anywhere and get a new Explorer window.

So far I have worked around this when I needed a Finder window by first hitting F19 which I bound to Exposé’s Show Desktop option and then clicking on the desktop. This enabled the finder and allows the Cmd-N hotkey to work.

However being able to just bring up a new Finder window from anywhere would of course be preferable. I first tried through the keyboard system preferences, however even though you can bind new keyboard shortcuts to any menu item by name. Because the application you target usually needs to focused this would not be of much help. There is a “Any application” setting, but this seems to work for a few people if any. I have not managed to get it right.

In Apple’s AppleScript documentation there is an example of how to bring up a Finder window with specific settings (like Column, List or Icon View, the initially displayed folder etc.) that goes like this:

tell the application "Finder"
	set w to make Finder window to home
	set current view of w to column view
	set toolbar visible of w to true
	set sidebar width of w to 0
end tell

On the net I found a nice little application called “Spark”. It provides a working way to define system wide keyboard shortcuts. Among other things like simply launching an app you can also execute AppleScripts. So I just defined Cmd-Shift-E – similar to Windows-E – to run the aforementioned script.

Picture 6

When you first start Spark it allows you to enable it on logon, so it is immediately available even after a reboot. I have not yet tried what happens if an application defines a shortcut for itself, so maybe there will need to be some tweaking.

Sunday, January 04, 2009

Migrate VM from VirtualBox to VMware Fusion

For some time I have been using VirtualBox to run the few Windows applications I still need. While being generally very usable there were still some issues with networking, sharing folders and sometimes the VM would crash when shutting down the guest OS.

Yesterday I decided to give VMware Fusion a chance. I downloaded and installed the trial version. Because I did not want to reinstall Vista and go through the whole update story again I looked for a way to reuse the existing VirtualBox VM. Unfortunately VMware cannot open the VDI files directly.

There are some How-To’s on the web which usually include some trickery with Linux or at least involve several steps, but all those seemed a little too much hassle for me and I kept looking for an easier way.

Turns out, VMware themselves offer the solution for free: Fusion’s main menu bar includes a “Migrate your PC…” option that will just open browser and take you to http://www.vmware.com/download/fusion/windows_to_mac.html.

VMware Converter Web Site

There you can first have a look at a video which shows the process of downloading and installing the VMware Converter started edition. This tool is designed to create a new Virtual Machine from a running physical PC.

I imagined that this tool would not really mind whether I was running Vista on a physical piece of equipment or inside a different virtualization product, so I downloaded it into the Virtual Box Vista VM and installed it.

From there everything was really simple. I just had to click through the conversion wizard and point to a directory (I used an external USB drive) where the new VM was to be created and stored.

Conversion of the Vista installation with approx. 18GB of used space on a 20GB virtual hard disk took about some hours – I let it run over night. In the morning I could simply open the newly created machine with Fusion. Booting took some time and once I had logged in Vista detected tons of new hardware and installed the necessary drivers. One time I saw a wizard come up and ask for drivers for a “Base system device”. As I could not do anything about it I just ignored it. Later I installed VMware tools manually again which seems to have fixed whatever was missing.

Through the Control Panel I uninstalled the VirtualBox Guest additions and VMware Converter which of course migrated itself over.

Live Writer in Unity mode So far I have not seen any problems – the integration experience is really good. I just set up some shared folders with no problems at all. Right now I am writing this post in Windows Live Writer in Unity mode, creating screenshots in Mac OS and simply importing them through the shared folders. Something that seems to be a problem of Live Writer was an exception message when I tried to insert a PNG by going through the UNC Path to the host which starts with \\.host\… This brought up an error where the stack trace said something about problems parsing the host name. I just mapped a drive letter to get around that.

From what I have seen so far I think I will just buy a license after the end of the trial.

Saturday, January 03, 2009

Mac OS X – Full Keyboard Control

As a long time Windows user I still have some trouble finding my way around Mac OS X Leopard without resorting to the mouse all the time. I am a “keyboard person” and like to keep my hands right before me instead of constantly reaching for the mouse.

When I started to use Mac OS I believed it would simply be a matter of practice and learning some new key combinations until I could work as mouselessly as before.

Since August I have gotten much more fluent with the keyboard alone, but something that bothered me ever since was that not every button, tab, slider etc. could be focused with the TAB key or activated using some mnemonic – as is normal in virtually every Windows application, especially Microsoft’s own ones.

On the Mac the focus would only jump between various text controls and not to buttons and the like. I started to believe that the Apple idea of “keep things simple and define a default that’s good for 90% of the people” without a chance for the remaining 10% to have things their way was going a little too far here.

Only recently when I started using XCode to get my feet wet with Cocoa and Objective-C I looked for a way to quickly switch between my default German keyboard layout – which is sensible for writing Mails, letters etc. – and a UK/US English one – much easier to program with as all the square and curly brackets are located in a much easier way. On Windows I just hit the left Alt and Shift keys to toggle thru the list of active keyboard mappings.

Though the Mac’s System Preferences “International” applet I activated the “U.S. Extended” keyboard layout and defined Ctrl-Option-Space as the toggle. Only by change I clicked on the “Keyboard Shortcuts…” button:

Picture 1

This opens the “Keyboard and Mouse” preferences:

Picture 2

There – one the rightmost tab – sits the option I have been looking for: “Full keyboard access”. Switch to “All controls” and now I can readily reach all controls without having to get my fingers off the mouse. Guess it will still be some time until I am “as at home” in Mac OS as I was in Windows.