protected override bool OnDragDrop(DragContext context, int x, int y, uint time_)
        {
            object dragData = context.GetDragData();
            ResourceInfoDragData resourceInfoDragData = dragData as ResourceInfoDragData;
            bool result;

            if (resourceInfoDragData == null || resourceInfoDragData.Items.Count < 1 || !(resourceInfoDragData.Items.FirstOrDefault <ResourceItem>() is ResourceFile))
            {
                result = false;
            }
            else
            {
                ResourceFile resourceFile = (ResourceFile)resourceInfoDragData.Items.FirstOrDefault <ResourceItem>();
                if (resourceFile != null)
                {
                    if (this.CheckResource(resourceFile))
                    {
                        this.SetValue(resourceFile);
                        this.resourceFile = resourceFile;
                    }
                }
                result = base.OnDragDrop(context, x, y, time_);
            }
            return(result);
        }
        protected override bool OnDragDrop(DragContext context, int x, int y, uint time_)
        {
            ResourceInfoDragData dragData = context.GetDragData() as ResourceInfoDragData;

            if (dragData == null)
            {
                return(false);
            }
            ResourceFile file = dragData.Items.FirstOrDefault <ResourceItem>() as ResourceFile;

            if (file != null && this.CheckResource(file))
            {
                this.SetValue(file);
            }
            return(base.OnDragDrop(context, x, y, time_));
        }
Beispiel #3
0
        protected override bool OnDragMotion(DragContext context, int x, int y, uint time_)
        {
            DragDropJudedArgs args = new DragDropJudedArgs()
            {
                DragContext = context
            };

            OnOnDragMotionJudgedHandle(args);
            if (!args.Handle)
            {
                var dragwidget = context.GetSourceWidget();
                if (dragwidget != null)
                {
                    var dragData = context.GetDragData() as DragData;
                    //内部拖拽
                    if (dragData != null)
                    {
                        return(base.OnDragMotion(context, x, y, time_));
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    //此时拖拽为外部拖拽
                    return(true);
                }
            }
            else
            {
                if (args.AllDrop)
                {
                    return(base.OnDragMotion(context, x, y, time_));
                }
                else
                {
                    return(false);
                }
            }
        }
Beispiel #4
0
        /// <summary> 接收具有拖拽数据的事件
        /// 做为数据接收者时触发 </summary>
        /// <param name="context"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="selection_data"></param>
        /// <param name="info"></param>
        /// <param name="time_"></param>
        protected override void OnDragDataReceived(DragContext context, int x, int y, SelectionData selection_data, uint info, uint time_)
        {
            DragDropJudedArgs args = new DragDropJudedArgs()
            {
                DragContext = context
            };

            OnOnDragDataReceivedJudgedHandle(args);
            if (!args.Handle)
            {
                base.OnDragDataReceived(context, x, y, selection_data, info, time_);
                var dragData = context.GetDragData() as DragData;
                //内部拖拽
                if (dragData != null)
                {
                    Gtk.TreePath treePath; Gtk.TreeViewDropPosition dropPostition;
                    var          isDrop = GetDropTargetRow(x, y, out treePath, out dropPostition);

                    #region 结构树内数据项之间拖拽

                    if (isDrop)
                    {
                        dragData.IsDo = true;
                        var iters          = dragData.SelectionDatas as List <T>;
                        var treeiterparent = this.GetTreeIter(treePath);
                        if (iters != null)
                        {
                            var parentjti = this.GetJisonsTreeIter(treeiterparent);
                            if (!iters.Contains(parentjti.Data))
                            {
                                switch (dropPostition)
                                {
                                case TreeViewDropPosition.Before:
                                {
                                    if (iters.All(i => this.RootTreeIter.CanDrop(parentjti.Data, i as object, DropPosition.InsertBefore, false)))
                                    {
                                        this.RootTreeIter.Drop(parentjti.Data, iters.Cast <object>().ToList(), DropPosition.InsertBefore, false);
                                    }
                                    break;
                                }

                                case TreeViewDropPosition.After:
                                {
                                    if (iters.All(i => this.RootTreeIter.CanDrop(parentjti.Data, i as object, DropPosition.InsertAfter, false)))
                                    {
                                        this.RootTreeIter.Drop(parentjti.Data, iters.Cast <object>().ToList(), DropPosition.InsertAfter, false);
                                    }
                                    break;
                                }

                                default:
                                {
                                    if (!iters.Contains(parentjti.Data) && iters.All(i => this.RootTreeIter.CanDrop(parentjti.Data, i as object, DropPosition.Add, false)))
                                    {
                                        this.RootTreeIter.Drop(parentjti.Data, iters.Cast <object>().ToList(), DropPosition.Add, false);
                                    }
                                    break;
                                }
                                }
                            }
                        }
                    }

                    #endregion

                    #region 数据拖动到结构树数据项之外时触发

                    else if (treePath == null)
                    {
                        dragData.IsDo = true;
                        var iters = dragData.SelectionDatas as List <T>;
                        if (iters != null)
                        {
                            foreach (var item in iters)
                            {
                                var jti = this.GetJisonsTreeIter(item);
                                if (this.JisonsTreeIters.Contains(jti) &&
                                    this.GetParentTreeIter(jti.TreeIter).Equals(TreeIter.Zero))
                                {
                                    continue;
                                }

                                if (item != null)
                                {
                                    if (this.RootTreeIter != null && this.RootTreeIter.FirstDepthChildren.FirstOrDefault() != null)
                                    {
                                        this.RootTreeIter.Drop(this.RootTreeIter.FirstDepthChildren.FirstOrDefault(), iters.Cast <object>().ToList(), DropPosition.Add, false);
                                    }
                                }
                            }
                        }
                    }

                    #endregion
                }
            }
        }
Beispiel #5
0
        public static bool GetDataPresent(this DragContext context, Type dataType)
        {
            object dragData = context.GetDragData();

            return(dragData != null && dragData.GetType().Equals(dataType));
        }