Index: /trunk/build.xml
===================================================================
--- /trunk/build.xml	(revision 7286)
+++ /trunk/build.xml	(revision 7287)
@@ -153,9 +153,7 @@
             <arch name="i386"/>
 
-            <bundledocument extensions="osm" icon="macosx/JOSM.app/Contents/Resources/JOSM.icns" name="OSM files" role="editor"/>
-
             <classpath file="${bundle.jar}"/>
 
-            <option value="-Xmx512m"/>
+            <option value="-Xmx1024m"/>
 
             <option value="-Xdock:icon=Contents/Resources/JOSM.icns"/>
@@ -174,7 +172,8 @@
         
         <xmltask source="${bundle.outdir}/JOSM.app/Contents/Info.plist" dest="${bundle.outdir}/JOSM.app/Contents/Info.plist" indent="false">
-            <insert position="before" path="/plist/dict/key[1]"><![CDATA[<key>CFBundleAllowMixedLocalizations</key>
-<string>true</string>
-]]></insert>
+        	<!-- remove empty CFBundleDocumentTypes definition -->
+        	<remove path="/plist/dict/key[text()='CFBundleDocumentTypes']|/plist/dict/key[text()='CFBundleDocumentTypes']/following-sibling::array[1]"/>
+            <!-- insert our own keys -->
+            <insert position="before" path="/plist/dict/key[1]" file="macosx/JOSM.app/Contents/Info.plist_template.xml" />
         </xmltask>
         
Index: /trunk/macosx/JOSM.app/Contents/Info.plist_template.xml
===================================================================
--- /trunk/macosx/JOSM.app/Contents/Info.plist_template.xml	(revision 7287)
+++ /trunk/macosx/JOSM.app/Contents/Info.plist_template.xml	(revision 7287)
@@ -0,0 +1,75 @@
+<key>CFBundleAllowMixedLocalizations</key>
+<string>true</string>
+<key>UTExportedTypeDeclarations</key>
+<array>
+    <dict>
+        <key>UTTypeIdentifier</key>
+        <string>org.openstreetmap.josm.osm</string>
+        <key>UTTypeDescription</key>
+        <string>JOSM File</string>
+        <key>UTTypeIconFile</key>
+        <string>macosx/JOSM.app/Contents/Resources/JOSM.icns</string>
+        <key>UTTypeReferenceURL</key>
+        <string>http://wiki.openstreetmap.org/wiki/JOSM_file_format</string>
+        <key>UTTypeConformsTo</key>
+        <array>
+            <string>public.xml</string>
+        </array>
+        <key>UTTypeTagSpecification</key>
+        <dict>
+            <key>com.apple.ostype</key>
+            <string>JOSM</string>
+            <key>public.filename-extension</key>
+            <array>
+                <string>osm</string>
+            </array>
+        </dict>
+    </dict>
+</array>
+<key>CFBundleDocumentTypes</key>
+<array>
+    <dict>
+        <key>CFBundleTypeIconFile</key>
+        <string>macosx/JOSM.app/Contents/Resources/JOSM.icns</string>
+        <key>CFBundleTypeName</key>
+        <string>OSM Files</string>
+        <key>CFBundleTypeRole</key>
+        <string>Editor</string>
+        <key>LSHandlerRank</key>
+        <string>Owner</string>
+        <key>LSItemContentTypes</key>
+        <array>
+            <string>org.openstreetmap.josm.osm</string>
+        </array>
+        <key>NSExportableTypes</key>
+        <array>
+            <string>org.openstreetmap.josm.osm</string>
+            <string>com.pkware.zip-archive</string>
+            <string>org.gnu.gnu-zip-archive</string>
+            <string>public.archive.bzip2</string>
+        </array>
+    </dict>
+    <dict>
+        <key>CFBundleTypeIconFile</key>
+        <string>macosx/JOSM.app/Contents/Resources/JOSM.icns</string>
+        <key>CFBundleTypeName</key>
+        <string>OSM Compressed Files</string>
+        <key>CFBundleTypeRole</key>
+        <string>Editor</string>
+        <key>LSHandlerRank</key>
+        <string>Alternate</string>
+        <key>LSItemContentTypes</key>
+        <array>
+            <string>com.pkware.zip-archive</string>
+            <string>org.gnu.gnu-zip-archive</string>
+            <string>public.archive.bzip2</string>
+        </array>
+        <key>NSExportableTypes</key>
+        <array>
+            <string>org.openstreetmap.josm.osm</string>
+            <string>com.pkware.zip-archive</string>
+            <string>org.gnu.gnu-zip-archive</string>
+            <string>public.archive.bzip2</string>
+        </array>
+    </dict>
+</array>
Index: /trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java	(revision 7286)
+++ /trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java	(revision 7287)
@@ -10,4 +10,5 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
+import java.util.Arrays;
 import java.util.List;
 
