Changeset 7253 in josm
- Timestamp:
- 2014-06-19T00:59:46+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
r7022 r7253 5 5 6 6 import java.awt.event.KeyEvent; 7 import java.io.File; 7 8 import java.io.IOException; 8 9 import java.lang.reflect.InvocationHandler; 9 10 import java.lang.reflect.Method; 10 11 import java.lang.reflect.Proxy; 12 import java.util.List; 11 13 12 14 import javax.swing.UIManager; 13 15 14 16 import org.openstreetmap.josm.Main; 17 import org.openstreetmap.josm.actions.OpenFileAction; 15 18 import org.openstreetmap.josm.data.Preferences; 16 19 … … 39 42 Object Ocom_apple_eawt_Application = Ccom_apple_eawt_Application.getConstructor((Class[])null).newInstance((Object[])null); 40 43 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); 42 45 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) { 47 55 // We'll just ignore this for now. The user will still be able to close JOSM by closing all its windows. 48 56 Main.warn("Failed to register with OSX: " + ex); … … 50 58 } 51 59 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 { 54 63 Boolean handled = Boolean.TRUE; 55 64 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; 56 77 case "handleQuit": 57 78 handled = Main.exitJosm(false, 0); … … 69 90 try { 70 91 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) { 72 93 Main.warn("Failed to report handled event: " + ex); 73 94 }
Note:
See TracChangeset
for help on using the changeset viewer.