示例#1
0
        /// <summary>
        /// Update content preview depending on available clipboard data and selected file extension
        /// </summary>
        private void updateContentPreview()
        {
            textPreview.Hide();
            htmlPreview.Hide();
            imagePreview.Hide();

            BaseContent content = clipData.ForExtension(comExt.Text);

            if (content != null)
            {
                box.Text = content.Description;

                if (content is ImageContent imageContent)
                {
                    imagePreview.BackgroundImage = imageContent.Image;
                    imagePreview.Show();
                    return;
                }

                if (content is HtmlContent htmlContent)
                {
                    htmlPreview.DocumentText = htmlContent.Text;
                    htmlPreview.Show();
                    return;
                }

                if (content is TextLikeContent textLikeContent)
                {
                    if (content is RtfContent)
                    {
                        textPreview.Rtf = textLikeContent.Text;
                    }
                    else
                    {
                        textPreview.Text = textLikeContent.Text;
                    }
                    textPreview.Show();
                    return;
                }
            }

            // no matching data found
            box.Text = Resources.str_error_cliboard_format_missmatch;
        }
示例#2
0
        /// <summary>
        /// Read the clipboard and update the UI
        /// </summary>
        /// <returns></returns>
        private bool readClipboard()
        {
            clipData = ClipboardContents.FromClipboard();

            // Update extension dropdown list
            comExt.Items.Clear();
            foreach (var content in clipData.Contents)
            {
                comExt.AddWithSeparator(content.Extensions.Except(comExt.ItemArray()));
            }

            // if selected extension does not match available contents, adjust it
            if (comExt.Text == "*" || comExt.Text == null || clipData.ForExtension(comExt.Text) == null)
            {
                // chose file extension based on available contents in this order
                BaseContent content = clipData.PrimaryContent;
                if (content is ImageContent)
                {
                    comExt.Text = content.Extensions.Contains(Settings.Default.extensionImage) ? Settings.Default.extensionImage : content.DefaultExtension;
                }
                else if (content is TextContent)
                {
                    comExt.Text = Settings.Default.extensionText == null ? content.DefaultExtension : Settings.Default.extensionText;
                }
                else if (content != null)
                {
                    comExt.Text = content.DefaultExtension;
                }
                else
                {
                    comExt.Text = "";
                }
            }

            if (comExt.Items.Count > 0)
            {
                updateContentPreview();
                return(true);
            }

            MessageBox.Show(Resources.str_noclip_text, Resources.str_main_window_title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return(false);
        }