@@ -15,6 +16,8 @@
 
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.actions.OpenFileAction;
+import org.openstreetmap.josm.actions.OpenFileAction.OpenFileTask;
 import org.openstreetmap.josm.data.Preferences;
+import org.openstreetmap.josm.io.OsmTransferException;
+import org.xml.sax.SAXException;
 
 /**
@@ -37,19 +40,20 @@
     @Override
     public void startupHook() {
-        // Here we register callbacks for the menu entries in the system menu
+        // Here we register callbacks for the menu entries in the system menu and file opening through double-click
         try {
             Class<?> Ccom_apple_eawt_Application = Class.forName("com.apple.eawt.Application");
+            Class<?> Ccom_apple_eawt_QuitHandler = Class.forName("com.apple.eawt.QuitHandler");
+            Class<?> Ccom_apple_eawt_AboutHandler = Class.forName("com.apple.eawt.AboutHandler");
+            Class<?> Ccom_apple_eawt_OpenFilesHandler = Class.forName("com.apple.eawt.OpenFilesHandler");
+            Class<?> Ccom_apple_eawt_PreferencesHandler = Class.forName("com.apple.eawt.PreferencesHandler");
             Object Ocom_apple_eawt_Application = Ccom_apple_eawt_Application.getConstructor((Class[])null).newInstance((Object[])null);
-            Class<?> Ccom_apple_eawt_ApplicationListener = Class.forName("com.apple.eawt.ApplicationListener");
-            Method MaddApplicationListener = Ccom_apple_eawt_Application.getDeclaredMethod("addApplicationListener", Ccom_apple_eawt_ApplicationListener);
-            Object Oproxy = Proxy.newProxyInstance(PlatformHookOsx.class.getClassLoader(), new Class<?>[] { Ccom_apple_eawt_ApplicationListener }, ivhandler);
-            MaddApplicationListener.invoke(Ocom_apple_eawt_Application, Oproxy);
-            Method MsetEnabledPreferencesMenu = Ccom_apple_eawt_Application.getDeclaredMethod("setEnabledPreferencesMenu", boolean.class);
-            MsetEnabledPreferencesMenu.invoke(Ocom_apple_eawt_Application, Boolean.TRUE);
-            // Register callback for file opening through double-click
-            Class<?> Ccom_apple_eawt_OpenFilesHandler = Class.forName("com.apple.eawt.OpenFilesHandler");
-            Method MsetOpenFileHandler = Ccom_apple_eawt_Application.getDeclaredMethod("setOpenFileHandler", Ccom_apple_eawt_OpenFilesHandler);
-            Object Oproxy2 = Proxy.newProxyInstance(PlatformHookOsx.class.getClassLoader(), new Class<?>[] { Ccom_apple_eawt_OpenFilesHandler }, ivhandler);
-            MsetOpenFileHandler.invoke(Ocom_apple_eawt_Application, Oproxy2);
+            Object Oproxy = Proxy.newProxyInstance(PlatformHookOsx.class.getClassLoader(), new Class<?>[] {
+                Ccom_apple_eawt_QuitHandler, Ccom_apple_eawt_AboutHandler, Ccom_apple_eawt_OpenFilesHandler, Ccom_apple_eawt_PreferencesHandler}, ivhandler);
+            Ccom_apple_eawt_Application.getDeclaredMethod("setQuitHandler", Ccom_apple_eawt_QuitHandler).invoke(Ocom_apple_eawt_Application, Oproxy);
+            Ccom_apple_eawt_Application.getDeclaredMethod("setAboutHandler", Ccom_apple_eawt_AboutHandler).invoke(Ocom_apple_eawt_Application, Oproxy);
+            Ccom_apple_eawt_Application.getDeclaredMethod("setOpenFileHandler", Ccom_apple_eawt_OpenFilesHandler).invoke(Ocom_apple_eawt_Application, Oproxy);
+            Ccom_apple_eawt_Application.getDeclaredMethod("setPreferencesHandler", Ccom_apple_eawt_PreferencesHandler).invoke(Ocom_apple_eawt_Application, Oproxy);
+            // this method has been deprecated, but without replacement ATM
+            Ccom_apple_eawt_Application.getDeclaredMethod("setEnabledPreferencesMenu", boolean.class).invoke(Ocom_apple_eawt_Application, Boolean.TRUE);
         } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) {
             // We'll just ignore this for now. The user will still be able to close JOSM by closing all its windows.
@@ -61,7 +65,6 @@
     @Override
     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-        Boolean handled = Boolean.TRUE;
         if (Main.isDebugEnabled()) {
-            Main.debug("OSX handler: "+method.getName()+" - "+args);
+            Main.debug("OSX handler: "+method.getName()+" - "+Arrays.toString(args));
         }
         switch (method.getName()) {
@@ -69,19 +72,31 @@
             if (args[0] != null) {
                 try {
-                    Object oFiles = args[0].getClass().getDeclaredMethod("getFiles").invoke(args[0]);
+                    Object oFiles = args[0].getClass().getMethod("getFiles").invoke(args[0]);
                     if (oFiles instanceof List) {
-                        OpenFileAction.openFiles((List<File>)oFiles, true);
-                    } else {
-                        Main.warn("OSX openFiles called without List: "+oFiles);
+                        Main.worker.submit(new OpenFileTask((List<File>)oFiles, null) {
+                            @Override
+                            protected void realRun() throws SAXException, IOException, OsmTransferException {
+                                // Wait for JOSM startup is advanced enough to load a file
+                                while (Main.parent == null || !Main.parent.isVisible()) {
+                                    try {
+                                        Thread.sleep(25);
+                                    } catch (InterruptedException e) {
+                                        Main.warn(e);
+                                    }
+                                }
+                                super.realRun();
+                            }
+                        });
                     }
                 } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) {
                     Main.warn("Failed to access open files event: " + ex);
                 }
-            } else {
-                Main.warn("OSX openFiles called without args");
             }
-            return null;
-        case "handleQuit":
-            handled = Main.exitJosm(false, 0);
+            break;
+        case "handleQuitRequestWith":
+            boolean closed = Main.exitJosm(false, 0);
+            if (args[1] != null) {
+                args[1].getClass().getDeclaredMethod(closed ? "performQuit" : "cancelQuit").invoke(args[1]);
+            }
             break;
         case "handleAbout":
@@ -92,12 +107,5 @@
             break;
         default:
-            return null;
-        }
-        if (args[0] != null) {
-            try {
-                args[0].getClass().getDeclaredMethod("setHandled", new Class<?>[] { boolean.class }).invoke(args[0], new Object[] { handled });
-            } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) {
-                Main.warn("Failed to report handled event: " + ex);
-            }
+            Main.warn("OSX unsupported method: "+method.getName());
         }
         return null;
