summary history branches tags files
commit:01090d51a3fbb78a7ec4bd416233b6d86d16be8a
author:Jørgen P. Tjernø
committer:Jørgen P. Tjernø
date:Mon Mar 1 01:39:50 2021 -0800
parents:9956b66760de76b5f013e7e6161517100cdd7148
Add plumbing for application:openFile:

This plumbs through a callback for application:openFile: -- allowing an
application to register for file types. Fixes GH-25.
diff --git a/src/osx.rs b/src/osx.rs
line changes: +18/-0
index 7bddbaa..286524c
--- a/src/osx.rs
+++ b/src/osx.rs
@@ -925,6 +925,22 @@ impl INSObject for ObjcSubclass {
                                           FruitCallbackKey::Method("applicationWillFinishLaunching:"),
                                           event as *mut Object);
             }
+            /// NSApplication delegate callback
+            extern "C" fn objc_open_file(
+                this: &Object,
+                _cmd: Sel,
+                _application: u64,
+                file: u64,
+            ) -> bool {
+                let ptr: u64 = unsafe { *this.get_ivar("_rustwrapper") };
+                ObjcSubclass::dispatch_cb(
+                    ptr,
+                    FruitCallbackKey::Method("application:openFile:"),
+                    file as *mut Object,
+                );
+
+                true
+            }
             /// Register the Rust ObjcWrapper instance that wraps this object
             ///
             /// In order for an instance of this ObjC owned object to reach back
@@ -947,6 +963,8 @@ impl INSObject for ObjcSubclass {
                 decl.add_method(sel!(applicationDidFinishLaunching:), f);
                 let f: extern fn(&Object, Sel, u64) = objc_will_finish;
                 decl.add_method(sel!(applicationWillFinishLaunching:), f);
+                let f: extern "C" fn(&Object, Sel, u64, u64) -> bool = objc_open_file;
+                decl.add_method(sel!(application:openFile:), f);
             }
 
             decl.register();