Esempio n. 1
0
        /// <summary>
        /// Creates a data object containing the selection's text.
        /// </summary>
        public virtual DataObject CreateDataObject(TextArea textArea)
        {
            DataObject data = new DataObject();

            // Ensure we use the appropriate newline sequence for the OS
            string text = TextUtilities.NormalizeNewLines(GetText(), Environment.NewLine);

            // Enable drag/drop to Word, Notepad++ and others
            if (EditingCommandHandler.ConfirmDataFormat(textArea, data, DataFormats.UnicodeText))
            {
                data.SetText(text);
            }

            // Enable drag/drop to SciTe:
            // We cannot use SetText, thus we need to use typeof(string).FullName as data format.
            // new DataObject(object) calls SetData(object), which in turn calls SetData(Type, data),
            // which then uses Type.FullName as format.
            // We immitate that behavior here as well:
            if (EditingCommandHandler.ConfirmDataFormat(textArea, data, typeof(string).FullName))
            {
                data.SetData(typeof(string).FullName, text);
            }

            // Also copy text in HTML format to clipboard - good for pasting text into Word
            // or to the SharpDevelop forums.
            if (EditingCommandHandler.ConfirmDataFormat(textArea, data, DataFormats.Html))
            {
                HtmlClipboard.SetHtml(data, CreateHtmlFragment(new HtmlOptions(textArea.Options)));
            }
            return(data);
        }
Esempio n. 2
0
        /// <inheritdoc/>
        public override System.Windows.DataObject CreateDataObject(TextArea textArea)
        {
            var data = base.CreateDataObject(textArea);

            if (EditingCommandHandler.ConfirmDataFormat(textArea, data, RectangularSelectionDataType))
            {
                MemoryStream isRectangle = new MemoryStream(1);
                isRectangle.WriteByte(1);
                data.SetData(RectangularSelectionDataType, isRectangle, false);
            }
            return(data);
        }