Example #1
0
        private Content CoerceContent(ClipEventArgs args)
        {
            var content_type = new List<String>();
            var formats = args.Clip.GetFormats();

            foreach (var format in formats)
            {
                switch (format)
                {
                    case "PNG":
                        content_type.Add("image/png");
                        break;

                    case "DeviceIndependentBitmap":
                        content_type.Add("image/bmp");
                        break;

                    case "FileName":
                    case "FileDrop":
                        content_type.Add("text/path");
                        break;

                    case "HTML Format":
                    case "text/html":
                        content_type.Add("text/html");
                        var html = args.Clip.GetData("HTML Format", true);
                        break;

                    case "Text":
                    case "UnicodeText":
                    case "System.String":
                    case "text/plain":
                        content_type.Add("text/plain");
                        break;
                }
            }

            content_type = content_type.Distinct().ToList(); // eliminate duplicates
            var description = "Unable to find text description.";

            if (content_type.Contains("text/path"))
            {
                var builder = new StringBuilder();
                var files = args.Clip.GetData("FileName", true) as String[];
                foreach (var file in files)
                {
                    builder.Append(file);
                    builder.Append(';');
                }
                description = builder.ToString();
            }
            else if (content_type.Contains("text/plain"))
            {
                description = args.Clip.GetData("System.String", true) as String;
            }
            else if (content_type.Contains("text/html"))
            {
                description = args.Clip.GetData("HTML Format", true) as String;
            }

            return new Content () { Clip = args.Clip, ContentType = content_type, Description = description };
        }
Example #2
0
 protected void OnClipboardChanged(ClipEventArgs e)
 {
     if (ClipboardChanged != null)
         ClipboardChanged(this, e);
 }