コード例 #1
0
ファイル: DragDrop.cs プロジェクト: mo5h/omeo
        public void Drop(IResource targetResource, IDataObject data, DragDropEffects allowedEffect, int keyState)
        {
            // If the base handler can handle the dragover, let it do the drop
            if (_baseHandler.DragOver(targetResource, data, allowedEffect, keyState) != DragDropEffects.None)
            {
                _baseHandler.Drop(targetResource, data, allowedEffect, keyState);
                return;
            }

            // Now give the link-handler a try
            if (_linkhandler.DragOver(targetResource, data, allowedEffect, keyState) != DragDropEffects.None)
            {
                _linkhandler.Drop(targetResource, data, allowedEffect, keyState);
                return;
            }
        }
コード例 #2
0
        /// <summary>
        /// Handles the DnD <see cref="JetListView.DragDrop"/> event from the underlying <see cref="JetListView"/>, and fires the own <see cref="ResourceDrop"/> event for the external handlers (if none available, invokes the default handler).
        /// </summary>
        private void HandleDragDrop(object sender, JetListViewDragEventArgs args)
        {
            try
            {
                ////////////
                // Prepare
                JetListViewNode nodeInsertionPoint = args.DropTargetNode;                 // In tree-insertion-mode, we drop to the parent, and here we store the original target to use as an insertion point
                IResource       targetRes;
                if (!CheckDragDropMode(args, out targetRes))
                {
                    return;                     // Operation cancelled
                }
                // The resources being dragged
                IResourceList resDragged = args.Data.GetDataPresent(typeof(IResourceList)) ? (IResourceList)args.Data.GetData(typeof(IResourceList)) : Core.ResourceStore.EmptyResourceList;
                lock (resDragged)                  // Kill the resource list to avoid the changes
                    resDragged = Core.ResourceStore.ListFromIds(resDragged.ResourceIds, false);

                ////////////
                // Reorder
                // If we were dragging in the insertion mode, change the order
                // Do it beforehand to avoid “jumping” the item when it first gets added to the end and then jumps to the proper place
                if (((args.DropTargetRenderMode & DropTargetRenderMode.InsertAny) != 0) && (nodeInsertionPoint != null))
                {
                    if (nodeInsertionPoint.Parent != null)
                    {
                        // Collect IDs of the current set of resources under the node (they may be useful if there's no existing order yet)
                        // TODO: lock?
                        IntArrayList arOld = new IntArrayList(nodeInsertionPoint.Parent.Nodes.Count);
                        foreach (JetListViewNode node in nodeInsertionPoint.Parent.Nodes)
                        {
                            arOld.Add(((IResource)node.Data).OriginalId);
                        }
                        UserResourceOrder uro = new UserResourceOrder(
                            nodeInsertionPoint.Parent.Data != null ? (IResource)nodeInsertionPoint.Parent.Data : _resRoot
                            , JobPriority.Immediate);
                        uro.Insert(
                            ((IResource)nodeInsertionPoint.Data).OriginalId
                            , resDragged.ResourceIds
                            , ((args.DropTargetRenderMode & DropTargetRenderMode.InsertBelow) != 0)
                            , arOld);
                    }
                }

                /////////
                // Drop
                // Invoke the external handler for the drop event
                if ((ResourceDrop != null) && (resDragged.Count > 0))                  // A custom handler is available
                {
                    ResourceDrop(this, new ResourceDragEventArgs(targetRes, resDragged));
                }
                else
                {                                                                          // No custom handler, invoke the default one
                    if ((targetRes == RootResource) && (_rootResourceDropHandler != null)) // Empty/Root special handler
                    {
                        _rootResourceDropHandler.Drop(targetRes, args.Data, args.AllowedEffect, args.KeyState);
                    }
                    else                     // Normal d'n'd handler
                    {
                        Core.UIManager.ProcessDragDrop(targetRes, args.Data, args.AllowedEffect, args.KeyState);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.ReportException(ex, ExceptionReportFlags.AttachLog);
            }
        }