diff options
author | Jeremie Laval <jeremie.laval@gmail.com> | 2012-02-10 21:29:16 +0400 |
---|---|---|
committer | Jeremie Laval <jeremie.laval@gmail.com> | 2012-02-15 21:29:48 +0400 |
commit | 388eef19c21c72d14e2b36a9366930cfbbe26236 (patch) | |
tree | acabab1cc4c38c4d1fa7f7b21dd3207e35e81070 /AppDelegate.cs | |
parent | 6c69ab5622d7f0a9b27f6214fee5ef374aa5d9b2 (diff) |
[macdoc] Work around the OpenDocument/MakeDocument issue by using our own custom binding
Diffstat (limited to 'AppDelegate.cs')
-rw-r--r-- | AppDelegate.cs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/AppDelegate.cs b/AppDelegate.cs index 5564f3e..c7f446d 100644 --- a/AppDelegate.cs +++ b/AppDelegate.cs @@ -2,8 +2,10 @@ using System; using System.Drawing; using MonoMac.Foundation; using MonoMac.AppKit; +using MonoMac.ObjCRuntime; using Monodoc; using System.IO; +using System.Runtime.InteropServices; namespace macdoc { @@ -76,12 +78,29 @@ namespace macdoc [Export ("handleGetURLEvent:withReplyEvent:")] public void HandleGetURLEvent (NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvt) { + NSError error; // Received event is a list (1-based) of URL strings for (int i = 1; i <= evt.NumberOfItems; i++) { var innerDesc = evt.DescriptorAtIndex (i); - controller.OpenDocument (new NSUrl (innerDesc.StringValue), i == evt.NumberOfItems, delegate {}); + // The next call works fine but is Lion-specific + //controller.OpenDocument (new NSUrl (innerDesc.StringValue), i == evt.NumberOfItems, delegate {}); + Call_OpenDocument (new NSUrl (innerDesc.StringValue), i == evt.NumberOfItems, out error); } } + + // We use a working OpenDocument method that doesn't return anything because of MonoMac bug#3380 + public void Call_OpenDocument (NSUrl absoluteUrl, bool displayDocument, out NSError outError) + { + outError = null; + if (absoluteUrl == null) + throw new ArgumentNullException ("absoluteUrl"); + IntPtr outErrorPtr = Marshal.AllocHGlobal(4); + Marshal.WriteInt32(outErrorPtr, 0); + + MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr_bool_IntPtr (controller.Handle, selOpenDocumentWithContentsOfURLDisplayError_, absoluteUrl.Handle, displayDocument, outErrorPtr); + } + + IntPtr selOpenDocumentWithContentsOfURLDisplayError_ = new Selector ("openDocumentWithContentsOfURL:display:error:").Handle; } } |