コード例 #1
0
ファイル: Selection.cs プロジェクト: danwalmsley/PerspexEdit
        /// <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);
        }
コード例 #2
0
        /// <summary>
        /// Creates a new TextAreaDefaultInputHandler instance.
        /// </summary>
        public TextAreaDefaultInputHandler(TextArea textArea) : base(textArea)
        {
            this.NestedInputHandlers.Add(CaretNavigation = CaretNavigationCommandHandler.Create(textArea));
            this.NestedInputHandlers.Add(Editing         = EditingCommandHandler.Create(textArea));
            this.NestedInputHandlers.Add(MouseSelection  = new SelectionMouseHandler(textArea));

            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, ExecuteUndo, CanExecuteUndo));
            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, ExecuteRedo, CanExecuteRedo));
        }
コード例 #3
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);
        }