I ran a query to see all the bugs fixed in the Eclipse Platform in 3.6; it is a long list (4309 and counting). Felipe gets credit for the oldest bug fixed (raised in 2001), but in a close second is bug 4922 (raised only a day later).
This bug is about opening files in eclipse from the command line. Fixing it required a coordinated effort between Platform UI, SWT , and the Equinox launcher . A lot of the credit for what was done goes to Kevin Barnes.
This post is an effort to explain some of the technical details of what is going here.
On the Mac... : On the mac all we do is handle the apple event "kAEOpenDocuments ", most of the rest of this post doesn't apply to the mac.
Windows and GTK... Everything below applies to Windows and GTK, though there are some differences in the implementation details.
On Motif... Sorry, this doesn't work on motif.
Everything starts in the eclipse launcher. We added a few new command line options:
The first argument is obvious enough, open the specified file in eclipse.
eclipse --launcher.openFile myFile.txt
This is great, but it is a bit much to type on the command line and is not quite enough to make everyone happy. We introduced the "default action" argument. This goes in the eclipse.ini file, the value should be "openFile ":
... -showsplash org.eclipse.platform --launcher.defaultAction openFile -vmargs -Xms256m -Xmx768m
This tells the launcher that if it is called with a command line that only contains arguments that don't start with "- ", then those arguments should be treated as if they followed "--launcher.openFile ".
eclipse myFile.txt
This is the kind of command line the launcher will receive on windows when you double click a file that is associated with eclipse, or you select files and choose "Open With" or "Send To " Eclipse.
Relative paths will be resolved first against the current working directory, and second against the eclipse program directory.
The launcher talks to SWT through the use of a hidden window. The launcher and SWT both need to agree on the name of this window . This allows the launcher to find an already running eclipse and tell it to open the file. Any RCP application will need to ensure they get this right for things to work.
The launcher bases this on its "official name". The official name can be set with the -name argument. If -name is not set, then the official name is derived from the launcher executable, the extension is removed and the first letter is capitalized: rcp.exe becomes Rcp .
SWT bases this on the value set with the Display.setAppName() function. Normally, this is set by the Workbench when it creates the display and the value is the "appName" taken from the product extension point.
To take advantage of this, an RCP Application will need to register a listener for the SWT.OpenDocument event. It should register this listener before calling PlatformUI.createAndRunWorkbench so that the listener is in place before the workbench starts running the event loop.
The event loop will start running while the splash screen is still up, so events may arrive before the workbench is ready to actually open an editor for the file. This means that the listener should save the file paths it gets from the OpenDocument events so they can be opened at some later time. WorkbenchAdvisor#eventLoopIdle can be a good place to check for saved open file events.
Here is an overview of the flow of events in the launcher when processing --launcher.openFile on windows.
On GTK, things happen in a similar manner with a few differences: