예제 #1
0
        private bool Validate(ProjectEditor 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 BaseShape shape:
                    return(editor?.OnDropShape(shape, point.X, point.Y, bExecute) == true);

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

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

                case PageContainer 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);
                }
                return(true);
            }

            return(false);
        }
예제 #2
0
        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?.LogError($"{ex.Message}{Environment.NewLine}{ex.StackTrace}");
                }
            }

            // 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?.LogError($"{ex.Message}{Environment.NewLine}{ex.StackTrace}");
                }
            }

            // 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?.LogError($"{ex.Message}{Environment.NewLine}{ex.StackTrace}");
                }
            }

            // 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?.LogError($"{ex.Message}{Environment.NewLine}{ex.StackTrace}");
                }
            }

            // 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?.LogError($"{ex.Message}{Environment.NewLine}{ex.StackTrace}");
                }
            }

            // 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?.LogError($"{ex.Message}{Environment.NewLine}{ex.StackTrace}");
                }
            }
        }