Changeset 7287 in josm


Ignore:
Timestamp:
2014-07-04T00:00:19+02:00 (10 years ago)
Author:
Don-vip
Message:

fix #10025 - File registration with Mac OSX (many thanks to Stereo and cquest for their help)

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/build.xml

    r7231 r7287  
    153153            <arch name="i386"/>
    154154
    155             <bundledocument extensions="osm" icon="macosx/JOSM.app/Contents/Resources/JOSM.icns" name="OSM files" role="editor"/>
    156 
    157155            <classpath file="${bundle.jar}"/>
    158156
    159             <option value="-Xmx512m"/>
     157            <option value="-Xmx1024m"/>
    160158
    161159            <option value="-Xdock:icon=Contents/Resources/JOSM.icns"/>
     
    174172       
    175173        <xmltask source="${bundle.outdir}/JOSM.app/Contents/Info.plist" dest="${bundle.outdir}/JOSM.app/Contents/Info.plist" indent="false">
    176             <insert position="before" path="/plist/dict/key[1]"><![CDATA[<key>CFBundleAllowMixedLocalizations</key>
    177 <string>true</string>
    178 ]]></insert>
     174                <!-- remove empty CFBundleDocumentTypes definition -->
     175                <remove path="/plist/dict/key[text()='CFBundleDocumentTypes']|/plist/dict/key[text()='CFBundleDocumentTypes']/following-sibling::array[1]"/>
     176            <!-- insert our own keys -->
     177            <insert position="before" path="/plist/dict/key[1]" file="macosx/JOSM.app/Contents/Info.plist_template.xml" />
    179178        </xmltask>
    180179       
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    r7283 r7287  
    1010import java.lang.reflect.Method;
    1111import java.lang.reflect.Proxy;
     12import java.util.Arrays;
    1213import java.util.List;
    1314
     
    1516
    1617import org.openstreetmap.josm.Main;
    17 import org.openstreetmap.josm.actions.OpenFileAction;
     18import org.openstreetmap.josm.actions.OpenFileAction.OpenFileTask;
    1819import org.openstreetmap.josm.data.Preferences;
     20import org.openstreetmap.josm.io.OsmTransferException;
     21import org.xml.sax.SAXException;
    1922
    2023/**
     
    3740    @Override
    3841    public void startupHook() {
    39         // Here we register callbacks for the menu entries in the system menu
     42        // Here we register callbacks for the menu entries in the system menu and file opening through double-click
    4043        try {
    4144            Class<?> Ccom_apple_eawt_Application = Class.forName("com.apple.eawt.Application");
     45            Class<?> Ccom_apple_eawt_QuitHandler = Class.forName("com.apple.eawt.QuitHandler");
     46            Class<?> Ccom_apple_eawt_AboutHandler = Class.forName("com.apple.eawt.AboutHandler");
     47            Class<?> Ccom_apple_eawt_OpenFilesHandler = Class.forName("com.apple.eawt.OpenFilesHandler");
     48            Class<?> Ccom_apple_eawt_PreferencesHandler = Class.forName("com.apple.eawt.PreferencesHandler");
    4249            Object Ocom_apple_eawt_Application = Ccom_apple_eawt_Application.getConstructor((Class[])null).newInstance((Object[])null);
    43             Class<?> Ccom_apple_eawt_ApplicationListener = Class.forName("com.apple.eawt.ApplicationListener");
    44             Method MaddApplicationListener = Ccom_apple_eawt_Application.getDeclaredMethod("addApplicationListener", Ccom_apple_eawt_ApplicationListener);
    45             Object Oproxy = Proxy.newProxyInstance(PlatformHookOsx.class.getClassLoader(), new Class<?>[] { Ccom_apple_eawt_ApplicationListener }, ivhandler);
    46             MaddApplicationListener.invoke(Ocom_apple_eawt_Application, Oproxy);
    47             Method MsetEnabledPreferencesMenu = Ccom_apple_eawt_Application.getDeclaredMethod("setEnabledPreferencesMenu", boolean.class);
    48             MsetEnabledPreferencesMenu.invoke(Ocom_apple_eawt_Application, Boolean.TRUE);
    49             // Register callback for file opening through double-click
    50             Class<?> Ccom_apple_eawt_OpenFilesHandler = Class.forName("com.apple.eawt.OpenFilesHandler");
    51             Method MsetOpenFileHandler = Ccom_apple_eawt_Application.getDeclaredMethod("setOpenFileHandler", Ccom_apple_eawt_OpenFilesHandler);
    52             Object Oproxy2 = Proxy.newProxyInstance(PlatformHookOsx.class.getClassLoader(), new Class<?>[] { Ccom_apple_eawt_OpenFilesHandler }, ivhandler);
    53             MsetOpenFileHandler.invoke(Ocom_apple_eawt_Application, Oproxy2);
     50            Object Oproxy = Proxy.newProxyInstance(PlatformHookOsx.class.getClassLoader(), new Class<?>[] {
     51                Ccom_apple_eawt_QuitHandler, Ccom_apple_eawt_AboutHandler, Ccom_apple_eawt_OpenFilesHandler, Ccom_apple_eawt_PreferencesHandler}, ivhandler);
     52            Ccom_apple_eawt_Application.getDeclaredMethod("setQuitHandler", Ccom_apple_eawt_QuitHandler).invoke(Ocom_apple_eawt_Application, Oproxy);
     53            Ccom_apple_eawt_Application.getDeclaredMethod("setAboutHandler", Ccom_apple_eawt_AboutHandler).invoke(Ocom_apple_eawt_Application, Oproxy);
     54            Ccom_apple_eawt_Application.getDeclaredMethod("setOpenFileHandler", Ccom_apple_eawt_OpenFilesHandler).invoke(Ocom_apple_eawt_Application, Oproxy);
     55            Ccom_apple_eawt_Application.getDeclaredMethod("setPreferencesHandler", Ccom_apple_eawt_PreferencesHandler).invoke(Ocom_apple_eawt_Application, Oproxy);
     56            // this method has been deprecated, but without replacement ATM
     57            Ccom_apple_eawt_Application.getDeclaredMethod("setEnabledPreferencesMenu", boolean.class).invoke(Ocom_apple_eawt_Application, Boolean.TRUE);
    5458        } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) {
    5559            // We'll just ignore this for now. The user will still be able to close JOSM by closing all its windows.
     
    6165    @Override
    6266    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    63         Boolean handled = Boolean.TRUE;
    6467        if (Main.isDebugEnabled()) {
    65             Main.debug("OSX handler: "+method.getName()+" - "+args);
     68            Main.debug("OSX handler: "+method.getName()+" - "+Arrays.toString(args));
    6669        }
    6770        switch (method.getName()) {
     
    6972            if (args[0] != null) {
    7073                try {
    71                     Object oFiles = args[0].getClass().getDeclaredMethod("getFiles").invoke(args[0]);
     74                    Object oFiles = args[0].getClass().getMethod("getFiles").invoke(args[0]);
    7275                    if (oFiles instanceof List) {
    73                         OpenFileAction.openFiles((List<File>)oFiles, true);
    74                     } else {
    75                         Main.warn("OSX openFiles called without List: "+oFiles);
     76                        Main.worker.submit(new OpenFileTask((List<File>)oFiles, null) {
     77                            @Override
     78                            protected void realRun() throws SAXException, IOException, OsmTransferException {
     79                                // Wait for JOSM startup is advanced enough to load a file
     80                                while (Main.parent == null || !Main.parent.isVisible()) {
     81                                    try {
     82                                        Thread.sleep(25);
     83                                    } catch (InterruptedException e) {
     84                                        Main.warn(e);
     85                                    }
     86                                }
     87                                super.realRun();
     88                            }
     89                        });
    7690                    }
    7791                } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) {
    7892                    Main.warn("Failed to access open files event: " + ex);
    7993                }
    80             } else {
    81                 Main.warn("OSX openFiles called without args");
    8294            }
    83             return null;
    84         case "handleQuit":
    85             handled = Main.exitJosm(false, 0);
     95            break;
     96        case "handleQuitRequestWith":
     97            boolean closed = Main.exitJosm(false, 0);
     98            if (args[1] != null) {
     99                args[1].getClass().getDeclaredMethod(closed ? "performQuit" : "cancelQuit").invoke(args[1]);
     100            }
    86101            break;
    87102        case "handleAbout":
     
    92107            break;
    93108        default:
    94             return null;
    95         }
    96         if (args[0] != null) {
    97             try {
    98                 args[0].getClass().getDeclaredMethod("setHandled", new Class<?>[] { boolean.class }).invoke(args[0], new Object[] { handled });
    99             } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) {
    100                 Main.warn("Failed to report handled event: " + ex);
    101             }
     109            Main.warn("OSX unsupported method: "+method.getName());
    102110        }
    103111        return null;
Note: See TracChangeset for help on using the changeset viewer.