コード例 #1
0
        protected void ProvideWebArchive(NSPasteboard pboard, NSPasteboardItem item, string type)
        {
            // This method does not seem to work any more. Disabled by not returning appropriate type in Types getter.
            var s = GetHtmlWithoutMetadata();

            if (s == null)
            {
                return;
            }

            var mainRsrc = new NSDictionary
            {
                ["WebResourceData"]             = NSData.FromString(s, NSStringEncoding.UTF8),
                ["WebResourceFrameName"]        = (NSString)"",
                ["WebResourceMIMEType"]         = (NSString)"text/html",
                ["WebResourceTextEncodingName"] = (NSString)"UTF-8",
                ["WebResourceURL"] = (NSString)"about:blank"
            };

            var container = new NSDictionary
            {
                ["WebMainResource"] = mainRsrc
            };

            var nsdata  = NSPropertyListSerialization.DataWithPropertyList(container, NSPropertyListFormat.Xml, out NSError error);
            var archive = NSString.FromData(nsdata, NSStringEncoding.UTF8);

            item.SetDataForType(nsdata, Pasteboard.NSPasteboardTypeWebArchive);
        }
コード例 #2
0
        public override bool PerformDragOperation(NSDraggingInfo sender)
        {
            var result = base.PerformDragOperation(sender);

            if (result)
            {
                var fileNamesXml = sender.DraggingPasteboard.GetStringForType("NSFilenamesPboardType");

                if (fileNamesXml != null)
                {
                    var propertyData = NSData.FromString(fileNamesXml);
                    var format       = NSPropertyListFormat.Xml;
                    var ser          = (NSArray)NSPropertyListSerialization.PropertyListWithData(propertyData, ref format, out var error);

                    if (error == null && ser != null && ser.Count > 0)
                    {
                        var path = NSString.FromHandle(ser.ValueAt(0));

                        DraggingDidEnd?.Invoke(this, path);
                    }
                }
            }

            return(result);
        }
コード例 #3
0
        static byte[] Serialize(NSDictionary plist)
        {
            NSError error;
            var     nsData = NSPropertyListSerialization.DataWithPropertyList(plist, NSPropertyListFormat.Xml, out error);

            if (nsData == null)
            {
                throw new Exception("Failed to serialize plist");
            }

            return(Encoding.UTF8.GetBytes(nsData.ToString()));
        }
コード例 #4
0
        /// <exception cref="FailedToParsePlist"></exception>
        public static NSDictionary PayloadToNSDictionary(byte[] payload)
        {
            var plistData = NSData.FromArray(payload);
            var format    = NSPropertyListFormat.Xml;

            NSError error;
            var     ret = (NSDictionary)NSPropertyListSerialization.PropertyListWithData(plistData, ref format, out error);

            if (ret == null)
            {
                throw new FailedToParsePlist();
            }

            return(ret);
        }