# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: C:\Users\jhavlin\releases # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: utilities/src/org/netbeans/modules/openfile/OpenFileMac.java --- utilities/src/org/netbeans/modules/openfile/OpenFileMac.java Base (BASE) +++ utilities/src/org/netbeans/modules/openfile/OpenFileMac.java Locally New @@ -0,0 +1,145 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.openfile; + +import java.io.File; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author jhavlin + */ +public class OpenFileMac { + + private static Logger LOG = + Logger.getLogger(OpenFileMac.class.getName()); + + public static void register() { + LOG.info("Registering Mac OpenFileHandler"); //NOI18N + try { + Class applicationClass = Class.forName( + "com.apple.eawt.Application"); //NOI18N + Object app = null; + try { + Method getApplicationMthd = applicationClass.getDeclaredMethod( + "getApplication"); //NOI18N + app = getApplicationMthd.invoke(null); + } catch (Exception e) { + LOG.log(Level.INFO, "Singleton not obtained", e); //NOI18N + } + if (app == null) { + app = applicationClass.getConstructor().newInstance(); + } + if (app == null) { + LOG.info("Could not get nor create application"); //NOI18N + return; + } + Class applicationListenerClass = Class.forName( + "com.apple.eawt.ApplicationListener"); //NOI18N + Method addListenerMethod = applicationClass.getDeclaredMethod( + "addApplicationListener", //NOI18N + new Class[]{applicationListenerClass}); + Object handlerProxy = Proxy.newProxyInstance( + OpenFileMac.class.getClassLoader(), + new Class[]{applicationListenerClass}, new Handler()); + addListenerMethod.invoke(app, new Object[]{handlerProxy}); + + } catch (ClassNotFoundException cnfe) { + LOG.info("Not Apple JDK: " + cnfe + ""); //NOI18N + } catch (Exception e) { + LOG.log(Level.INFO, e.getMessage(), e); //NOI18N + } + } + + private static class Handler implements InvocationHandler { + + private void openFile(String path) { + OpenFile.openFile(new File(path), -1); + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) + throws Throwable { + + LOG.info("Mac application event: " + method.getName()); //NOI18N + if ("handleOpenFile".equals(method.getName())) { //NOI18N + if (args.length == 1 && args[0] != null) { + String fileName = getFileName(args[0]); + if (fileName != null) { + LOG.info("Opening file path: " + fileName); //NOI18N + openFile(args[0].toString()); + } else { + LOG.info("Cannot get file name."); //NOI18N + } + } else { + LOG.info("Invalit number of arguments: " //NOI18N + + args.length); + for (Object o : args) { + LOG.info(o == null ? "null" : o.toString()); //NOI18N + } + } + } + return null; + } + + private String getFileName(Object appleEvent) { + if (appleEvent != null) { + try { + Method getFilenameMethod = + appleEvent.getClass().getDeclaredMethod( + "getFilename"); //NOI18N + String filename = (String) getFilenameMethod.invoke( + appleEvent); + return filename; + } catch (Exception ex) { + LOG.log(Level.INFO, + "Error getting name: " + appleEvent, ex); //NOI18N + } + } + return null; + } + } +} Index: utilities/src/org/netbeans/modules/utilities/Installer.java --- utilities/src/org/netbeans/modules/utilities/Installer.java Base (BASE) +++ utilities/src/org/netbeans/modules/utilities/Installer.java Locally Modified (Based On LOCAL) @@ -44,6 +44,7 @@ package org.netbeans.modules.utilities; +import org.netbeans.modules.openfile.OpenFileMac; import org.netbeans.modules.openfile.RecentFiles; import org.openide.modules.ModuleInstall; import org.openide.util.SharedClassObject; @@ -68,6 +69,7 @@ * Restores module. Restores "sub-module" Search. */ public void restored() { + OpenFileMac.register(); searchInstaller.restored(); RecentFiles.init(); }