Пример #1
0
		private void Element_Drop(jQueryEvent evt, DropEvent ui) {
			if (currentDropTarget == null) {
				DragEnded();
				return;
			}
			
			TreeNode dropParent, draggedNode = selectedNode;
			int dropIndex;
			if (currentDropTarget.above) {
				// Drop above the active node.
				dropParent = currentDropTarget.node.parent;
				dropIndex  = GetTreeNodeChildIndex(currentDropTarget.node);
			}
			else {
				// Drop into the active node.
				dropParent = currentDropTarget.node;
				dropIndex  = dropParent.children.Count;
			}

			TreeDragDropCompletingEventArgs completingArgs = new TreeDragDropCompletingEventArgs(draggedNode, dropParent, dropIndex);
			OnDragDropCompleting(completingArgs);
			if (completingArgs.Cancel) {
				DragEnded();
				return;
			}

			SetSelection(null, false, false);	// Temporarily remove the selection.
			
			// Remove the node from its current position.
			Element draggedElem = RemoveTreeNodeDOM(draggedNode);
			draggedNode.parent.children.RemoveAt(GetTreeNodeChildIndex(draggedNode));
			if (draggedNode.parent.children.Count == 0)
				UpdateExpansionClasses(GetNodeElement(draggedNode.parent), draggedNode.parent.icon, false, draggedNode.parent.expanded);	// Need to fix the classes to say that this node is now a leaf.

			// Add the node to its new position.
			if (dropParent.treeIfRoot == null) {
				DoSetTreeNodeExpanded(dropParent, true, true);
				Element dropParentN = GetNodeElement(dropParent);
				if (dropIndex == dropParentN.Children[1].Children.Length)
					dropParentN.Children[1].AppendChild(draggedElem);
				else
					dropParentN.Children[1].InsertBefore(draggedElem, dropParentN.Children[1].Children[dropIndex]);
			}
			else {
				Element elem = GetElement();
				if (dropIndex == elem.Children.Length)
					elem.AppendChild(draggedElem);
				else
					elem.InsertBefore(draggedElem, elem.Children[dropIndex]);
			}

			draggedNode.parent = dropParent;
			dropParent.children.Insert(dropIndex, draggedNode);
			
			// Restore the selection to the new node.
			SetSelection(draggedNode, false, false);

			var completedArgs = new TreeDragDropCompletedEventArgs(draggedNode, dropParent, dropIndex);
			OnDragDropCompleted(completedArgs);

			DragEnded();
		}
Пример #2
0
		protected virtual void OnDragDropCompleting(TreeDragDropCompletingEventArgs e) {
			if (DragDropCompleting != null)
				DragDropCompleting(this, e);
		}