oyarzun commented on issue #4005:
URL: https://github.com/apache/netbeans/issues/4005#issuecomment-1200448562

   @neilcsmith-net it is handled by the AppDelegate in a NSApplication, but 
console applications do not have an app delegate. 
   
   https://developer.apple.com/documentation/appkit/nsapplicationdelegate
   
https://developer.apple.com/documentation/appkit/nsapplicationdelegate/2887193-application
   
   This allows "open with" to work, but add an extra icon in the dock.
   
   ```diff
   diff --git a/nb/ide.launcher/macosx/Sources/NetBeansLauncher/main.swift 
b/nb/ide.launcher/macosx/Sources/NetBeansLauncher/main.swift
   index 923952ae1a..3c8b23cce7 100644
   --- a/nb/ide.launcher/macosx/Sources/NetBeansLauncher/main.swift
   +++ b/nb/ide.launcher/macosx/Sources/NetBeansLauncher/main.swift
   @@ -18,21 +18,66 @@
    */
   
    import Foundation
   +import AppKit
   
   -let netbeansURL = Bundle.main.url(forResource: "netbeans", withExtension: 
"", subdirectory: "NetBeans/netbeans/bin")
   +var openArgs = [String]()
   +
   +func launchNB() {
   +    let launchNetbeans = Process()
   +    launchNetbeans.arguments = args
   +    launchNetbeans.executableURL = netbeansURL
   +    do {
   +        try launchNetbeans.run()
   +    }
   +    catch {
   +        NSLog("NetBeans failed to start")
   +    }
   +
   +    // needed to keep Dock name based on CFBundleName from Info.plist
   +    // does not work if called from command line.
   +    launchNetbeans.waitUntilExit()
   +}
   +
   +class AppDelegate: NSObject, NSApplicationDelegate {
   +    func application(_ application: NSApplication, open urls: [URL]) {
   +        for url in urls {
   +            args.append(url.path)
   +            NSLog("urls %@", url.path)
   +        }
   +    }
   +
   +    func application(_ sender: NSApplication, openFile filename: String) -> 
Bool {
   +        args.append(filename)
   +        NSLog("openFile %@", filename)
   +        return true
   +    }
   +
   +    func application(_ sender: NSApplication, openFiles filenames: 
[String]) {
   +        for filename in filenames {
   +            args.append(filename)
   +            NSLog("openFiles %@", filename)
   +        }
   +    }
   +
   +    func applicationDidFinishLaunching(_ notification: Notification) {
   +        launchNB()
   +    }
   +}
   
    var args = [String]()
   +let app = NSApplication.shared
   +let delegate = AppDelegate()
   +app.delegate = delegate
   +
   +
   +let netbeansURL = Bundle.main.url(forResource: "netbeans", withExtension: 
"", subdirectory: "NetBeans/netbeans/bin")
   +
   
    // add user's command line arguments
    for argument in Array(CommandLine.arguments.dropFirst()) {
        args.append(argument)
    }
   
   -let launchNetbeans = Process()
   -launchNetbeans.arguments = args
   -launchNetbeans.executableURL = netbeansURL
   -try launchNetbeans.run()
   
   -// needed to keep Dock name based on CFBundleName from Info.plist
   -// does not work if called from command line.
   -launchNetbeans.waitUntilExit()
   +app.run()
   +
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to