Changeset 7253 in josm for trunk/src/org


Ignore:
Timestamp:
2014-06-19T00:59:46+02:00 (6 years ago)
Author:
Don-vip
Message:

see #10025 - open .osm files with double-click on OSX

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    r7022 r7253  
    55
    66import java.awt.event.KeyEvent;
     7import java.io.File;
    78import java.io.IOException;
    89import java.lang.reflect.InvocationHandler;
    910import java.lang.reflect.Method;
    1011import java.lang.reflect.Proxy;
     12import java.util.List;
    1113
    1214import javax.swing.UIManager;
    1315
    1416import org.openstreetmap.josm.Main;
     17import org.openstreetmap.josm.actions.OpenFileAction;
    1518import org.openstreetmap.josm.data.Preferences;
    1619
     
    3942            Object Ocom_apple_eawt_Application = Ccom_apple_eawt_Application.getConstructor((Class[])null).newInstance((Object[])null);
    4043            Class<?> Ccom_apple_eawt_ApplicationListener = Class.forName("com.apple.eawt.ApplicationListener");
    41             Method MaddApplicationListener = Ccom_apple_eawt_Application.getDeclaredMethod("addApplicationListener", new Class<?>[] { Ccom_apple_eawt_ApplicationListener });
     44            Method MaddApplicationListener = Ccom_apple_eawt_Application.getDeclaredMethod("addApplicationListener", Ccom_apple_eawt_ApplicationListener);
    4245            Object Oproxy = Proxy.newProxyInstance(PlatformHookOsx.class.getClassLoader(), new Class<?>[] { Ccom_apple_eawt_ApplicationListener }, ivhandler);
    43             MaddApplicationListener.invoke(Ocom_apple_eawt_Application, new Object[] { Oproxy });
    44             Method MsetEnabledPreferencesMenu = Ccom_apple_eawt_Application.getDeclaredMethod("setEnabledPreferencesMenu", new Class<?>[] { boolean.class });
    45             MsetEnabledPreferencesMenu.invoke(Ocom_apple_eawt_Application, new Object[] { Boolean.TRUE });
    46         } catch (Exception ex) {
     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);
     54        } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) {
    4755            // We'll just ignore this for now. The user will still be able to close JOSM by closing all its windows.
    4856            Main.warn("Failed to register with OSX: " + ex);
     
    5058    }
    5159
    52     @Override
    53     public Object invoke (Object proxy, Method method, Object[] args) throws Throwable {
     60    @SuppressWarnings("unchecked")
     61    @Override
     62    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    5463        Boolean handled = Boolean.TRUE;
    5564        switch (method.getName()) {
     65        case "openFiles":
     66            if (args[0] != null) {
     67                try {
     68                    Object oFiles = args[0].getClass().getDeclaredMethod("getFiles").invoke(args[0]);
     69                    if (oFiles instanceof List) {
     70                        OpenFileAction.openFiles((List<File>)oFiles, true);
     71                    }
     72                } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) {
     73                    Main.warn("Failed to access open files event: " + ex);
     74                }
     75            }
     76            return null;
    5677        case "handleQuit":
    5778            handled = Main.exitJosm(false, 0);
     
    6990            try {
    7091                args[0].getClass().getDeclaredMethod("setHandled", new Class<?>[] { boolean.class }).invoke(args[0], new Object[] { handled });
    71             } catch (Exception ex) {
     92            } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) {
    7293                Main.warn("Failed to report handled event: " + ex);
    7394            }
Note: See TracChangeset for help on using the changeset viewer.