예제 #1
0
        private void CopyTextAndHtml(IEnumerable <IEditor> editors, IDataObject dataObj)
        {
            var textExporter = new PlainTextExporter();

            dataObj.SetData(DataFormats.UnicodeText, textExporter.ExportText(editors));

            var htmlExporter = new HtmlExporter();
            var html         = htmlExporter.ExportHtml(editors);

            dataObj.SetData(DataFormats.Html, ClipboardUtil.GetCFHtmlMemoryStream(html));
        }
예제 #2
0
        // ========================================
        // method
        // ========================================
        public override void Execute()
        {
            var data = new DataObject();
            var copy = _target.CopyBlocksAndInlines(_range);

            data.SetData(StyledTextConsts.BlocksAndInlinesFormat.Name, false, copy);

            /// plain text
            {
                var writer = new PlainTextWriter();
                var text   = writer.ToPlainText(copy);
                data.SetText(text, TextDataFormat.UnicodeText);
            }

            /// html
            if (SupportHtml)
            {
                var writer = new HtmlWriter();
                var html   = writer.ToHtml(copy);
                data.SetData(DataFormats.Html, ClipboardUtil.GetCFHtmlMemoryStream(html));
            }

            Clipboard.SetDataObject(data, true);
        }
예제 #3
0
        protected IDragSource CreateFocusFigureDragSource()
        {
            var ret = MouseOperatableFactory.CreateDragSource(DragDropEffects.Copy | DragDropEffects.Move);

            ret.JudgeDragStart += (sender, e) => {
                e.DoIt = false;
                if (e.Button == MouseButtons.Left && e.Clicks == 1)
                {
                    var loc   = new Point(e.X, e.Y);
                    var focus = Host.Focus as StyledTextFocus;
                    if (focus.Figure.IsInSelection(loc))
                    {
                        _selectionRangeOnDragStart = focus.Selection.Range;
                        e.DoIt = true;
                    }
                }
            };

            //ret.DragStart += delegate {
            //    var focus = Host.Focus as StyledTextFocus;
            //    _selectionRangeOnDragStart = focus.Selection.Range;
            //};
            ret.DragSetData += (sender, e) => {
                var focus = Host.Focus as StyledTextFocus;
                var flows = focus.Referer.Target.CopyBlocksAndInlines(focus.Selection.Range);
                var data  = new DataObject();
                //data.SetData(StyledTextConsts.BlocksAndInlinesFormat.Name, flows);
                data.SetData(StyledTextConsts.BlocksAndInlinesFormat.Name, false, flows);

                /// plain text
                {
                    var writer = new PlainTextWriter();
                    var text   = writer.ToPlainText(flows);
                    data.SetText(text, TextDataFormat.UnicodeText);
                }

                var app = MemopadApplication.Instance;

                /// html
                {
                    var writer = new HtmlWriter();
                    var html   = writer.ToHtml(flows);
                    data.SetData(DataFormats.Html, ClipboardUtil.GetCFHtmlMemoryStream(html));
                }

                e.DataObject = new DataObject(data);
            };
            ret.DragFinish += (sender, e) => {
                if (Host.IsFocused)
                {
                    /// このEditorにdropされた場合,
                    /// Moveの処理もDragTargetのDragDropで処理されるので何もしない
                }
                else
                {
                    /// 他のEditorにdropされた
                    if (e.Effects == DragDropEffects.Move)
                    {
                        var memoStyledText = (MemoStyledText)Host.Model;
                        var node           = (INode)Host.Figure;

                        BeginUpdate();
                        using (node.BeginUpdateStyledText()) {
                            var cmd = new RemoveCommand(
                                memoStyledText.StyledText,
                                _selectionRangeOnDragStart.Offset,
                                _selectionRangeOnDragStart.Length
                                );
                            Host.Site.CommandExecutor.Execute(cmd);
                        }
                        EndUpdate();

                        /// コメント線の処理
                        DisconnectRemovedAnchor(node, node);

                        /// StyledText.IsEmptyになったら削除
                        var model = Host.Model as MemoStyledText;
                        if (model != null && model.StyledText.IsEmpty)
                        {
                            Host.RequestRemove();
                        }
                    }
                }
                _selectionRangeOnDragStart = Range.Empty;
            };

            return(ret);
        }