Exemple #1
0
        private bool Validate(IProjectEditor editor, object sender, DragEventArgs e, bool bExecute)
        {
            var point = DropHelper.GetPosition(sender, e);

            if (e.Data.Contains(DataFormats.Text))
            {
                var text = e.Data.GetText();

                if (bExecute)
                {
                    editor?.OnTryPaste(text);
                }

                return(true);
            }

            foreach (var format in e.Data.GetDataFormats())
            {
                var data = e.Data.Get(format);

                switch (data)
                {
                case IBaseShape shape:
                    return(editor?.OnDropShape(shape, point.X, point.Y, bExecute) == true);

                case IRecord record:
                    return(editor?.OnDropRecord(record, point.X, point.Y, bExecute) == true);

                case IShapeStyle style:
                    return(editor?.OnDropStyle(style, point.X, point.Y, bExecute) == true);

                case IPageContainer page:
                    return(editor?.OnDropTemplate(page, point.X, point.Y, bExecute) == true);

                default:
                    break;
                }
            }

            if (e.Data.Contains(DataFormats.FileNames))
            {
                var files = e.Data.GetFileNames().ToArray();
                if (bExecute)
                {
                    editor?.OnDropFiles(files, point.X, point.Y);
                }
                return(true);
            }

            return(false);
        }
        private void ZoomBorder_Drop(object sender, DragEventArgs e)
        {
            // Files.
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                try
                {
                    var files = (string[])e.Data.GetData(DataFormats.FileDrop);
                    if (_projectEditor.OnDropFiles(files))
                    {
                        e.Handled = true;
                    }
                }
                catch (Exception ex)
                {
                    _projectEditor?.Log?.LogException(ex);
                }
            }

            // Shapes.
            if (e.Data.GetDataPresent(typeof(IBaseShape)))
            {
                try
                {
                    if (e.Data.GetData(typeof(IBaseShape)) is IBaseShape shape)
                    {
                        var p = e.GetPosition(drawableControl);
                        _projectEditor.OnDropShape(shape, p.X, p.Y);
                        e.Handled = true;
                    }
                }
                catch (Exception ex)
                {
                    _projectEditor?.Log?.LogException(ex);
                }
            }

            // Groups.
            if (e.Data.GetDataPresent(typeof(IGroupShape)))
            {
                try
                {
                    if (e.Data.GetData(typeof(IGroupShape)) is IGroupShape group)
                    {
                        var p = e.GetPosition(drawableControl);
                        _projectEditor.OnDropShapeAsClone(group, p.X, p.Y);
                        e.Handled = true;
                    }
                }
                catch (Exception ex)
                {
                    _projectEditor?.Log?.LogException(ex);
                }
            }

            // Records.
            if (e.Data.GetDataPresent(typeof(IRecord)))
            {
                try
                {
                    if (e.Data.GetData(typeof(IRecord)) is IRecord record)
                    {
                        var p = e.GetPosition(drawableControl);
                        _projectEditor.OnDropRecord(record, p.X, p.Y);
                        e.Handled = true;
                    }
                }
                catch (Exception ex)
                {
                    _projectEditor?.Log?.LogException(ex);
                }
            }

            // Styles.
            if (e.Data.GetDataPresent(typeof(IShapeStyle)))
            {
                try
                {
                    if (e.Data.GetData(typeof(IShapeStyle)) is IShapeStyle style)
                    {
                        var p = e.GetPosition(drawableControl);
                        _projectEditor.OnDropStyle(style, p.X, p.Y);
                        e.Handled = true;
                    }
                }
                catch (Exception ex)
                {
                    _projectEditor?.Log?.LogException(ex);
                }
            }

            // Templates.
            if (e.Data.GetDataPresent(typeof(IPageContainer)))
            {
                try
                {
                    if (e.Data.GetData(typeof(IPageContainer)) is IPageContainer template)
                    {
                        _projectEditor.OnApplyTemplate(template);
                        e.Handled = true;
                    }
                }
                catch (Exception ex)
                {
                    _projectEditor?.Log?.LogException(ex);
                }
            }
        }